Replies: 3 comments 1 reply
-
The culprit id is being set here, lines 63 and 67: zag/packages/machines/menu/src/menu.connect.ts Lines 62 to 70 in 9e3d225 |
Beta Was this translation helpful? Give feedback.
-
This falls under the "Won't fix" category for now due to the code's design limitations. We made it this way to allow for:
As a temp. fix, I recommend aliasing item values with a unique id export function Menu() {
const uid = useId()
const service = useMachine(menu.machine, { id: uid})
const api = menu.connect(service, normalizeProps)
return (
<div>
<button {...api.getTriggerProps()}>
Actions <span {...api.getIndicatorProps()}>▾</span>
</button>
<div {...api.getPositionerProps()}>
<ul {...api.getContentProps()}>
<li {...api.getItemProps({ value: `${uid}/edit` })}>Edit</li>
</ul>
</div>
</div>
)
} We should mention this in the docs as a caveat. Redesigning this will lead to a breaking change upstream that I'm unprepared for. Thanks for understanding. |
Beta Was this translation helpful? Give feedback.
-
Changed my mind. I got a PR to fix this. Thanks for opening this @avallee |
Beta Was this translation helpful? Give feedback.
-
🐛 Bug report
Menu item ids are not scoped to their menu. Instead they are copied raw from the menu item's value property.
💥 Steps to reproduce
I used the example from https://zagjs.com/components/react/menu
Inspect the resulting dom. Note how
document.querySelectorAll('[id="edit"]')
returns two Elements in this example whiledocument.getElementById('edit')
only ever returns the first of these elements.💻 Link to reproduction
CodeSandbox reproduction: https://codesandbox.io/p/sandbox/busy-dust-fwhc9c
🧐 Expected behavior
The id prop on all elements of the page are meant to be unique. However, using identical values for a menu item in different menus results in this requirement being broken.
🧭 Possible Solution
Use scoping for the ids like most other parts of the menu are.
🌍 System information
📝 Additional information
Beta Was this translation helpful? Give feedback.
All reactions