gpbl / react-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.
https://daypicker.dev
MIT License
6.03k stars 722 forks source link

Disabled days can be selected with selected prop #2047

Closed berkin closed 4 months ago

berkin commented 8 months ago

Description

Disabled days can be selected with the selected prop. https://codesandbox.io/p/sandbox/funny-brahmagupta-2d3gdh?file=%2Fsrc%2FApp.tsx%3A9%2C5

Expected Behavior

it should not select the day.

Actual Behavior

i bind the datepicker to an input field. I disabled the future dates, but they can be selected by the input field.

image
berkin commented 8 months ago

As a workaround, on input change, I check if the date is not matched with disabled days. It does only cover the disabled prop, not the max for example.

....
if (
            isValid(date) &&
            (props.disabled == null ||
                !isMatch(
                    date,
                    Array.isArray(props.disabled)
                        ? props.disabled
                        : [props.disabled]
                ))
        ) {
setSelected(date)

}