Concepts
Part and state attributes
How to select and style every part with data-primitives-part, and its state with data-* and ARIA attributes, the same in every framework.
Every element a primitive renders says which part it is, and its state is attributes: select and style them, never class names the library does not have.
The part attribute
Every element carries data-primitives-part="<component>-<part>":
| element | attribute |
|---|---|
| a dialog's trigger | data-primitives-part="dialog-trigger" |
| a dialog's popup | data-primitives-part="dialog-popup" |
| an alert dialog's popup (Dialog's part, named by its root) | data-primitives-part="alert-dialog-popup" |
| a context menu's item (Menu's part, named by its root) | data-primitives-part="context-menu-item" |
| a tab | data-primitives-part="tabs-tab" |
| the tab indicator | data-primitives-part="tabs-indicator" |
| a combobox's hidden inputs | data-primitives-part="combobox-hidden-input" |
| a calendar's cell, and a range calendar's | data-primitives-part="calendar-cell", "range-calendar-cell" |
One attribute for the whole library, since many components have parts of the same name. Your tests, styles and tools can rely on it in every framework.
State attributes
A boolean state is an attribute that is present (with an empty value) or absent, never
"false", so [data-open] and Tailwind's data-open: variant just work.
| attribute | on |
|---|---|
data-open | an open overlay (a popup, its positioner, its arrow, a dialog's backdrop and viewport); an open collapsible, accordion item and their parts |
data-closed | a rendered overlay part that is not open (its exit runs, or the Portal's keepMounted keeps it, hidden); a closed collapsible, accordion item and their parts (with data-open: exactly one is present) |
data-panel-open | a collapsible's or an accordion's trigger while its panel is open |
data-popup-open | a trigger while its overlay is open: the active one of several detached triggers only (a Select's, a CascadeSelect's, a date picker's or a color picker popover's trigger, a Combobox's or an Autocomplete's input, input group and trigger too, a context menu's area) |
data-starting-style | an element that just mounted, for one frame: transition from it |
data-ending-style | an element whose exit animation runs; it unmounts (or is hidden) once its animations end: an overlay, a tabs panel, a collapsible or accordion panel |
data-selected | a selected tab and its panel, a selected select, combobox or listbox option, a cascade select's option on the chosen path, a selected tag of a tag group, a selected color swatch picker option, a chosen calendar date |
data-checked, data-unchecked, data-indeterminate | a checkbox's state (exactly one is present) and its indicator; a switch's and a radio's data-checked or data-unchecked, on its thumb or indicator too; a menu checkbox or radio item's, and its indicator's; a segmented control's item and its text; a rating's star (the one that holds the value is checked) |
data-indeterminate, data-progressing, data-complete | a progress bar's status, on every part (exactly one is present): no value, a value below max, max; data-complete also on every part of an OTP field whose code is complete |
data-scrubbing | every part of a number field while its scrub area scrubs |
data-readonly | a read-only number field's, OTP field's, date field's, time field's or range field's parts (and a read-only calendar or switch); a read-only rating and its stars; a read-only password input's, search field's or editable's parts |
data-pressed | a pressed toggle |
data-multiple | a toggle group or a listbox with multiple |
data-placeholder | a Select or a CascadeSelect showing its placeholder; a date or time field's segment with no value; an editable's preview showing its placeholder |
data-type | a date or time field's segment: its type (era, year, month, day, hour, minute, second, dayPeriod, timeZoneName, literal; a value) |
data-empty | a combobox's or an autocomplete's list with no item; a command's list with no item shown (once mounted); a tag group's root and list with no tag (once mounted); a tags input's root and control with no tag; a search field's parts and an editable's parts while the value is empty; a file upload's parts with no accepted file |
data-editing | a tags input's tag while its tag input edits it; an editable's parts while it edits |
data-visible | a password input's parts while its text is shown |
data-copied, data-failed | a clipboard's parts while its last copy succeeded, or failed, until its timeout |
data-drop-target | a drop zone, or a file upload's Dropzone and Root (and its parts), while a drag of files is over it |
data-rejected | a file upload's Item, and its parts, for a rejected file |
data-dragging | a slider (a color slider, a color area, a color wheel) while a pointer drags a thumb; a carousel's slides' container while a mouse drags them |
data-channel | a color slider's and a color field's parts, a color area's inputs: the color channel they edit (a value: hue, saturation, lightness, brightness, red, green, blue, alpha) |
data-axis | a color area's input: x or y (a value) |
data-format | a color picker and its FormatSelect: its format (a value: hex, rgb, hsl, hsb) |
data-index | a slider thumb's value index; an OTP field slot's index; a virtual list's rendered option's index; a carousel slide's index (a value) |
data-loading | a virtual list while loading (with aria-busy="true"); a command's list while loading |
data-required | a required checkbox, switch, radio group, segmented control or rating, and its radios; every part of a required number field, OTP field, date or time field, or range field |
data-invalid, data-valid | a field that shows an error, or that validated and is valid; data-invalid also on every part of a date, time or range field whose value is out of range or unavailable (a range: or whose end is before its start), and on a typed picker's segments whose complete entry is |
data-dirty, data-touched, data-filled, data-focused | a field whose value changed, whose control lost focus once, whose value is not empty, whose control has focus; data-filled also on an OTP field slot that holds a character |
data-highlighted | the menu item, select, cascade select, combobox, autocomplete or command option the keyboard or the pointer points at; a listbox's focused option; a rating's star drawn filled, whole or half (by the value, or the pointer's preview) |
data-half | a rating's star drawn half filled |
data-instant | a tooltip that opened with no delay (focus, or a hand-off in its group); a hover card moved to another of its triggers |
data-expanded | a toast viewport and its toasts while the pointer is over it or the keyboard is in it; a cascade select's parent option while its level is open |
data-has-children | a cascade select's parent option (an item with children) |
data-depth | a cascade select's level: its depth, 0 for the first (a value) |
data-limited | a toast queued past the limit (with inert) |
data-swiping, data-swipe-direction | a toast while a swipe moves it, and the direction it moves in (a value); a drawer's popup |
data-type | a toast's type, on its parts (a value: loading, success, error, or the app's own) |
data-priority | a toast viewport's live region: low (polite) or high (assertive) |
data-has-overflow-x, data-has-overflow-y | a scroll area whose content is wider (taller) than its viewport, on its root, viewport, content and scrollbars |
data-overflow-x-start, data-overflow-x-end, data-overflow-y-start, data-overflow-y-end | a scroll area scrolled away from that edge (the x edges logical: the start is the right edge in RTL) |
data-scrolling | a scroll area's parts while the user scrolls it (a scrollbar and its thumb: their own axis) |
data-hovering | a scroll area's scrollbars while a mouse or pen is over its root |
data-current | a pagination item of the current page (with aria-current="page"); a link or a breadcrumbs link to the current page; the current step's parts (with aria-current="step" on its item and trigger) and its content; a carousel indicator of the current page |
data-completed, data-incomplete | a step's parts before or after the current step (data-completed on every step, and on the steps root, once the process is completed) |
data-inview | a carousel slide on the current page (the others are inert) |
data-playing, data-paused | a carousel and its autoplay trigger while the slides rotate; a carousel while a hover pauses the rotation |
data-nested | a submenu's positioner and popup; a nested dialog's popup, backdrop and viewport (a dialog or alert dialog inside another's popup) |
data-nested-dialog-open | a dialog's popup, backdrop and viewport while a dialog nested in it is open |
data-side | the side a positioned overlay ended up on (a value: top, bottom, inline-start, inline-end, left, right, named as it was asked) |
data-align | start, center or end (a value) |
data-disabled | a disabled part |
data-orientation | horizontal or vertical (a value): tabs, an accordion, a slider, a radio group given an orientation, a separator, a toggle group, a toolbar and its parts, a menubar, a scroll area's scrollbar and thumb, a segmented control and its parts, the steps' parts, a carousel and its slides' container and indicator group, a color slider and its parts |
data-activation | automatic or manual on tabs (a value) |
data-activation-direction | where the newly selected tab sits from the previous one, on every tabs part (a physical value: left, right, up, down, none) |
data-today, data-outside-month, data-unavailable | a calendar cell of today, of another month's day, of a date the app marked unavailable |
data-range-start, data-range-end, data-in-range, data-range-preview | a range calendar's cells: the range's ends, its dates, the dates of a range being chosen |
data-readonly | a read-only calendar, a read-only switch and its thumb |
One CSS variable carries the depth of nested dialogs: a dialog's popup has the inline style
--nested-dialogs: <n>, the number of open dialogs nested below it as a chain (0 when none), to
scale or offset the parent (scale: calc(1 - 0.05 * var(--nested-dialogs))).
A scroll area writes what it measures: its viewport's --scroll-area-overflow-x-start, -x-end,
-y-start and -y-end (the distance to each edge, for a fade), its scrollbars'
--scroll-area-thumb-height / --scroll-area-thumb-width, and its root's
--scroll-area-corner-width / --scroll-area-corner-height.
A segmented control's indicator carries its checked item's box, from the root's padding box:
the logical --segment-indicator-inset-inline-start, -inset-block-start, -inline-size and
-block-size, and the physical --segment-indicator-left, -right, -top, -bottom, -width
and -height.
A toast carries its place in the stack: --toast-index, --toast-offset-y, --toast-height and
the swipe's --toast-swipe-movement-x / -y, with the viewport's --toast-frontmost-height.
ARIA carries the rest: aria-live (a toast viewport's live regions), aria-expanded, aria-selected, aria-checked, aria-pressed, aria-invalid,
aria-activedescendant, aria-modal, aria-controls, aria-current, aria-readonly, aria-valuenow,
aria-valuetext, aria-busy, and a virtual list's aria-setsize and aria-posinset.
An enter and exit transition
[data-primitives-part="dialog-popup"] {
transition: opacity 150ms, scale 150ms;
}
[data-primitives-part="dialog-popup"][data-starting-style],
[data-primitives-part="dialog-popup"][data-ending-style] {
opacity: 0;
scale: 0.95;
}The popup stays mounted while its exit transition runs, and unmounts when it ends (or, with the
Portal's keepMounted, is hidden with data-closed). onOpenChangeComplete(open) reports the end
of each transition.