Skip to content

Commit 8a7f18d

Browse files
committed
refactor(VDatePicker): use getPrefixedEventHandlers
1 parent 70efb5f commit 8a7f18d

File tree

4 files changed

+13
-30
lines changed

4 files changed

+13
-30
lines changed

packages/api-generator/src/locale/en/VDatePicker.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"update:month": "Emitted when the month changes.",
4747
"update:year": "Emitted when the year changes.",
4848
"update:viewMode": "Emitted when the view mode changes.",
49+
"[`${string}:day`]": "Any event on the day button.",
4950
"<domevent>:date": "Emitted when the specified DOM event occurs on the date button.",
5051
"<domevent>:month": "Emitted when the specified DOM event occurs on the month button.",
5152
"<domevent>:year": "Emitted when the specified DOM event occurs on the year button.",

packages/api-generator/src/locale/en/VDatePickerMonth.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
},
1616
"events": {
1717
"update:month": "Emitted when the month changes.",
18-
"update:year": "Emitted when the year changes.",
19-
"click:day": "Emitted when a day is clicked.",
20-
"dblclick:day": "Emitted when a day is double clicked."
18+
"update:year": "Emitted when the year changes."
2119
},
2220
"slots": {
2321
"year": "Slot for the year.",

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type { VDatePickerMonthsSlots } from './VDatePickerMonths'
3030
import type { VDatePickerYearsSlots } from './VDatePickerYears'
3131
import type { CalendarDay } from '@/composables/calendar'
3232
import type { VPickerSlots } from '@/labs/VPicker/VPicker'
33-
import type { GenericProps } from '@/util'
33+
import type { EventProp, GenericProps } from '@/util'
3434

3535
// Types
3636
export type VDatePickerSlots =
@@ -99,6 +99,7 @@ export const VDatePicker = genericComponent<new <
9999
: T,
100100
> (
101101
props: {
102+
[key: `on${Capitalize<string>}:day`]: EventProp<[Event, CalendarDay]>
102103
modelValue?: TModel
103104
'onUpdate:modelValue'?: (value: TModel) => void
104105
multiple?: Multiple
@@ -115,11 +116,9 @@ export const VDatePicker = genericComponent<new <
115116
'update:year': (date: any) => true,
116117
// 'update:inputMode': (date: any) => true,
117118
'update:viewMode': (date: any) => true,
118-
'click:day': (day: CalendarDay) => true,
119-
'dblclick:day': (day: CalendarDay) => true,
120119
},
121120

122-
setup (props, { emit, slots }) {
121+
setup (props, { emit, slots, attrs }) {
123122
const adapter = useDate()
124123
const { t } = useLocale()
125124
const { rtlClasses } = useRtl()
@@ -328,14 +327,6 @@ export const VDatePicker = genericComponent<new <
328327
onUpdateYear()
329328
}
330329

331-
function onClickDay (day: CalendarDay) {
332-
emit('click:day', day)
333-
}
334-
335-
function onDblclickDay (day: CalendarDay) {
336-
emit('dblclick:day', day)
337-
}
338-
339330
function onClickDate () {
340331
viewMode.value = 'month'
341332
}
@@ -489,14 +480,13 @@ export const VDatePicker = genericComponent<new <
489480
) : (
490481
<VDatePickerMonth
491482
key="date-picker-month"
483+
{ ...attrs }
492484
{ ...datePickerMonthProps }
493485
v-model={ model.value }
494486
v-model:month={ month.value }
495487
v-model:year={ year.value }
496488
onUpdate:month={ onUpdateMonth }
497489
onUpdate:year={ onUpdateYear }
498-
onClick:day={ onClickDay }
499-
onDblclick:day={ onDblclickDay }
500490
min={ minDate.value }
501491
max={ maxDate.value }
502492
>

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { MaybeTransition } from '@/composables/transition'
1313

1414
// Utilities
1515
import { computed, ref, shallowRef, toRef, watch } from 'vue'
16-
import { genericComponent, omit, propsFactory, useRender, wrapInArray } from '@/util'
16+
import { genericComponent, getPrefixedEventHandlers, omit, propsFactory, useRender, wrapInArray } from '@/util'
1717

1818
// Types
1919
import type { PropType } from 'vue'
@@ -31,7 +31,7 @@ export type DatePickerEvents = string[] |
3131
export type VDatePickerMonthSlots = {
3232
day: {
3333
props: {
34-
onClick: () => void
34+
onClick: (e: PointerEvent) => void
3535
}
3636
item: any
3737
i: number
@@ -78,11 +78,9 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
7878
'update:modelValue': (date: unknown) => true,
7979
'update:month': (date: number) => true,
8080
'update:year': (date: number) => true,
81-
'click:day': (day: CalendarDay) => true,
82-
'dblclick:day': (day: CalendarDay) => true,
8381
},
8482

85-
setup (props, { emit, slots }) {
83+
setup (props, { emit, slots, attrs }) {
8684
const daysRef = ref()
8785
const { t } = useLocale()
8886

@@ -176,12 +174,6 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
176174
} else {
177175
model.value = [date]
178176
}
179-
180-
emit('click:day', day)
181-
}
182-
183-
function onDblclick (day: CalendarDay) {
184-
emit('dblclick:day', day)
185177
}
186178

187179
function getEventColors (date: string): string[] {
@@ -269,6 +261,8 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
269261
))}
270262

271263
{ daysInMonth.value.map((item, i) => {
264+
const events = getPrefixedEventHandlers(attrs, ':day', nativeEvent => ({ nativeEvent, ...item }))
265+
272266
const slotProps = {
273267
props: {
274268
class: 'v-date-picker-month__day-btn',
@@ -280,8 +274,8 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
280274
variant: item.isSelected ? 'flat' : item.isToday ? 'outlined' : 'text',
281275
'aria-label': getDateAriaLabel(item),
282276
'aria-current': item.isToday ? 'date' : undefined,
283-
onClick: () => onClick(item),
284-
onDblclick: () => onDblclick(item),
277+
...events,
278+
onClick: (e: PointerEvent) => { onClick(item); events.onClick?.(e) },
285279
},
286280
item,
287281
i,

0 commit comments

Comments
 (0)