primitives: [Dialog][DropdownMenu] Cannot compose `DropdownMenu.Item` and `Dialog.Trigger` in latest
In previous versions it was possible to do <Dialog.Trigger as={DropdownMenu.Item} /> to trigger a dialog from a dropdown menu item but this is no longer working.
Before
https://codesandbox.io/s/unruffled-cache-g7cnm?file=/src/App.js
After
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 18 (4 by maintainers)
@andrevenancio I realised today that the controlled composition without a trigger is not really advisable because you lose some accessibility (aria attributes and things for screen readers).
Here’s the way we’ll be proposing for now to keep things accessible https://github.com/radix-ui/primitives/pull/818/files#diff-8e744cac508a099375ef58105d63d5be33aebf4ba5d37db4d4630f425a460898R402
I’ll be having a think about ways we can improve this DX going forward but this at least provides a usable composition of the two in the meantime.
Having examples of Dropdown + Dialog composition in the docs would be really great, given how often we get asked about those. If anything it would make our life easier by having a place to point people to.
Added an issue here: https://github.com/radix-ui/website/issues/384
@andrevenancio You shouldn’t need your
pointerEventslogic when the following PR is released https://github.com/radix-ui/primitives/pull/819 🎉Keyboard should also be okay when this PR is released https://github.com/radix-ui/primitives/pull/818
Since your example is not using the
Dialog.Trigger, I recommend manually returning focus to theDropdownMenu.Triggerfrom the dialog content’sonCloseAutoFocusevent for accessibility purposes. Otherwise, keyboard users/screen readers will lose their place in the document.Curious fact: if you add a
disabledprop to theDialog.triggerit works (by click only), which makes me think that some event handler is overwriting another instead of be composing themI wonder if it is worth documenting this in the dropdown examples as I since realised a better way that allows the composition @jgoux was looking for: https://codesandbox.io/s/magical-grass-j85kbz?file=/src/App.js
it allows multiple items to open different dialogs.
@asherccohen does this help? https://codesandbox.io/s/confident-dan-lxsf9r?file=/src/App.tsx
Yes this is because of this :