How Radix UI asChild feature can be implemented in Svelte? #14867
Unanswered
raythurnvoid
asked this question in
Q&A
Replies: 2 comments 4 replies
-
Hey, i actually found a solution to this problem! Let me know if you have any questions. |
Beta Was this translation helpful? Give feedback.
1 reply
-
https://www.divotion.com/blog/how-to-create-an-aschild-prop-in-svelte-5 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://www.radix-ui.com/primitives/docs/guides/composition#composition
The use case is pretty simple, you have a Button component, you want to reuse it perhaps to trigger a Dropdown, you don't want to manually define all the accessibility requirements for buttons that trigger dropdowns everytime so you create a DropdownTrigger component that is meant to wrap any kind of button and listen to the proper events and add the proper aria-attributes.
I've been trying to figure this out for a while now (since Svelte 3), and i don't see any proper way of achieving this that doesn't end up in manually using querySelector, mutation observers (in case the original button is replaced with another button component), or some weird prop binding gymnastic.
If i had a magic wand i would ask 3 features to achieve this:
Or maybe i'm completely on the wrong way and the actual "best practice" would actually be to go with querySelector and mutation observer and do everything manually. I may understand this choice since these features would be mostly used by libraries and not by regular users. It just seems inefficient that svelte already knows when elements are mount/unmounted and i would need to re-write the same code but worse because mutation observer are async.
Beta Was this translation helpful? Give feedback.
All reactions