Skip to content

Commit

Permalink
fix(datepicker): allow emptying field
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih committed Nov 22, 2024
1 parent a77f8f2 commit d1b6e87
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ const DatePicker: FC<DatePickerProps> = ({ allowedRange, ...props }: DatePickerP
const handleChange = (date?: Date) => {
const correctedDate = date ? postprocessDateFromPicker(date) : undefined
const validation = validate(allowedRange, date)

if (validation?.ok && props.onChange) {
props.onChange(correctedDate)
if (validation?.ok) {
setError(undefined)
} else {
setError(validation?.message)
}
if (props.onChange) {
props.onChange(correctedDate)
}
}

return <MonitorUIDatePicker {...props} defaultValue={value} onChange={handleChange} error={error || props.error} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,10 @@ const DateRangePicker: FC<DateRangePickerProps> = ({
}, [selectedRange, allowedRange])

const handleChange = (date?: Date, field: 'startDate' | 'endDate') => {
if (date) {
field === 'startDate' ? setStartDate(date) : setEndDate(date)
const correctedRange = [
field === 'startDate' ? date : startDate,
field === 'endDate' ? date : endDate
] as DateRange
field === 'startDate' ? setStartDate(date) : setEndDate(date)
const correctedRange = [field === 'startDate' ? date : startDate, field === 'endDate' ? date : endDate] as DateRange

onChange(correctedRange)
}
onChange(correctedRange)
}

return (
Expand Down

0 comments on commit d1b6e87

Please sign in to comment.