Skip to content

fix: selectDate not working with uncontrolled calendar and isDateUnavailable#10328

Open
cycsmail wants to merge 2 commits into
adobe:mainfrom
cycsmail:fix-7779-selectdate-unavailable-uncontrolled
Open

fix: selectDate not working with uncontrolled calendar and isDateUnavailable#10328
cycsmail wants to merge 2 commits into
adobe:mainfrom
cycsmail:fix-7779-selectdate-unavailable-uncontrolled

Conversation

@cycsmail

Copy link
Copy Markdown

Closes #7779

normalizeValue passed startDate (the start of the visible range) as the lower bound to previousAvailableDate. When you select a date that falls before the visible range, for example programmatically while a later month is shown, that search window is empty so the selection was always rejected and value stayed null. It only showed up when isDateUnavailable was set, since that's the path that goes through previousAvailableDate. The fix clamps the lower bound to the selected date when the date is before startDate, so a date outside the visible range can still be selected. In-range selection is unchanged.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Render an uncontrolled Calendar with isDateUnavailable, navigate to another month, then call selectDate with a date outside the visible range, it should now select instead of doing nothing. Added packages/react-stately/test/calendar/useCalendarState.test.ts covering selecting a date both before and after the visible range. The before-range test fails without this change and passes with it, and the existing react-aria calendar + Calendar/RangeCalendar suites still pass. Run yarn jest useCalendarState.

🧑 Your Project:

N/A

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some changes to hit a little more surface area with tests and simplify the code to convey intent.

Looks like you need to sign the CLA https://github.com/adobe/react-spectrum/blob/main/CONTRIBUTING.md#contributor-license-agreement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CalendarState selectDate does not work with uncontrolled calendar and isDateUnavailable

2 participants