v160 · javascript · cssom · carousels

Scroll-button directions

The subtle edge case (CSSWG #14528). ::scroll-button() accepts physical directions (left right up down) and logical ones (inline-start inline-end block-start block-end). A CSSPseudoElement you create with pseudo() keeps the coordinate space you wrote; one the browser hands you through event.pseudoTarget always uses the logical name. Flip the carousel to right-to-left and the “left” button becomes inline-end.

Probing this browser…

1 · pseudo() keeps your coordinate space

track.pseudo("::scroll-button(d)") in the current direction
dreturnedselectorTextspec expects
pick a direction

2 · pseudoTarget uses logical names

Click the black CSS arrow buttons under the track (the ::scroll-button() pseudo-elements). The HTML buttons are the keyboard path and the production-safe controls.

No scroll-button click yet.

migration note

// Pre-160 code often did this — it breaks on scroll buttons:
const key = pseudo.selectorText ?? pseudo.type;   // "::scroll-button" → matches nothing

// Compare against the LOGICAL name for browser-created objects:
carousel.addEventListener("click", (e) => {
  const p = e.pseudoTarget;
  if (p?.selectorText === "::scroll-button(inline-end)") track("next");
});
// …but a user-created one keeps what you passed:
carousel.pseudo("::scroll-button(left)").selectorText;   // "::scroll-button(left)"

see also