# Styling ## Component state Prefer the primitive's data attributes for state styling, such as `data-checked:` or `data-disabled:`. Use its CSS variables for exposed dynamic values, such as popup anchor width and available height. Do not mirror primitive state in React solely to style it. Field validity has three states: `data-valid`, `data-invalid`, or neither before validation. `not-data-invalid` includes the unvalidated state; it is not equivalent to `data-valid`. Preserve existing interaction variants when adding error styles so call-site overrides keep merging. Disabled surfaces take precedence over invalid and read-only appearance. Keep invalid state and error associations intact while limiting error colors to enabled controls. Read-only locks the value, not the control. It stays focusable, keeps its indicators and drops hover feedback without looking disabled. Its popup opens for browsing; choosing a value and the parts that only commit or clear one are unavailable. Expose it with `aria-readonly`, never `aria-disabled`. Where supported by the upstream part, `className(state)` and `style(state)` read that part's state. At call sites, before using a callback or React state to calculate styles, check whether data attributes or CSS variables already express the requirement. When direct state access is needed, add a short comment explaining why; for example, Tooltip and Popover can share `data-popup-open` on one trigger while the style needs only Popover's open state. This does not restrict conditional rendering of content. Composite content forwards these callbacks to its styled part: for example, `PopoverContent` receives Popup state, not Positioner state. Native DOM props and custom convenience APIs do not automatically support state callbacks. Use `render` for element composition, not merely to change styles. A callback on `PopoverTrigger` reads Popover state; one on a standalone `Button` reads Button state. Composition does not change which state a part owns. With `render={