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: disable tab for outside days (#1567) #1576

Merged
merged 8 commits into from Oct 9, 2022
Merged

Conversation

DanielJKelly
Copy link
Contributor

@DanielJKelly DanielJKelly commented Oct 7, 2022

Context

Please see #1567 for more context about the issue this PR is meant to fix.

Analysis

The issue is that const isFocusTarget = Boolean(focusContext.focusTarget && isSameDay(focusContext.focusTarget, day)) will return true for multiple days if there is a day that is both "selected" and "outside".

If a day is both outside and selected, the equivalent "inside" day must also be present on one of the displayed calendars, so this day will receive tabIndex=0 and there is no need for the outside version of the day to have tabIndex=0.

Solution

Per the above analysis, my solution is to not consider a day with both the selected and outside active modifiers as a focus target, meaning the tabIndex will be set to -1.

@DanielJKelly DanielJKelly marked this pull request as ready for review October 7, 2022 17:39
@DanielJKelly
Copy link
Contributor Author

"If a day is both outside and selected, the equivalent "inside" day must also be present on one of the displayed calendars"

I just realized this is not true, whoops. Perhaps I could check if the day is within more than one displayed month 🤔

@DanielJKelly DanielJKelly changed the title fix: Set tabIndex to -1 when day is both outside and selected (#1567) fix: Set tabIndex to -1 when day is both outside and displayed (#1567) Oct 8, 2022
@DanielJKelly
Copy link
Contributor Author

"If a day is both outside and selected, the equivalent "inside" day must also be present on one of the displayed calendars"

I just realized this is not true, whoops. Perhaps I could check if the day is within more than one displayed month 🤔

I updated the PR to check if a day is both outside and displayed, which I think makes sense.

@gpbl
Copy link
Owner

gpbl commented Oct 8, 2022

Hey @DanielJKelly thanks for your PR, I've been investigating #1567 too and this one seems a good solution.

If a day is both outside and selected, the equivalent "inside" day must also be present on one of the displayed calendars,

I want to give a second look: I'm not 100% sure of this (yet) :)

focusContext.focusTarget && isSameDay(focusContext.focusTarget, day)
focusContext.focusTarget &&
isSameDay(focusContext.focusTarget, day) &&
!isOutsideAndDisplayed
Copy link
Owner

Choose a reason for hiding this comment

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

I think we don't need to check if the date is displayed or not. I'd just check the activeModifiers.outside.

Suggested change
!isOutsideAndDisplayed
!activeModifiers.outside

@gpbl
Copy link
Owner

gpbl commented Oct 9, 2022

@DanielJKelly Thanks for your investigation! I could review your PR and apply some changes:

  • disabled tabIndex for outside days
  • added an integration test for your use case

I think we should fix this in getInitialFocusTarget, but this function is not aware of the outside days yet.

What do you think? Am I missing something if we don't check "displayed days"?

@gpbl gpbl changed the title fix: Set tabIndex to -1 when day is both outside and displayed (#1567) fix: disable tab for outside days (#1567) Oct 9, 2022
@DanielJKelly
Copy link
Contributor Author

@DanielJKelly Thanks for your investigation! I could review your PR and apply some changes:

  • disabled tabIndex for outside days
  • added an integration test for your use case

I think we should fix this in getInitialFocusTarget, but this function is not aware of the outside days yet.

What do you think? Am I missing something if we don't check "displayed days"?

@gpbl Thanks for the feedback and making the changes. I think you are right that checking "displayed days" is unnecessary. I only added that extra check because I wasn't completely sure if there was some use case I was missing for having an outside day be focusable.

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.

Bug: Stuck in a focus loop trying to focus outside day
2 participants