Skip to content

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

Mute and Favourite keep their names and set 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

Bold and Italic change their fill with a class and set no 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

Each card is a 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

The cards as plain buttons, with 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, DropdownMenuCheckboxItem and DropdownMenuRadioItem. Each exposes its state in code and as data-state for styling.
  • In a video call's toolbar, Mute is a Toggle with the fixed name "Mute", so a screen reader announces it as pressed when it is on. A Favourite star built from a Button gets aria-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-pressed together report the state twice.
  • On a checkout page, the delivery options Standard and Next day are cards. Build them as a RadioGroup with a RadioGroupItem and a Label in 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", put aria-selected on the chosen role="option" element. In a menu, a checkable item is menuitemcheckbox or menuitemradio with aria-checked.
  • In shadcn's Command, aria-selected marks 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 as aria-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, or aria-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-accent or data-[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 button with aria-expanded, and ARIA only when there is none.

Don't

  • Draw Bold as on with className={bold ? "bg-accent" : ""} on a plain Button and leave aria-pressed out.
  • Build the delivery cards as <Card onClick> with border-primary on 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-none while 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 put aria-selected on the li around 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, never aria-selected, on a link. The sort order of a column sits on its header cell as aria-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

Stances on VIS-008a
SourceRoleStancePage
WCAG 2.2LawRequires4.1.2 Name, Role, Value
WCAG 2.2LawSupports1.3.1 Info and Relationships
Material DesignJudge SupportsLists: accessibility
States: applying states
Apple Human Interface GuidelinesJudge No position
Carbon Design SystemJudge SupportsButton: accessibility
Disabled states
Tile: accessibility
GOV.UK Design SystemExpert witness No position
Nielsen Norman GroupExpert witness SupportsButton 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