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

Remove options when ending focus management #399

Merged
merged 3 commits into from
Jun 15, 2024
Merged

Conversation

JelloBagel
Copy link
Contributor

@JelloBagel JelloBagel commented Jun 13, 2024

Context

What are you trying to accomplish?

Fix bug found when removing nodes in a focus zone and with strict mode enabled. Also, I added a test to check for this.

What approach did you choose and why?

We were running into focus inconsistencies when using useFocusZone in our component. I pinpointed it to this line

      if (removedNode instanceof HTMLElement) {
          endFocusManagement(...iterateFocusableElements(removedNode, iterateFocusableElementsOptions))
       }

where an empty array was being returned from

         iterateFocusableElements(removedNode, iterateFocusableElementsOptions)

and the endFocusManagement is unable to remove the focusable elements causing jumpy focus behavior for the user.

This was because in our component, we passed strict=true in the iterateFocusableElementsOptions object, which hits these lines of strict checks inside iterateFocusableElements. Because the node no longer existed/was removed, the strict check failed and returned an empty array.

I removed the iterateFocusableElementsOptions argument so when a node is removed all focusable elements within it are removed from the focusableElements list

@JelloBagel JelloBagel requested a review from a team as a code owner June 13, 2024 03:25
Copy link

changeset-bot bot commented Jun 13, 2024

🦋 Changeset detected

Latest commit: 7d2d85f

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

This PR includes changesets to release 1 package
Name Type
@primer/behaviors 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

Copy link
Contributor

@TylerJDev TylerJDev left a comment

Choose a reason for hiding this comment

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

LGTM!

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