-
-
Notifications
You must be signed in to change notification settings - Fork 741
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: prevent focus from moving beyond toDate and fromDate #1468
Conversation
b9e7e09
to
d62e0eb
Compare
What about always enabling the behavior I implemented behind |
That behavior is native in the browser already when we rollback #1449. I'd say is a better solution! |
The behavior I implemented here prevents the issue described in #1320 from happening. |
6d78c9f
to
ccb093a
Compare
@gpbl FYI, @react-aria/datepicker behaves similarly to what I implemented here when https://react-spectrum.adobe.com/react-aria/useDatePicker.html#minimum-and-maximum-values |
cec75c9
to
ccb093a
Compare
@gpbl is it possible to estimate when you will be able to take a look at this? Thanks! |
Thanks @kimamula, I will check it out. Still we need to fix #1320 in a PR ad-hoc, after reverting #1451. The fix should focus only on the fix and have updated tests. If you want to help:
If you have urgency with this issue, consider to downgrade to |
ccb093a
to
1765823
Compare
I think we'd better close #1483 for a easier development on our local machine. Also, it seems the tests don't cover the issue. The test should confirm that the disabled days are skipped when moving with the keyboard navigation. Thanks for your help! |
Thank you for your review!! I believe this PR fixes the issue shown in the CodeSandbox example you provided in #1320. I didn't know about It seems difficult and will take a lot of time to determine how to move the focus when encountering a @react-aria/datepicker renders disabled dates without actually "disabling" them. This way, it does not have this issue as well as the issue I described in #1449. |
I found that the issue described in your comment is not specific to I still hope this issue could be addressed in a separate PR, but here are my thoughts on how to solve the issue:
// pseudo code (focusStartOfWeek and focusEndOfWeek are omitted)
const moveFocus = (addFn: typeof addDays, after: boolean) => {
if (!focusedDay) return;
let newFocusedDay = addFn(focusedDay, after ? 1 : -1);
if (!isFocusable(newFocusedDay)) {
newFocusedDay = findNearestFocusableDayTo(newFocusedDay);
if (isSameDay(focusedDay, newFocusedDay) {
newFocusedDay = after ? findNextFocusableDay(focusedDay) : findPreviousFocusableDay(focusedDay);
}
}
if (!newFocusedDay) return;
navigation.goToDate(newFocusedDay, focusedDay);
focus(newFocusedDay);
};
const focusDayBefore = () => moveFocus(addDays, false);
const focusDayAfter = () => moveFocus(addDays, true);
const focusWeekBefore = () => moveFocus(addWeeks, false);
const focusWeekAfter = () => moveFocus(addWeeks, true);
const focusMonthBefore = () => moveFocus(addMonths, false);
const focusMonthAfter = () => moveFocus(addMonths, true);
const focusYearBefore = () => moveFocus(addYears, false);
const focusYearAfter = () => moveFocus(addYears, true); |
@kimamula I see thanks for the feedback! I'll send some updates for this PR, which is a good start! Thanks again for your work here. |
Any ETA on this branch being merged in? |
@gpbl is there anything I can do to get this PR merged? |
Thanks @kimamula! There are few bugs surfacing listed here https://github.com/gpbl/react-day-picker/issues, it would be nice some help there too. Now that #1483 is closed it should be easier to debug and review this PR. @McSam27 please don't ask for ETA thanks, I'm working on this issue in my free-time 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @kimamula ! Thanks for your patience – I want to update in a second PR some code and ask for a review 🙏
@@ -83,75 +86,32 @@ export function FocusProvider(props: { children: ReactNode }): JSX.Element { | |||
setFocusedDay(date); | |||
}; | |||
|
|||
const focusDayBefore = () => { | |||
const moveFocus = (addFn: typeof addDays, after: boolean) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change - I'd better move it in an external function tho... I will update the code when merged.
Prevent focus from moving beyond toDate and fromDate to fix #1320