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(focusZone): handle complex child reordering #1225

Merged
merged 3 commits into from
May 13, 2021
Merged

Conversation

dgreif
Copy link
Member

@dgreif dgreif commented May 13, 2021

Using focusZone in SelectPanel, I have noticed scenarios where filtering causes items to still be present, but reorder based on similarity to the filter. In these scenarios, focusZone currently has a tendency to mix up the focus order. This happens when two items are moved, but put back in opposite order. To avoid this confusion, we can simply handle all removals first, then handle additions.

Merge checklist

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

@dgreif dgreif requested review from smockle and colebemis May 13, 2021 18:56
@changeset-bot
Copy link

changeset-bot bot commented May 13, 2021

🦋 Changeset detected

Latest commit: 9a68576

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 May 13, 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/4es6ua5MQRcponcibKFZ2vGwezcz
✅ Preview: https://primer-components-git-responsive-focus-zone-primer.vercel.app

@vercel vercel bot temporarily deployed to Preview May 13, 2021 18:58 Inactive
expect(document.activeElement).toEqual(firstButton)

// move secondButton and thirdButton to the end of the zone, in reverse order
focusZoneContainer.appendChild(thirdButton)
Copy link
Member

@smockle smockle May 13, 2021

Choose a reason for hiding this comment

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

TIL (from Node.appendChild() on MDN):

If the given child is a reference to an existing node in the document, appendChild() moves it from its current position to the new position (there is no requirement to remove the node from its parent node before appending it to some other node).

@@ -7,6 +7,9 @@ async function nextTick() {
return new Promise(resolve => setTimeout(resolve, 0))
}

const moveDown = () => userEvent.type(document.activeElement!, '{arrowdown}')
Copy link
Member

Choose a reason for hiding this comment

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

Verified the magic string '{arrowdown}': https://github.com/testing-library/user-event#special-characters 👍

@dgreif dgreif enabled auto-merge (squash) May 13, 2021 19:39
@dgreif dgreif merged commit 84c7e77 into main May 13, 2021
@dgreif dgreif deleted the responsive-focus-zone branch May 13, 2021 19:42
@github-actions github-actions bot mentioned this pull request May 13, 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