next: [data-state]
Attribute Conflicts in Component Compositions
#1177
Replies: 2 comments
-
I am running into this same issue when using a tooltip with the collapsible component. |
Beta Was this translation helpful? Give feedback.
-
I'm still deciding how to approach this. I feel the explicit With that in mind, I also want to support more advanced use cases and composition, so perhaps we can add either a In the meantime, this can be accomplished in userland, albeit not pretty, but possible: <Tooltip.Trigger>
{#snippet child({ props })}
<Toggle.Root {...props} data-tooltip-state={props['data-state']}>
{#snippet child({ props })}
<button {...props} data-toggle-state={props['data-state']}>I have [data-state] from the Toggle, not from the Tooltip.</button>
{/snippet}
</Toggle.Root>
{/snippet}
</Tooltip.Trigger> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Based on #823 , there's a systemic issue with component composition where multiple components using the same
[data-state]
attribute conflict with each other. IMO it is something to decide before 1.0. While the Toggle and Tooltip example demonstrates this problem, it affects any combination of components that rely on the[data-state]
(or similiar) attribute for styling and state management.Current Behavior
Expected Behavior
Elements should be styleable based on each component's state independently, regardless of how many components are composed together
Impact
Example
Details
Current Style Conflicts
Details
Proposed Solutions
Solution 1: Component-Specific Data Attributes
Use distinct data attributes for each component type:Each component gets its own attribute
Pros:
Cons:
Solution 2: Combined State Values
Use a single
data-state
attribute with combined values:Pros:
Cons:
Reproduction
https://stackblitz.com/edit/stackblitz-starters-xdgpeu?file=src%2Froutes%2F%2Bpage.svelte
Logs
No response
System Info
Severity
blocking an upgrade
Beta Was this translation helpful? Give feedback.
All reactions