Skip to content

Commit ea0c51c

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

File tree

4 files changed

+17
-37
lines changed

4 files changed

+17
-37
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: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ 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'
20-
import type { CalendarDay } from '@/composables/calendar'
2120
import type { GenericProps } from '@/util'
2221

2322
export type DatePickerEventColorValue = boolean | string | string[]
@@ -31,7 +30,7 @@ export type DatePickerEvents = string[] |
3130
export type VDatePickerMonthSlots = {
3231
day: {
3332
props: {
34-
onClick: () => void
33+
onClick: (e: PointerEvent) => void
3534
}
3635
item: any
3736
i: number
@@ -78,11 +77,9 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
7877
'update:modelValue': (date: unknown) => true,
7978
'update:month': (date: number) => true,
8079
'update:year': (date: number) => true,
81-
'click:day': (day: CalendarDay) => true,
82-
'dblclick:day': (day: CalendarDay) => true,
8380
},
8481

85-
setup (props, { emit, slots }) {
82+
setup (props, { emit, slots, attrs }) {
8683
const daysRef = ref()
8784
const { t } = useLocale()
8885

@@ -166,22 +163,14 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
166163
}
167164
}
168165

169-
function onClick (day: CalendarDay) {
170-
const { date } = day
171-
166+
function onClick (value: unknown) {
172167
if (props.multiple === 'range') {
173-
onRangeClick(date)
168+
onRangeClick(value)
174169
} else if (props.multiple) {
175-
onMultipleClick(date)
170+
onMultipleClick(value)
176171
} else {
177-
model.value = [date]
172+
model.value = [value]
178173
}
179-
180-
emit('click:day', day)
181-
}
182-
183-
function onDblclick (day: CalendarDay) {
184-
emit('dblclick:day', day)
185174
}
186175

187176
function getEventColors (date: string): string[] {
@@ -269,6 +258,8 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
269258
))}
270259

271260
{ daysInMonth.value.map((item, i) => {
261+
const events = getPrefixedEventHandlers(attrs, ':day', nativeEvent => ({ nativeEvent, ...item }))
262+
272263
const slotProps = {
273264
props: {
274265
class: 'v-date-picker-month__day-btn',
@@ -280,8 +271,8 @@ export const VDatePickerMonth = genericComponent<new <TModel>(
280271
variant: item.isSelected ? 'flat' : item.isToday ? 'outlined' : 'text',
281272
'aria-label': getDateAriaLabel(item),
282273
'aria-current': item.isToday ? 'date' : undefined,
283-
onClick: () => onClick(item),
284-
onDblclick: () => onDblclick(item),
274+
...events,
275+
onClick: (e: PointerEvent) => { onClick(item.date); events.onClick?.(e) },
285276
},
286277
item,
287278
i,

0 commit comments

Comments
 (0)