liveBook · Manning

Accessible name

As explained in React in Depth

An accessible name is the programmatically determined text label by which an interface element is identified to assistive technologies.

An accessible name is the programmatically determined text label that identifies an interface element to assistive technologies. It can remain correct even when the visual presentation changes, such as when a link contains an image with alt text. section 10.1

Use accessible names when testing elements according to how users interact with the interface:

  • Query an element by semantic role, such as link, button, heading, image, or listitem, rather than by tag name, class, or another implementation attribute. section 10.1
  • Pass the expected name to getByRole, for example getByRole("link", { name: "Blog" }). section 10.1
  • Recognize that names may come from text, nested nodes, images, SVGs, or other complex HTML; the underlying algorithm is more complicated than this summary. section 10.1

How React in Depth covers it

How deep it goes
Defines name sources and demonstrates queries, but defers the complete accessible-name algorithm.
Examples
Uses Blog links with text or image alt text and tests a MenuItem rendered with React Testing Library.
What it assumes
Assumes familiarity with HTML roles and component tests while briefly establishing how names derive from rendered content.
What you can do after
Apply it via React Testing Library to query elements by role and accessible name instead of presentation-specific selectors.
How it connects
Connects accessible names with semantic roles, assistive technologies, alternative text, and component testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.