[csswg-drafts] [css-scoping] Add abilty to select slot fallback content (#10771)

sorvell has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-scoping] Add abilty to select slot fallback content ==
### Background

It is often useful to select and style slot fallback content. When this content is in the same scope as the slot for which it is fallback, this is easily done; however, when the fallback content is rendered as a result of [flattening](https://dom.spec.whatwg.org/#find-flattened-slotables), it is not currently possible. 

For example, if "all content shown in slots should have an outline when hovered," a user can do the following, but this misses selecting any flattened fallback content.

```css
::slotted(:hover), slot > :hover {  
    outline: 2px solid;
}
```

Flattened assigned nodes are selectable via `::slotted(...)`, but this selector [cannot select fallback content](https://github.com/w3c/csswg-drafts/issues/5482#issuecomment-697635756).

The ability to select fallback content [will also be useful](https://github.com/w3c/csswg-drafts/pull/10586#discussion_r1727267445) for the `::has-slotted(...)` selector.

For example, if "leading padding should account for the presence of a slotted icon," a user can do the following, but again this misses selecting any flattened fallback content.

```css
.container:has(:has-slotted(*), slot > *)) {
  padding: 0.25rem;
}
```

### Proposal

Add complementary versions of `::slotted` and `:has-slotted` that function similarly but also include fallback content. Naming these is challenging of course. Let's start with:

* `::flat-slotted(...)`: the same as `::slotted(...)` but includes all fallback content, flattened or not.
* `:has-flat-slotted(...)`: the same as `:has-slotted(...)` but includes all fallback content, flattened or not.

### Alternatives Considered

Another possibility would be to have selectors that exclusively select fallback content. This is strictly more powerful since fallbacks are currently not specifically selectable. However, use cases for this are not currently clear so it seems unnecessary.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10771 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 23 August 2024 15:13:02 UTC