v160 · css · view transitions
Design-system tabs
The case that motivated the feature. <ds-tabs> owns a sliding indicator inside its shadow tree, while the tabs and panels are the consumer’s slotted light DOM. The component runs an element-scoped transition on itself, lists its own shadow root and passes a direction type — so the private indicator and the public panel animate in one transition, with no ::part() leak and the rest of the page still interactive.
shadowRoots dictionary member…Switch tabs
Overview
The underline is drawn inside the component’s shadow tree and named there. This panel is your markup, named by your stylesheet.
Details
Arrow keys move between tabs; Home and End jump to the ends. Each switch is one element-scoped view transition on <ds-tabs>.
Changelog
Direction comes from a view transition type: forward slides in from the right, backward from the left.
the component
class DsTabs extends HTMLElement {
#root = this.attachShadow({ mode: "closed" }); // closed is fine: we hold it
// shadow CSS: .indicator { view-transition-name: ds-indicator; }
// :host::view-transition-group(ds-indicator) { animation-duration: 300ms; }
select(next) {
const dir = next > this.index ? "forward" : "backward";
const update = () => this.#apply(next);
if (!("startViewTransition" in Element.prototype)) return update();
const t = this.startViewTransition({
update,
types: [dir],
shadowRoots: [this.#root], // the component opts its own tree in
});
t.ready.catch(() => {});
}
}
The consumer keeps naming its own panel (view-transition-name: ds-panel) in its own stylesheet; the component keeps ds-indicator private. Because the transition starts on the host, the pseudo-elements hang off <ds-tabs>, so the component can style them from inside with :host::view-transition-group(…) and the page with ds-tabs::view-transition-…. Without the feature the indicator simply jumps while the panel still animates.