-
Notifications
You must be signed in to change notification settings - Fork 535
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
Conversation
🦋 Changeset detectedLatest commit: 3857674 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/primer/primer-components/B2BdNxg7zwkThmfV5nvJLcy5iom3 |
@@ -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, []) |
There was a problem hiding this comment.
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 Group
s changes?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this 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!
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 theAnchorOverlay
component. This allows you to have a fixed height/width on the overlay if list items are loaded asynchronously after the overlay opens.Item
data to include anid
field, which could be astring
ornumber
. We should allow these to be passed in onItemProps
and use them as thekey
prop when present. We also don't want to use them on the actualItem
element in the DOM as they will likely not be globally uniqueActionList
will create a single group wrapper if it is passed a list of items without any group details. This group was previously receiving auniqueId
for itsgroupId
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 triggeredlist
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