Skip to content

Commit c3c3729

Browse files
authored
fix(DatePicker): align modelValue prop type with sibling pickers (#2657)
Calendar, MonthPicker, and YearPicker accepted `DateValue | DateValue[] | undefined` while DatePicker, RangeCalendar, and the range pickers also accepted `null`. Add `| null` to bring the single/multi-select pickers in line with the range variants so consumers binding form state that uses `null` as the empty value get a consistent API. Refs #2600
1 parent 0e80c37 commit c3c3729

6 files changed

Lines changed: 32 additions & 4 deletions

File tree

packages/core/src/Calendar/CalendarRoot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface CalendarRootProps extends PrimitiveProps {
9898
/** A function that returns the previous page of the calendar. It receives the current placeholder as an argument inside the component. */
9999
prevPage?: (placeholder: DateValue) => DateValue
100100
/** The controlled selected date value of the calendar. Can be bound as `v-model`. */
101-
modelValue?: DateValue | DateValue[] | undefined
101+
modelValue?: DateValue | DateValue[] | null
102102
/** Whether multiple dates can be selected */
103103
multiple?: boolean
104104
/** Whether or not to disable days outside the current view. */

packages/core/src/DateRangeField/DateRangeFieldRoot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export interface DateRangeFieldRootProps extends PrimitiveProps, FormFieldProps
8484
8585
export type DateRangeFieldRootEmits = {
8686
/** Event handler called whenever the model value changes */
87-
'update:modelValue': [DateRange]
87+
'update:modelValue': [date: DateRange]
8888
/** Event handler called whenever the placeholder value changes */
8989
'update:placeholder': [date: DateValue]
9090
}

packages/core/src/MonthPicker/MonthPicker.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ describe('month picker', async () => {
9797
expect(getByTestId('heading')).toHaveTextContent('1980')
9898
})
9999

100+
it('does not crash when modelValue is null', async () => {
101+
const { picker, rerender } = setup({ pickerProps: { modelValue: null } })
102+
103+
expect(getSelectedMonths(picker)).toHaveLength(0)
104+
105+
await rerender({
106+
pickerProps: {
107+
modelValue: calendarDate,
108+
},
109+
})
110+
111+
expect(getSelectedMonth(picker)).toHaveTextContent('Jan')
112+
})
113+
100114
it('navigates to next year using next button', async () => {
101115
const { getByTestId, user } = setup({ pickerProps: { modelValue: calendarDate } })
102116

packages/core/src/MonthPicker/MonthPickerRoot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface MonthPickerRootProps extends PrimitiveProps {
7474
/** A function that returns the previous page of the month picker. Receives the current placeholder as an argument. */
7575
prevPage?: (placeholder: DateValue) => DateValue
7676
/** The controlled selected month value of the month picker. Can be bound as `v-model`. */
77-
modelValue?: DateValue | DateValue[] | undefined
77+
modelValue?: DateValue | DateValue[] | null
7878
/** Whether multiple months can be selected */
7979
multiple?: boolean
8080
}

packages/core/src/YearPicker/YearPicker.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ describe('year picker', async () => {
5454
expect(getByTestId('heading')).toHaveTextContent('1980 - 1991')
5555
})
5656

57+
it('does not crash when modelValue is null', async () => {
58+
const { picker, rerender } = setup({ pickerProps: { modelValue: null } })
59+
60+
expect(getSelectedYears(picker)).toHaveLength(0)
61+
62+
await rerender({
63+
pickerProps: {
64+
modelValue: calendarDate,
65+
},
66+
})
67+
68+
expect(getSelectedYear(picker)).toHaveTextContent('1980')
69+
})
70+
5771
it('navigates to next decade using next button', async () => {
5872
const { getByTestId, user } = setup({ pickerProps: { modelValue: calendarDate } })
5973

packages/core/src/YearPicker/YearPickerRoot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export interface YearPickerRootProps extends PrimitiveProps {
7575
/** A function that returns the previous page of the year picker. Receives the current placeholder as an argument. */
7676
prevPage?: (placeholder: DateValue) => DateValue
7777
/** The controlled selected year value of the year picker. Can be bound as `v-model`. */
78-
modelValue?: DateValue | DateValue[] | undefined
78+
modelValue?: DateValue | DateValue[] | null
7979
/** Whether multiple years can be selected */
8080
multiple?: boolean
8181
/** Number of years to display per page */

0 commit comments

Comments
 (0)