Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-shadow-parts] Specifying named slot in styling it's slotted content #8577

Open
castastrophe opened this issue Mar 13, 2023 · 2 comments

Comments

@castastrophe
Copy link

When discussing #7922, I raised a concern that the current implementation of ::slotted (which matches selectors based on their light DOM relationships, regardless of slot assignments) could be compounded by adding combinator support inside that pseudo.

This codepen demonstrates the confusion of styling :first-child/:last-child when using named slots b/c the selector is evaluated based on the :first-child in the light DOM but not the :first-child as assigned to a named slot.

I propose we create a new approach to styling slotted content that allows authors to identify 'default' or named slot. i.e.,

::resolved-slot('one', *:first-child) {

^ Not in love with that naming but we can bikeshed later.

Alternatively, @LeaVerou mentioned a possible alternative syntax entirely to indicate a shift from the web component's Shadow DOM to the light DOM. Perhaps:

@slotted {
  p:first-child { ... }
  div + div { ... }
}

with a named slot:

@slotted (name="one"){
  p:first-child { ... }
  div + div { ... }
}
@castastrophe
Copy link
Author

castastrophe commented Mar 13, 2023

I'll add, I rather like the ergonomics of making slotted an at-rule because it functions in many ways like container queries in the sense it creates a scope for the content inside it. It also makes me wonder if there additional conditions that might be able to be included.

@slotted one { ... }
@slotted two not (width: 400px) { ... }

@jaredcwhite
Copy link

I also really like the @slotted syntax for addressing this. I sort of wonder though if it should always be just be a single named or default slot, and not apply to all slots? Because the selectors are more specific and also related to their slotted-specific positioning, I don't know that it makes sense to write rules which simply "apply to all the slots". (Maybe…you could still opt-in using * or something?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants