Skip to content

Consider using Shadow Parts as an alternative to pseudo-elements for structure and user styling #190

Open
@bgrins

Description

@bgrins

I'd like to consider Shadow Parts as an alternative to using nested pseudo-element structure for user styling. Maybe this has already been discussed and dismissed, but I wanted to raise this coming out of mozilla/standards-positions#677.

I'm not sure it's ideal to expose the deep pseudo-element tree to developers - both ergonimcally, and in the case where a UA may want to change the internal representation of the various parts i.e. if future iterations introduce new features which would benefit from a change in the tree.

So instead of having something like

::page-transition
├─ ::page-transition-container(root)
│  └─ ::page-transition-image-wrapper(root)
│     ├─ ::page-transition-outgoing-image(root)
│     └─ ::page-transition-incoming-image(root)
│...

with

::page-transition-container(root)::image-wrapper::outgoing-image {
  /* … */
}

Could there be something like:

<div part="page-transition">
├─ <div part="page-transition-root-container">
│  └─ <div part="page-transition-root-image-wrapper">
│     ├─ <div part="page-transition-root-outgoing-image">
|     └─ <div part="page-transition-root-incoming-image">
|...

with

:root::part(page-transition-root-outgoing-image) {
  /* … */
}

Some of the potential challenges with this approach (at least the ones I've thought of) are:

  • What if a user attached their own Shadow Root to the root element? That's not allowed on html elements, but what would happen if a developer replaced the documentElement with an element that does support them? Perhaps the feature isn't supported in that case.
  • I don't believe UA shadow parts have been exposed to content CSS before so this would have to be an exception

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions