@use "../utils/css/mixins"; @layer wp-ui { @layer utilities, components, compositions, overrides; @layer components { .tablist { display: flex; align-items: stretch; overflow-inline: auto; overscroll-behavior-inline: none; --direction-start: left; --direction-end: right; &:dir(rtl) { --direction-start: right; --direction-end: left; } position: relative; &[data-orientation="horizontal"] { --fade-width: 4rem; --fade-gradient-base: transparent 0%, #000 var(--fade-width); --fade-gradient-composed: var(--fade-gradient-base), #000 60%, transparent 50%; width: fit-content; /* Paint outside the list when the tabs fit. Shadows and outlines * do not contribute to the measured scrollable width. */ &:not(.is-scrolling) { overflow: visible; } &.is-overflowing-first { mask-image: linear-gradient(to var(--direction-end), var(--fade-gradient-base)); } &.is-overflowing-last { mask-image: linear-gradient(to var(--direction-start), var(--fade-gradient-base)); } &.is-overflowing-first.is-overflowing-last { mask-image: linear-gradient(to right, var(--fade-gradient-composed)), linear-gradient(to left, var(--fade-gradient-composed)); } &.is-minimal-variant { gap: 1rem; } } &[data-orientation="vertical"] { flex-direction: column; } } .indicator { @media not (prefers-reduced-motion) { transition-property: translate, width, height; transition-duration: 0.2s; transition-timing-function: ease-out; } position: absolute; pointer-events: none; z-index: 1; background-color: var(--wpds-color-foreground-interactive-neutral); @media not (forced-colors: active) { .tablist:has( > .tab[aria-selected="true"]:not( [data-disabled] ):focus-visible ) & { background-color: var(--wpds-color-foreground-interactive-neutral-active); } } /* Forced colors mode replaces other background colors with `Canvas`. */ @media (forced-colors: active) { background-color: CanvasText; } &[data-orientation="horizontal"] { /* stylelint-disable-next-line logical-css/require-logical-properties -- Physical properties are necessary for the indicator to work as expected. */ left: 0; bottom: 0; height: var(--wpds-border-width-focus); width: var(--active-tab-width); translate: var(--active-tab-left) 0; } &[data-orientation="vertical"] { top: var(--wpds-dimension-padding-md); inset-inline-start: 0; width: var(--wpds-border-width-focus); height: max(0px, calc(var(--active-tab-height) - 2 * var(--wpds-dimension-padding-md))); translate: 0 var(--active-tab-top); } } .tab { /* Resets */ border-radius: 0; background: transparent; border: none; box-shadow: none; outline: none; /* The focus indicator is drawn inside the tab. */ padding: 0; /* Positioning */ z-index: 1; flex: 1 0 auto; position: relative; display: flex; align-items: center; /* Appearance */ cursor: var(--wpds-cursor-control); /* Typography */ font-family: var(--wpds-typography-font-family-body); font-size: var(--wpds-typography-font-size-md); white-space: nowrap; /* Characters in some languages (e.g. Japanese) may have a native higher line-height. */ line-height: 1.2; font-weight: 400; color: var(--wpds-color-foreground-interactive-neutral); &:is([aria-selected="true"], [data-disabled]) { cursor: default; } &[data-disabled] { color: var(--wpds-color-foreground-interactive-neutral-disabled); @media (forced-colors: active) { color: GrayText; } } &:not([data-disabled]):is( :not([aria-selected="true"]):hover, :not([aria-selected="true"]):active, :focus-visible ) { color: var(--wpds-color-foreground-interactive-neutral-active); &::after { background-color: var(--wpds-color-background-interactive-neutral-weak-active); box-shadow: 0 0 0 var(--_wp-ui-tabs-background-overhang, 0) var(--wpds-color-background-interactive-neutral-weak-active); opacity: 1; } } /* Interaction background and focus indicator. */ &::before, &::after { position: absolute; z-index: -1; pointer-events: none; border-radius: var(--wpds-border-radius-sm); /* Animation */ opacity: 0; @media not (prefers-reduced-motion) { transition: opacity 0.1s linear; } } /* Only keyboard focus draws an outline, which forced colors mode * keeps, so a hovered tab does not look focused there. */ &:focus-visible::after, .is-minimal-variant.is-scrolling[data-orientation="horizontal"] &:focus-visible::before { @include mixins.focus-ring(); outline-offset: calc(-1 * var(--wpds-border-width-focus)); opacity: 1; } [data-orientation="horizontal"] & { --_wp-ui-tabs-background-inset: calc((48px - var(--wpds-dimension-size-md)) / 2); padding-inline: var(--wpds-dimension-padding-lg); height: 48px; /* TODO: use semantic size/height tokens when available */ scroll-margin: 24px; /* Leave space between the background and the selection indicator. */ &::after { content: ""; inset: var(--_wp-ui-tabs-background-inset); } } /* Minimal tabs are as wide as their labels, so the background * extends into the gap between them. A shadow paints that overhang * because, unlike a negative inset, it adds no scrollable overflow. */ .is-minimal-variant[data-orientation="horizontal"] & { --_wp-ui-tabs-background-overhang: var(--wpds-dimension-padding-xs); padding-inline: 0; &::after { /* Let the clip alone shape the outer corners. */ border-radius: 0; clip-path: inset(calc(-1 * var(--_wp-ui-tabs-background-overhang)) round var(--wpds-border-radius-sm)); inset-block: calc(var(--_wp-ui-tabs-background-inset) + var(--_wp-ui-tabs-background-overhang)); inset-inline: 0; outline-offset: calc(var(--_wp-ui-tabs-background-overhang) - var(--wpds-border-width-focus)); } } /* An SVG can paint past its viewport without making the list scroll. * Use the native outline when a custom render wraps or omits the SVG. */ .is-minimal-variant:not(.is-scrolling)[data-orientation="horizontal"] &:focus-visible:has(> .tab-children > .focus-ring)::after { outline: none; } .is-minimal-variant:not(.is-scrolling)[data-orientation="horizontal"] &:focus-visible:not(:has(> .tab-children > .focus-ring))::after { border-radius: max(0px, var(--wpds-border-radius-sm) - var(--_wp-ui-tabs-background-overhang)); } .is-minimal-variant.is-scrolling[data-orientation="horizontal"] & { /* Paint the ring inside the tab so only the background can be * clipped. */ &::before { content: ""; z-index: 0; inset-block: var(--_wp-ui-tabs-background-inset); inset-inline: 0; } &:focus-visible::after { outline: none; } } [data-orientation="vertical"] & { padding: var(--wpds-dimension-padding-md); min-height: var(--wpds-dimension-size-lg); &::after { content: ""; inset: 0; } } } .focus-ring { display: none; pointer-events: none; .is-minimal-variant:not(.is-scrolling)[data-orientation="horizontal"] .tab:focus-visible > .tab-children > & { display: block; position: absolute; inset-inline-start: 0; top: var(--_wp-ui-tabs-background-inset); width: 100%; height: calc(100% - 2 * var(--_wp-ui-tabs-background-inset)); container-type: size; overflow: visible; } rect { /* Clip the outer half of the stroke to draw it inside the background. */ x: calc(-1 * var(--_wp-ui-tabs-background-overhang)); width: calc(100% + 2 * var(--_wp-ui-tabs-background-overhang)); height: 100%; /* SVG clamps the two axes independently. Keep the corners circular. */ rx: min(var(--wpds-border-radius-sm), 50cqh, 50% + var(--_wp-ui-tabs-background-overhang)); fill: none; stroke: var(--focus-color, var(--wpds-color-stroke-focus)); stroke-width: calc(2 * var(--wpds-border-width-focus)); clip-path: inset(0 round var(--wpds-border-radius-sm)) fill-box; @media (forced-colors: active) { stroke: CanvasText; } } } .tab-children { flex-grow: 1; display: flex; align-items: center; [data-orientation="horizontal"] & { justify-content: center; } [data-orientation="vertical"] & { justify-content: start; } } } } /* Unlayered theme rules for svg can expose idle rings or clip the stroke. */ .tab .focus-ring { all: revert-layer; }