-
Notifications
You must be signed in to change notification settings - Fork 51
PopoverPrimitive - Allow dynamic toggle element
#3189
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Pull Request Overview
This PR fixes a bug in the Hds::PopoverPrimitive component where dynamically swapped toggle elements would stop working, ensuring proper association between toggle and popover elements regardless of when they're rendered.
- Refactored the linking logic to run whenever toggle or popover elements are set up
- Added proper cleanup for toggle elements when they're removed from the DOM
- Improved positioning update handling to work with dynamically changed elements
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/components/src/components/hds/popover-primitive/index.ts | Core fix implementing dynamic linking between toggle and popover elements |
| showcase/tests/integration/components/hds/popover-primitive/index-test.js | Added comprehensive test coverage for dynamic toggle swapping and improved existing tests |
| .changeset/brave-owls-jump.md | Changelog entry documenting the new dynamic toggle element support |
packages/components/src/components/hds/popover-primitive/index.ts
Outdated
Show resolved
Hide resolved
didoo
left a comment
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.
Great PR! 🙌
I have left only a few suggestions, but nothing is a blocker.
showcase/tests/integration/components/hds/popover-primitive/index-test.js
Show resolved
Hide resolved
packages/components/src/components/hds/popover-primitive/index.ts
Outdated
Show resolved
Hide resolved
|
I followed the logic and I can see why this implementation is flagged as minor, which is great. Should we plan to test it with a release candidate though? |
shleewhite
left a comment
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.
Could you add an example of the toggle switching to the showcase?
[premise: no strong opinions] I thought the same at the beginning, but then I thought that maybe in this case it's not necessary, there is nothing UI related that a visual regression tests or a human test could catch, that the integration tests does not already catch |
Independently of the next release? We can, but I don't think it's necessary. |
This was my thinking as well. I can add the examples in the showcase if anyone has a strong opinion, but this more covers an edge case than provides additional intentional behavior. |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Dylan Hyun <[email protected]> Co-authored-by: Cristiano Rastelli <[email protected]>
42fc2b6 to
9e004ea
Compare
📌 Summary
If merged, this PR will fix a bug where the
Hds::PopoverPrimitivewould stop working if its toggle element was dynamically swapped, ensuring the popover remains correctly associated and positioned.🛠️ Detailed description
The previous implementation only ran the logic to link the toggle and popover (
popovertarget,aria-controls, and positioning) once when the component was first rendered. This caused a bug when a consumer dynamically changed the toggle element, as the new element was never linked to the popover.Example of Broken Behavior
In the code below, clicking the "Original" button worked, but after a state change, the "New" button would not trigger the popover.
🔗 External links
Jira ticket: HDS-4701
👀 Component checklist
💬 Please consider using conventional comments when reviewing this PR.
📋 PCI review checklist
Examples of changes to controls include access controls, encryption, logging, etc.
Examples include changes to operating systems, ports, protocols, services, cryptography-related components, PII processing code, etc.