Accessibility
Learn how to make the most of the primitives' accessibility features and guidelines.
The primitives handle many of the complex details of accessibility: roles and ARIA attributes, pointer interactions, keyboard navigation and focus management. They aim for an accessible experience out of the box, with parameters to configure it. This page covers what they do, and what's still up to you.
Keyboard navigation
Each primitive follows its WAI-ARIA Authoring Practices pattern and its keyboard behaviour. That matters most to people who can't use a pointer, and to everyone who prefers the keyboard. Many primitives use the arrow keys, letters for typeahead, Home, End, Enter and Esc.
Focus management
The primitives move focus for you after an interaction: into a popup when it opens, around a group with the arrow
keys, and back to the trigger when the popup closes. Popups take InitialFocus and
FinalFocus parameters to choose where focus goes instead.
Focus also follows what Blazor renders. If Blazor removes the focused item, focus moves to the item now in its place rather than to the page, and closing or disabling a part from code returns focus to its trigger.
It's up to you to show where focus is, usually by styling :focus-visible, and the highlighted item of
a menu or list (data-highlighted). For WCAG AA, the indicator needs a contrast of at least 3:1 with what
it sits on (non-text contrast), as do
the borders that show where a control is and the marks that show its state, such as a checked box or a pressed
toggle. WCAG also has guidelines on focus
appearance. An outline stays visible in Windows' high contrast mode (forced colors), where box shadows and
backgrounds can disappear.
Color contrast
When you style the parts, meet the minimum contrast between each foreground and its background. Unless your app has strict requirements to comply with current standards, consider APCA.
Accessible labels
Form, Field,
Fieldset and Input associate labels,
descriptions and errors with their controls for you, and a native <label> works as well.
A plain <label> works too, wherever it can't reach the element that takes focus by itself:
- Checkbox, Switch and
Radio render a
<span>, which no label can name. A<label for>at theidyou give the control, or a<label>around it, names it througharia-labelledby, set once the page is interactive. -
A Slider's thumbs take a
<label for>at the root'sid, or anaria-labeloraria-labelledbyon the root. Name the thumbs of a range one by one witharia-labelon eachSliderThumb. - The list of options of a Select or Combobox is named after the label of its trigger or input.
An aria-label or aria-labelledby you pass always wins over the one a part would set.
Most apps also have controls whose accessible name has to come from markup, such as alt,
aria-label or aria-labelledby: a button with only an icon, or a select with no visible
label. A trigger with role="combobox" isn't named by its text, which is its value. WAI-ARIA has
guidelines on providing accessible names to
custom controls.
Dragging
Anything that changes by dragging needs a way to do the same with a single click or tap (WCAG 2.5.7). A slider's track and a scroll area's track jump where you press them, a carousel has previous and next buttons, and a drawer closes from its close button, its backdrop or Esc. Where you build something else that drags, add the alternative yourself.
Server rendering
Every role and ARIA state is rendered by Blazor, not added later by JavaScript, so it's in the HTML from the first render, prerendered or not. The JavaScript only does what has to happen inside a browser event, such as moving focus and positioning popups, and reports back to Blazor, which keeps the state.