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(useFocusZone): remove suspended active descendant state #1288

Merged
merged 6 commits into from
Jun 14, 2021

Conversation

dgreif
Copy link
Member

@dgreif dgreif commented Jun 10, 2021

The active-descendant variant of focus zone currently supports a "suspended" state. The zone is suspended upon first creation, and any time the user presses esc. After further integration of the SelectPanel, it's been determined that we should activate the first descendant immediately, rather than requiring the user to press the down arrow to exit suspended state. To accomplish this goal, I have completely removed the concept of a suspended state. The zone will now remember the last active descendant and activate it immediately when focus moves into the activeDescendantControl element. When focus leaves that element, we will keep track of the selected descendant, but "clear" the active descendant state from the control element and inform the consumer that there is no longer an active descendant. If focus returns to the control element, the same descendant will become active again. Further, if one of the descendant elements is focused, the zone will immediately move focus to the control element and set the active descendant to the element that originally received focus. This works great for clicking on items in the SelectPanel

As part of this work, I was able to remove the subscribeToActiveElementChanges code. This was in place with some assumptions about overlapping zones and a desire to focus descendant elements if the control element didn't have focus. This approach was very complicated and does not appear to have any benefit in our real-world use cases so far. I also added a NestedZones story to verify that regular zone behavior works as expected.

Finally, I updated the FilteredActionList refs to more closely match the setup from the active descendant story. The big difference is that the control input is no longer in the container that is passed to the zone.

Closes https://github.com/github/primer/issues/184

Screenshots

CleanShot.2021-06-10.at.16.25.04.mp4
CleanShot.2021-06-10.at.16.23.07.mp4

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

@changeset-bot
Copy link

changeset-bot bot commented Jun 10, 2021

🦋 Changeset detected

Latest commit: ca0a77e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jun 10, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/primer/primer-components/GYJKdQrv9DHM1dWXZpJbc1FKZ8AY
✅ Preview: https://primer-components-git-remove-active-descendant-suspended-primer.vercel.app

@vercel vercel bot temporarily deployed to Preview June 11, 2021 04:46 Inactive
"@primer/components": patch
---

Removed "suspended" state from active-descendant focus zones. Active descendant will now be active as soon as the `activeDescendantControl` element is focused, and cannot be deactivated by pressing `esc`. This is a breaking change to `useFocusZone`, but this behavior is still considred to be in `alpha`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a simpler way to explain this change? As someone not familiar with the intricacies of focus zones, this description is a little hard to follow

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Much clearer. Thank you ❤️

@vercel vercel bot temporarily deployed to Preview June 11, 2021 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview June 11, 2021 22:06 Inactive
Co-authored-by: Cole Bemis <colebemis@github.com>
@vercel vercel bot temporarily deployed to Preview June 11, 2021 22:09 Inactive
Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Excellent work on this ✨

@vercel vercel bot temporarily deployed to Preview June 14, 2021 19:02 Inactive
@dgreif dgreif merged commit 1520711 into main Jun 14, 2021
@dgreif dgreif deleted the remove-active-descendant-suspended branch June 14, 2021 19:06
@github-actions github-actions bot mentioned this pull request Jun 14, 2021
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.

2 participants