Skip to content

Commit

Permalink
fix: regression on date picker calendars not updating fields
Browse files Browse the repository at this point in the history
  • Loading branch information
epr3 committed Aug 15, 2024
1 parent 4d7fca8 commit 2f0a1b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/radix-vue/src/DateField/DateFieldRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ onMounted(() => {
const modelValue = useVModel(props, 'modelValue', emits, {
defaultValue: defaultValue.value,
passive: (props.modelValue === undefined) as false,
}) as Ref<DateValue>
const defaultDate = getDefaultDate({
Expand Down
10 changes: 7 additions & 3 deletions packages/radix-vue/src/DatePicker/DatePickerRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const dir = useDirection(propDir)
const modelValue = useVModel(props, 'modelValue', emits, {
defaultValue: defaultValue.value,
passive: (props.modelValue === undefined) as false,
}) as Ref<DateValue | undefined>
const defaultDate = computed(() => getDefaultDate({
Expand Down Expand Up @@ -157,12 +158,15 @@ provideDatePickerRootContext({
dateFieldRef,
dir,
onDateChange(date: DateValue | undefined) {
if (!date || !modelValue.value)
if (!date || !modelValue.value) {
modelValue.value = date
else if (!preventDeselect.value && isSameDay(modelValue.value as DateValue, date))
}
else if (!preventDeselect.value && isSameDay(modelValue.value as DateValue, date)) {
modelValue.value = undefined
else
}
else {
modelValue.value = date.copy()
}
},
onPlaceholderChange(date: DateValue) {
if (!isEqualDay(date, placeholder.value))
Expand Down
4 changes: 3 additions & 1 deletion packages/radix-vue/src/DateRangeField/DateRangeFieldRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
areAllDaysBetweenValid,
hasTime,
isBefore,
isBeforeOrSame,
} from '@/date'
import { createContent, getSegmentElements, initializeSegmentValues, isSegmentNavigationKey, syncSegmentValues } from '@/DateField/utils'
import type { Direction } from '@/shared/types'
Expand Down Expand Up @@ -121,6 +122,7 @@ onMounted(() => {
const modelValue = useVModel(props, 'modelValue', emits, {
defaultValue: props.defaultValue ?? { start: undefined, end: undefined },
passive: (props.modelValue === undefined) as false,
}) as Ref<DateRange>
const defaultDate = getDefaultDate({
Expand Down Expand Up @@ -180,7 +182,7 @@ const isInvalid = computed(() => {
if (!modelValue.value.start || !modelValue.value.end)
return false
if (!isBefore(modelValue.value.start, modelValue.value.end))
if (!isBeforeOrSame(modelValue.value.start, modelValue.value.end))
return true
if (propsIsDateUnavailable.value !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ const {
const dir = useDirection(propsDir)
const modelValue = useVModel(props, 'modelValue', emits, {
defaultValue: props.defaultValue,
defaultValue: props.defaultValue ?? { start: undefined, end: undefined },
passive: (props.modelValue === undefined) as false,
}) as Ref<DateRange>
const defaultDate = getDefaultDate({
Expand Down

0 comments on commit 2f0a1b3

Please sign in to comment.