Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Reset date range calendar when value is empty string or array #17889

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/react/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,15 @@ const DatePicker = React.forwardRef(function DatePicker(
useEffect(() => {
if (calendarRef?.current?.set) {
if (value !== undefined) {
calendarRef.current.setDate(value);
// To make up for calendarRef.current.setDate not making provision for an empty string or array
if (
value === '' ||
(Array.isArray(value) && value.every((element) => element === ''))
) {
calendarRef.current.clear();
} else {
calendarRef.current.setDate(value);
}
}
updateClassNames(calendarRef.current, prefix);
//for simple date picker w/o calendar; initial mount may not have value
Expand Down
Loading