Skip to content

[css-pseudo-4] Proxying pseudo-elements as "real" (<slot>) elements #12575

@noamr

Description

@noamr

This is an alternative idea to the many existing suggestions about improving access to pseudo-elements such as #12163.

The idea is that instead of figuring all kinds of different accessors to pseudo-elements, we would allow the author to create a real-DOM proxy for them, using a <slot> element. e.g.

<menu>
  <>Menu content<>
  <slot name="::backdrop"></slot>
</menu>

The slot element wouldn't render anything on its own, but would rather be a "reference" to a pseudo-element, the backdrop of the menu in this case.
This pseudo element is now available using querySelector or any other DOM APIs, it dispatches events in the normal way, it works with getComputedStyle and getBoundingClientRect(), and so forth. But rendering-wise it represents whatever the corresponding pseudo-element represents.

I think this would alleviate a lot of the issues raised about the pseudo-element specific JS APIs, though there are several things to be mindful around it.

@tabatkins @danielsakhapov @emilio @fantasai I wonder what you think about this approach.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions