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

Selecting unavailable dates with keyboard selects previous avaialable date in Calendar, DatePicker, useCalendarState, etc #5692

Open
pianomansam opened this issue Jan 12, 2024 · 3 comments · May be fixed by #6330
Labels
bug Something isn't working

Comments

@pianomansam
Copy link

Provide a general summary of the issue here

The documentation says that while unavailable dates remain focusable, they cannot be selected. However, when keyboard users attempt to select an unavailable date, the next available previous date is selected. This is completely unexpected. Attempting to select an unavailable date with a keyboard should do nothing, just like it does with a mouse.

🤔 Expected Behavior?

No value should be set.

😯 Current Behavior

The first available date prior to the selection is selected.

💁 Possible Solution

It appears that this is a result #3005 making changes to the setValue in useCalendarState.ts

It looks like #3005 attempted to make it changes only when "blurring a RangeCalendar while in the middle of a selection", yet its changes appear to be affecting every time the value is changed.

A possible solution would be to completely undo the changes that #3005 makes to setValue or to modify them to only affect the blurring of a RangeCalendar in the middle of selection.

🔦 Context

No response

🖥️ Steps to Reproduce

Here is a modified example that makes the current date unavailable. Use the keyboard to navigate to today and attempt to select it. You will receive an alert stating yesterday's date and you will see yesterday selected.

https://codesandbox.io/p/sandbox/intelligent-shape-ghv2v2

Version

latest

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Mac OS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@snowystinger snowystinger added the bug Something isn't working label Jan 12, 2024
@richardbann
Copy link
Contributor

Hi, just had a look at this. A fix in useCalendarState would solve this: https://github.com/richardbann/react-spectrum/blob/671337e075654dde758d9f16e3f81687cfb9f38c/packages/%40react-stately/calendar/src/useCalendarState.ts#L289-L292
Unsure if this affects other use cases.
Other solution could be to introduce a new function ex. selectFocusedDateIfAvailable and call this function when the current behaviour is not OK.
Let me know if I should work on a PR, thanks.

@pianomansam
Copy link
Author

@richardbann perhaps you can fork my code sandbox to demonstrate that your update resolves this

@pianomansam
Copy link
Author

@richardbann FWIW, I've made your update locally and it appears to resolve my use case.

richardbann pushed a commit to richardbann/react-spectrum that referenced this issue May 4, 2024
Selecting unavailable dates with keyboard selects previous avaialable date in Calendar, DatePicker, useCalendarState, etc
@richardbann richardbann linked a pull request May 4, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants