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-selectors] :first-assigned / :last-assigned / :nth-assigned #6620

Open
castastrophe opened this issue Sep 16, 2021 · 1 comment
Open

Comments

@castastrophe
Copy link

When styling web components with multiple named slots, the :first-child / :last-child / :nth-child pseudo-classes, when used inside the :slotted() pseudo-element, represent an element's relationship to it's light DOM siblings.

CodePen: https://codepen.io/castastrophe/pen/yLXpagw

image

Given the following markup:

    <x-component>
        <span slot="one" id="first">Light DOM: span 1</span>
        <span slot="two" id="nth-2">Light DOM: span 2</span>
        <span slot="one" id="nth-3">Light DOM: span 3</span>
        <span slot="two" id="nth-4">Light DOM: span 4</span>
        <span id="last">Light DOM: span 5</span>
    </x-component>
  • We expect :slotted(*:first-child) to apply only to #first.
  • We expect :slotted(*:last-child) to apply only to #last.
  • We expect :slotted(*:nth-child(2)) to apply only to #nth-2.

Given named slots, many authors expect these pseudo-classes to represent the element's relationship to it's fellow slotted siblings as such:

  • :slotted(*:first-child) expected to apply to #first, #nth-2, and #last.
  • :slotted(*:last-child) expected to apply to #nth-3, #nth-4, #last.
  • :slotted(*:nth-child(2)) expected to apply to #nth-3, #nth-4, #last.
  • [name="two"]:slotted(*:first-child) expected to apply only to #nth-2.
  • [name="one"]:slotted(*:last-child) expected to apply only to #nth-3.

Rather than muddy the existing behavior of :first-child etc., I propose we add :first-assigned / :last-assigned / :nth-assigned() which will represent a slotted element's relationship to it's sibling assigned nodes. ++ @Westbrook for the naming proposal!

@jpzwarte
Copy link

Just ran into this, but i figured out a workaround: ::slotted(:nth-child(1 of :not([slot]))). This only matches the first child in the default slot.

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