VIS-008a Set every state a control shows in code on the control, and change it whenever the look changes
- Level
- Rule
- Verdict
- Requirement
- Status
- proposed, version 1.0.0
Rule
When a control shows a state, such as on or off, selected, checked, expanded or unavailable, that state is also set in code on the control itself. Whenever the look changes, the state in code changes with it.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Toggles that carry their state
aria-pressed, which flips with every press; the look (a fill, a slashed microphone, a filled star) is styled from it with aria-pressed:. Press them and read "State in code" change with the look.Don't: Drawn as on, silent in code
aria-pressed. Press one: it looks on, but a screen reader announces an ordinary button, and "State in code" stays empty.Do: Delivery cards that are checked in code
Delivery
RadioGroupItem with its text as the label, so the chosen card is aria-checked="true" and the others are not. Choose with a click or the arrow keys and watch the code follow.Don't: Delivery cards that only look chosen
Delivery
border-primary and a check on the chosen one. They work with a click and Tab, but the code carries no checked state, so a screen reader cannot tell which delivery is chosen.Why
A screen reader and speech control do not see a filled icon, a coloured border or a rotated chevron. They read the state the control carries in code. A Mute button drawn as on but silent in code is announced as an ordinary button, and the person cannot tell whether they are heard. A card drawn as chosen is announced as nothing at all. A state that is set once and never updated is worse: it tells the opposite of what the screen shows. WCAG 2.2, 4.1.2 Name, Role, Value requires that states the person can change can also be set by software, and that changes are passed on to assistive technology. Its explanation adds that states can be read by software, and names checked, selected and expanded among those states, and custom toggles and disclosures among the controls. 1.3.1 Info and Relationships supports it: what the look tells must also be in the code. The criterion does not say which element or attribute to use.
Do
- Use the components that set the state for you: shadcn's
Toggle,ToggleGroup,Checkbox,RadioGroup,Switch,Tabs,Accordion,Collapsible,Select,DropdownMenuCheckboxItemandDropdownMenuRadioItem. Each exposes its state in code and asdata-statefor styling. - In a video call's toolbar, Mute is a
Togglewith the fixed name "Mute", so a screen reader announces it as pressed when it is on. A Favourite star built from aButtongetsaria-pressed={isFavourite}and keeps its name. - Or let the name follow the state instead, as a Play button that becomes Pause. Use one way or the other, not both: a name that changes and
aria-pressedtogether report the state twice. - On a checkout page, the delivery options Standard and Next day are cards. Build them as a
RadioGroupwith aRadioGroupItemand aLabelin each card, so the chosen card is checked in code. Reaching them by keyboard is KBD-001. - In a list of options with
role="listbox", putaria-selectedon the chosenrole="option"element. In a menu, a checkable item ismenuitemcheckboxormenuitemradiowitharia-checked. - In shadcn's
Command,aria-selectedmarks the option under the cursor, not the chosen value. In a combobox with one choice, the trigger's text names the chosen value; if the open list also marks it with a check, give that option its own state, such asaria-checked, or hidden text. In a list where several values can be chosen, every chosen option needs that state. - The button Show filters carries
aria-expanded={open}, and the value changes every time the panel opens or closes. - A control that is off is off in code:
disabled, oraria-disabled="true"with a guard that ignores the press. When a control may be off at all is ACT-004, ACT-005 and STA-005b. - Our own advice: style the state from the attribute, as in
aria-pressed:bg-accentordata-[state=on]:bg-accent, so the look cannot drift from the code. - Our own advice: use a native element where one exists, such as a checkbox or a
buttonwitharia-expanded, and ARIA only when there is none.
Don't
- Draw Bold as on with
className={bold ? "bg-accent" : ""}on a plainButtonand leavearia-pressedout. - Build the delivery cards as
<Card onClick>withborder-primaryon the chosen one and no checked state. - Rotate the chevron on Show filters and never set
aria-expanded, or set it on first render and never update it. - Fade a button with
opacity-50 pointer-events-nonewhile it is still enabled in code, so Enter runs it and a screen reader calls it an ordinary button. - Put
aria-disabled="true"on a control that still looks usable and still does its job when pressed. - Hard-code
aria-pressed={true}, or putaria-selectedon theliaround a button instead of on the element with the role.
Exceptions
- Focus. Focus is a state too, but the browser sets it. Its visible look is KBD-001.
- The visible side. How a state looks is VIS-003a (more than colour), VIS-004 (3:1) and VIS-008b (a lasting state kept visible under hover, focus and press).
- Narrower rules come first. The current page in a menu is NAV-002a, which uses
aria-current, neveraria-selected, on a link. The sort order of a column sits on its header cell asaria-sort, not on the sort button, as TBL-002 says. - Neighbouring rules. A control's role is ACT-009, its name ACT-001b and FRM-010. That a choice control only records the choice is FRM-012b.
Verdict
Requirement. Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Requires | 4.1.2 Name, Role, Value |
| WCAG 2.2 | Law | Supports | 1.3.1 Info and Relationships |
| Material Design | Judge | Supports | Lists: accessibility States: applying states |
| Apple Human Interface Guidelines | Judge | No position | |
| Carbon Design System | Judge | Supports | Button: accessibility Disabled states Tile: accessibility |
| GOV.UK Design System | Expert witness | No position | |
| Nielsen Norman Group | Expert witness | Supports | Button States: Communicate Interaction, by Kelley Gordon |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Colour and motion: 11 rules and 0 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.