This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
[✨] Allow classes with Slots for selecting with global() #93
Labels
[STAGE-2] incomplete implementation
Remove this label when implementation is complete
[STAGE-2] not fully covered by tests yet
Remove this label when tests are verified to cover the implementation
[STAGE-2] unresolved discussions left
Remove this label when all critical discussions are resolved on the issue
[STAGE-3] docs changes not added yet
Remove this label when the necessary documentation for the feature / change is added
[STAGE-3] missing 2 reviews for RFC PRs
Remove this label when at least 2 core team members reviewed and approved the RFC implementation
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:slot
and theSlot
component.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
Slot
element only allowsname
field 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
Slot
element is not an actual slot, the path I can see would be to allow theclass
property 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
:empty
would 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.
The text was updated successfully, but these errors were encountered: