Skip to content

Commit 010ded6

Browse files
authored
fix(VDatePicker): completely hide days not in weekdays array (#21624)
fixes #21492 fixes #19718 This reverts commit b1f270b.
1 parent ec4dfc1 commit 010ded6

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

packages/vuetify/src/components/VDatePicker/VDatePickerMonth.sass

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,18 @@
1010
--v-date-picker-month-day-diff: 4px
1111

1212
.v-date-picker-month__weeks
13-
display: grid
14-
grid-template-rows: min-content min-content min-content min-content min-content min-content min-content
13+
display: flex
14+
flex-direction: column
1515
column-gap: $date-picker-month-column-gap
1616
font-size: $date-picker-month-font-size
1717

18-
+ .v-date-picker-month__days
19-
grid-row-gap: 0
20-
2118
.v-date-picker-month__weekday
2219
font-size: $date-picker-month-font-size
2320

2421
.v-date-picker-month__days
2522
display: grid
26-
grid-template-columns: min-content min-content min-content min-content min-content min-content min-content
23+
grid-template-columns: repeat(var(--v-date-picker-days-in-week), min-content)
2724
column-gap: $date-picker-month-column-gap
28-
flex: 1 1
29-
justify-content: space-around
3025

3126
.v-date-picker-month__day
3227
align-items: center

packages/vuetify/src/components/VDatePicker/VDatePickerMonth.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const VDatePickerMonth = genericComponent<VDatePickerMonthSlots>()({
5757
setup (props, { emit, slots }) {
5858
const daysRef = ref()
5959

60-
const { daysInMonth, model, weekNumbers } = useCalendar(props)
60+
const { daysInMonth, model, weekNumbers, weekDays, weekdayLabels } = useCalendar(props)
6161
const adapter = useDate()
6262

6363
const rangeStart = shallowRef()
@@ -142,7 +142,10 @@ export const VDatePickerMonth = genericComponent<VDatePickerMonthSlots>()({
142142
}
143143

144144
useRender(() => (
145-
<div class="v-date-picker-month">
145+
<div
146+
class="v-date-picker-month"
147+
style={{ '--v-date-picker-days-in-week': weekDays.value.length }}
148+
>
146149
{ props.showWeek && (
147150
<div key="weeks" class="v-date-picker-month__weeks">
148151
{ !props.hideWeekdays && (
@@ -165,7 +168,7 @@ export const VDatePickerMonth = genericComponent<VDatePickerMonthSlots>()({
165168
key={ daysInMonth.value[0].date?.toString() }
166169
class="v-date-picker-month__days"
167170
>
168-
{ !props.hideWeekdays && adapter.getWeekdays(props.firstDayOfWeek).map(weekDay => (
171+
{ !props.hideWeekdays && weekdayLabels.value.map(weekDay => (
169172
<div
170173
class={[
171174
'v-date-picker-month__day',

packages/vuetify/src/composables/calendar.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ export function useCalendar (props: CalendarProps) {
122122

123123
const weekDays = computed(() => {
124124
const firstDayOfWeek = adapter.toJsDate(adapter.startOfWeek(adapter.date(), props.firstDayOfWeek)).getDay()
125-
// Always generate all days, regardless of props.weekdays
126-
return [0, 1, 2, 3, 4, 5, 6].map(day => (day + firstDayOfWeek) % 7)
125+
return props.weekdays.map(day => (day + firstDayOfWeek) % 7)
126+
})
127+
128+
const weekdayLabels = computed(() => {
129+
const labels = adapter.getWeekdays(props.firstDayOfWeek)
130+
131+
return weekDays.value.map(day => labels[day])
127132
})
128133

129134
const weeksInMonth = computed(() => {
@@ -223,7 +228,7 @@ export function useCalendar (props: CalendarProps) {
223228
return !props.allowedDates(date)
224229
}
225230

226-
return !props.weekdays.includes(adapter.toJsDate(date).getDay())
231+
return false
227232
}
228233

229234
return {
@@ -234,6 +239,7 @@ export function useCalendar (props: CalendarProps) {
234239
model,
235240
weeksInMonth,
236241
weekDays,
242+
weekdayLabels,
237243
weekNumbers,
238244
}
239245
}

0 commit comments

Comments
 (0)