[✨] Allow classes with Slots for selecting with global() #169
Replies: 3 comments 2 replies
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
We moved this issue to |
Beta Was this translation helpful? Give feedback.
-
|
I think frameworks have a choice to make if things such as components and slots have a real world DOM element representation. Angular and web-components such as lit choose yes, while most JSX-based frameworks choose no. There are pros and cons for both choices. I think in the case you are describing, you are wishing that we would have a DOM element so that you can style it, but we don't. I don't think it would be easy to add without breaking everyone else, so we probably will not do it. I think the work around here is to maybe use inlined components and then look at |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem?
When building components that rely on slots and Shadow DOM, I used various selectors and tricks with the slot element before; however, the CSS options became pretty limited when using the
q:slotand theSlotcomponent.One trick I have used before is to assign a class to a slot and select the slotted elements only in that:
https://stackblitz.com/edit/lit-classed-slot-selector?file=src%2Fmy-element.ts
However, given how the
Slotelement only allowsnamefield and it is not an actual element, I cannot do this anymore:https://stackblitz.com/edit/qwik-classed-slot-selector?file=src%2Froutes%2Findex.tsx
Describe the solution you'd like
Given how the
Slotelement is not an actual slot, the path I can see would be to allow theclassproperty and automatically attach that to all slotted elements within the particular slot. That way, the:global()could have a valid selector.would render as:
Describe alternatives you've considered
The workaround is to wrap each slot into an extra parent and use that for selecting slotted elements. While it works, it introduces additional entries in the DOM that should not be needed in the first place. Furthermore, it complicates the necessary CSS as selectors such as
:emptywould see the host component as filled even if no elements were slotted.Alternatively, one could drop Slots altogether and use props, but I consider that an anti-pattern.
Additional context
The main reason why this is important for me is that I want to use CSS Grid to align slotted elements when the host element is not empty. When nothing is passed into the slots, the whole component renders nothing, effectively removing itself from a bigger component's layout.
Beta Was this translation helpful? Give feedback.
All reactions