Skip to content

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
@JelloBagel JelloBagel requested a review from TylerJDev June 13, 2024 03:25
@changeset-bot
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
Member

@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.

3 participants