-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(react-headless-components-preview): share anchor-name across positioned popovers #36347
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "usePositioning: share anchor-name across positioned popovers so a Tooltip and Menu can attach to one trigger", | ||
| "packageName": "@fluentui/react-headless-components-preview", | ||
| "email": "mgodbolt+microsoft@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,9 +72,31 @@ export function usePositioning(options: PositioningProps): PositioningReturn { | |
| if (!effectiveTarget) { | ||
| return; | ||
| } | ||
| effectiveTarget.style.setProperty('anchor-name', anchorName); | ||
|
|
||
| // `anchor-name` is a comma-separated list. Append this instance's name | ||
| // instead of overwriting so that multiple positioned popovers can share a | ||
| // single trigger (e.g. a Tooltip on hover and a Menu on click attached to | ||
| // the same button) without clobbering each other's anchor. On cleanup we | ||
| // remove only our own name, preserving any others still in use. | ||
| const readAnchorNames = () => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: define this function in module scope rather than in the closure. |
||
| effectiveTarget.style | ||
| .getPropertyValue('anchor-name') | ||
| .split(',') | ||
| .map(name => name.trim()) | ||
| .filter(Boolean); | ||
|
|
||
| const names = readAnchorNames(); | ||
| if (!names.includes(anchorName)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check could be included in |
||
| effectiveTarget.style.setProperty('anchor-name', [...names, anchorName].join(', ')); | ||
| } | ||
|
|
||
| return () => { | ||
| effectiveTarget.style.removeProperty('anchor-name'); | ||
| const remaining = readAnchorNames().filter(name => name !== anchorName); | ||
| if (remaining.length > 0) { | ||
| effectiveTarget.style.setProperty('anchor-name', remaining.join(', ')); | ||
| } else { | ||
| effectiveTarget.style.removeProperty('anchor-name'); | ||
| } | ||
| }; | ||
| }, [effectiveTarget, anchorName]); | ||
|
|
||
|
|
||
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.
we should also add a e2e test that covers the Menu + Tooltip scenario mentioned in the issue