Skip to content

[css-pseudo] Add ::backdrop and ::view-transitions to the CSSPseudoElement's allowed pseudo-elements list #13804

@danielsakhapov

Description

@danielsakhapov

CSSPseudoElement is currently only defined for ::after, ::before and ::marker, but ::backdrop and ::view-transitions also make sense to be added there.

E.g. ::backdrop is useful to close a dialog when its backdrop is clicked, without interfering with clicks inside the dialog content.

dialog.addEventListener('click', (event) => {
  if (event.pseudoTarget?.type === '::backdrop') {
    dialog.close();
  }
});

without involving any intersection code to determine if the dialog itself vs ::backdrop has been clicked.

And ::view-transitions can be used to do a geometry-aware view transition we can read the bounding rect of ::view-transition-old to set a custom animation origin.

document.addEventListener('transitionstart', (event) => {
  if (event.pseudoTarget?.type === '::view-transition-old') {
    const rect = event.pseudoTarget.getBoundingClientRect();
    setTransformOrigin(rect);
  }
});

or intercept VT mid-flight to start a new one, while knowing the coordinates of the currently aminating element to avoid sudden jumps and such.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions