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

Support for pseudo elements with ::slotted() selectors #655

Closed
ghost opened this issue Aug 10, 2017 · 27 comments
Closed

Support for pseudo elements with ::slotted() selectors #655

ghost opened this issue Aug 10, 2017 · 27 comments

Comments

@ghost
Copy link

ghost commented Aug 10, 2017

This was discussed in Issue #331 but I don't think we came to a conclusion.

The CSS Scoping spec does not explicitly disallow pseudo elements in the "selector list" like the specs for :not() and :matches() do. Neither does it currently explicitly allow pseudo elements after ::slotted.

Should we:

  1. Not support other pseudo elements on ::slotted selectors
  2. Support other pseudo elements inside ::slotted(): ::slotted(div::before)
  3. Support other pseudo elements after ::slotted(): ::slotted(div)::before

@hayatoito @tabatkins

@abdonrd
Copy link
Contributor

abdonrd commented Aug 11, 2017

Thanks for register! I would like use it.

Example: https://jsbin.com/jamiyitace/edit?html,output

@tabatkins
Copy link

The pseudo-elements aren't slotted, so (2) is out.

(3) works for me from a spec perspective, and seems useful for authors; there's no good reason behaviorally to disallow it, I think? Only question is if it's reasonable engine-wise.

@rniwa
Copy link
Collaborator

rniwa commented Aug 13, 2017

The last time we discussed this, the question was what would happen if the slotted element had already specified ::before. Given we've defined the cascading order for slotting, that should no longer be a question?

@TakayoshiKochi
Copy link
Member

I think cascading order or specificity of these selectors are already clear in the current spec.

@ghost
Copy link
Author

ghost commented Aug 14, 2017

Generated content like ::before should match rules from the same scopes and using the same cascading order as the actual element, I presume.

@tabatkins
Copy link

Yeah, there's no reason to be different there.

@ghost
Copy link
Author

ghost commented Aug 14, 2017

Regarding engines, implementing this in Blink is just a matter of allowing it in the selector parser. Adding a simple check made ::before/::after/::first-line/::first-letter seemingly work out-of-the-box.

@ghost
Copy link
Author

ghost commented Aug 15, 2017

An admissive Blink implementation with tests: https://chromium-review.googlesource.com/c/616042

@abdonrd
Copy link
Contributor

abdonrd commented Aug 15, 2017

Thanks @rune-opera! 👏

@ghost
Copy link
Author

ghost commented Aug 21, 2017

So, the proposal is to resolve as option (3). Allow pseudo element after ::slotted() like: ::slotted(*)::before.

Should this be scheduled for resolution at a csswg telcon?

@tabatkins
Copy link

Done w3c/csswg-drafts#1747

@tabatkins
Copy link

And done; the tree-abiding pseudos (::before, ::after, ::marker, and ::placeholder) can all go after ::slotted() now.

@abdonrd
Copy link
Contributor

abdonrd commented Sep 26, 2017

@rune-opera @tabatkins and the selectors like :hover, :first-child, etc should be inside the ::slotted(), right?

::slotted(div:first-child) {}

@ghost
Copy link
Author

ghost commented Sep 26, 2017

@abdonrd Yes.

@abdonrd
Copy link
Contributor

abdonrd commented Sep 26, 2017

Thanks! :)

@abdonrd
Copy link
Contributor

abdonrd commented Oct 13, 2017

Thanks @robdodson for filled at Webkit! https://bugs.webkit.org/show_bug.cgi?id=178237

@heruan
Copy link

heruan commented Nov 10, 2017

Does ::slotted(div:first-child) {} select the :first-child in the slot, or in the light DOM?

<dom-module id="my-element">
  <template>
    <style>
      slot[name="a"]::slotted(div:first-child) {
        background-color: red;
      }
    </style>
    <slot></slot>
    <slot name="a"></slot>
  </template>
</dom-module id="my-element">

<my-element>
  <div>Bar</div>
  <div slot="a">Foo</div>
  <div slot="a">Bar</div>
</my-element>

Is "Foo" supposed to have a red background? In latest Chrome, it doesn't.

@web-padawan
Copy link

@hayatoito Do I understand correctly that this has been only implemented in Blink for ::before and ::after, but not for the ::placeholder?

The following CSS doesn't work in Chrome, Safari and Firefox:

::slotted(input)::placeholder {
  color: red;
}

Live example: https://jsfiddle.net/webpadawan/v3ksqhcx/

@hayatoito
Copy link
Contributor

@web-padawan
Could you file a bug in http://crbug.com/ for Blink?

@emilio
Copy link

emilio commented Jan 23, 2019

Works in Firefox Nightly FWIW, and I think @lilles fixed it on Blink too.

@lilles
Copy link

lilles commented Jan 23, 2019

Fixed: https://crbug.com/902518

@alexstep-dev
Copy link

Would be grate to use this kind of selectors:

::slotted(div[slot="content"]::-webkit-scrollbar) {
  display: none;
}

@annevk
Copy link
Collaborator

annevk commented Apr 18, 2019

@BinaryCry feature requests are best done in a new issue, though please take https://whatwg.org/faq#adding-new-features into account. Thanks!

@egucciar
Copy link

Anyone else observing that Safari and Chrome on iOS are not working with this ?

@rniwa
Copy link
Collaborator

rniwa commented Apr 29, 2019

WebKit bug tracks the issue on iOS.

@xgqfrms
Copy link

xgqfrms commented Sep 4, 2020

::slotted & :host

https://developer.mozilla.org/en-US/docs/Web/CSS/::slotted

https://developer.mozilla.org/en-US/docs/Web/CSS/:host

https://developers.google.com/web/fundamentals/web-components/shadowdom

demo

/* Selects any element placed inside a slot */

::slotted(*) {
  font-weight: bold;
}

/* Selects any <span> placed inside a slot */
::slotted(span) {
  font-weight: bold;
}
/* Selects a shadow root host */
:host {
  font-weight: bold;
}

@web-padawan
Copy link

Here is another WebKit bug for ::slotted(input)::placeholder support.

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

No branches or pull requests