Skip to content

Commit b1f270b

Browse files
committed
fix(calendar): don't allow selecting dates outside of weekdays prop
fixes #19718
1 parent 3b8a325 commit b1f270b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/vuetify/src/composables/calendar.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface CalendarProps {
2929
'onUpdate:year': ((value: number) => void) | undefined
3030
}
3131

32+
export type CalendarWeekdays = 0 | 1 | 2 | 3 | 4 | 5 | 6
33+
3234
// Composables
3335
export const makeCalendarProps = propsFactory({
3436
allowedDates: [Array, Function] as PropType<unknown[] | ((date: unknown) => boolean)>,
@@ -44,14 +46,17 @@ export const makeCalendarProps = propsFactory({
4446
showAdjacentMonths: Boolean,
4547
year: [Number, String],
4648
weekdays: {
47-
type: Array<number>,
49+
type: Array as PropType<CalendarWeekdays[]>,
4850
default: () => [0, 1, 2, 3, 4, 5, 6],
4951
},
5052
weeksInMonth: {
5153
type: String as PropType<'dynamic' | 'static'>,
5254
default: 'dynamic',
5355
},
54-
firstDayOfWeek: [Number, String],
56+
firstDayOfWeek: {
57+
type: [Number, String],
58+
default: 0,
59+
},
5560
}, 'calendar')
5661

5762
export function useCalendar (props: CalendarProps) {
@@ -96,17 +101,16 @@ export function useCalendar (props: CalendarProps) {
96101
v => adapter.getMonth(v)
97102
)
98103

99-
const defaultFirstDayOfWeek = computed(() => {
100-
return props.firstDayOfWeek ?? props.weekdays[0]
101-
})
102-
103104
const weekDays = computed(() => {
104-
const firstDayOfWeek = Number(props.firstDayOfWeek ?? 0)
105-
return props.weekdays.map(day => (day + firstDayOfWeek) % 7)
105+
const firstDayOfWeek = Number(props.firstDayOfWeek)
106+
107+
// Always generate all days, regardless of props.weekdays
108+
return [0, 1, 2, 3, 4, 5, 6].map(day => (day + firstDayOfWeek) % 7)
106109
})
107110

108111
const weeksInMonth = computed(() => {
109-
const weeks = adapter.getWeekArray(month.value, defaultFirstDayOfWeek.value)
112+
const firstDayOfWeek = Number(props.firstDayOfWeek)
113+
const weeks = adapter.getWeekArray(month.value, firstDayOfWeek)
110114

111115
const days = weeks.flat()
112116

@@ -202,7 +206,7 @@ export function useCalendar (props: CalendarProps) {
202206
return !props.allowedDates(date)
203207
}
204208

205-
return false
209+
return !props.weekdays.includes(adapter.toJsDate(date).getDay())
206210
}
207211

208212
return {

0 commit comments

Comments
 (0)