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

AnchoredOverlay and ActionList fixes for SelectPanel #1209

Merged
merged 5 commits into from
May 6, 2021
Merged

Conversation

dgreif
Copy link
Member

@dgreif dgreif commented May 6, 2021

These changes address a number of issues/missing features that were found during development of the SelectPanel component (currently being built in a separate project)

  • Overlay height/width should be able to be set through the AnchorOverlay component. This allows you to have a fixed height/width on the overlay if list items are loaded asynchronously after the overlay opens.
  • It is common for Item data to include an id field, which could be a string or number. We should allow these to be passed in on ItemProps and use them as the key prop when present. We also don't want to use them on the actual Item element in the DOM as they will likely not be globally unique
  • ActionList will create a single group wrapper if it is passed a list of items without any group details. This group was previously receiving a uniqueId for its groupId on every render. This caused react to remove the existing DOM elements and create all new ones for the entire list contents. Not ideal for perf or for focus management.
  • AnchoredOverlay was delaying the focus zone from activating until user interaction triggered list mode. This is a problem if the user changes focus by clicking into the list. There is no reason not to activate the focus zone as soon as the overlay is opened. Focus trap should still be deferred, but there are remaining issues around when that activates with user clicks (Activate focus trap when clicking inside AnchoredOverlay #1210)

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 VanAnderson May 6, 2021 19:46
@changeset-bot
Copy link

changeset-bot bot commented May 6, 2021

🦋 Changeset detected

Latest commit: 3857674

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 6, 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/B2BdNxg7zwkThmfV5nvJLcy5iom3
✅ Preview: https://primer-components-git-select-panel-fixes-primer.vercel.app

@@ -153,10 +147,11 @@ export function List(props: ListProps): JSX.Element {
let groups: (GroupProps | (Partial<GroupProps> & {renderItem?: typeof Item; renderGroup?: typeof Group}))[] = []

// Collect rendered `Item`s into `Group`s, avoiding excess iteration over the lists of `items` and `groupMetadata`:
const singleGroupId = useMemo(uniqueId, [])
Copy link
Member

@smockle smockle May 6, 2021

Choose a reason for hiding this comment

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

To clarify, this is here (as opposed to preceding line 154) to ensure the same number of hooks is called on each render, i.e. to avoid conditionally calling useMemo as the number of Groups changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that's exactly why. Hooks shouldn't be called inside loops or conditionals to ensure consistent execution order across renders.

Copy link
Member

@smockle smockle left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Contributor

@VanAnderson VanAnderson left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me!

@vercel vercel bot temporarily deployed to Preview May 6, 2021 20:41 Inactive
@dgreif dgreif enabled auto-merge (squash) May 6, 2021 20:42
@dgreif dgreif merged commit d20a599 into main May 6, 2021
@dgreif dgreif deleted the select-panel-fixes branch May 6, 2021 20:46
@github-actions github-actions bot mentioned this pull request May 6, 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.

3 participants