The Screen Reader Only component should be used to visually hide content that is necessary to provide appropriate context to users who experience a page using assistive technology.
When wrapped with the Screen Reader Only component, content is visually hidden but still available to assistive technology. This can be useful when information or relationships between UI controls are only communicated visually. By being able to visually hide some content you are able to provide clarifying information to non-sighted users without adding redundancy to the visual design.
Examples
Providing visually hidden headings to sectioned content
All sectioning elements, such as Cards, should contain a heading to provide a clear document outline and form of navigation to assistive technology users. However, there may be times a heading is not required (or even redundant) in a particular UI for sighted users. By using the Screen Reader Only component you can provide a visually hidden heading to give additional context and heirarchy. In the example below, we've added "Flex" as a heading that is accessible to assistive technology, but hidden visually.
<Card>
<ScreenReaderOnlyas="div">
<Headingas="h2"variant="heading20">Flex</Heading>
</ScreenReaderOnly>
<Paragraph>
Deploy an omnichannel contact center within minutes and customize every element of the experience, including the agent desktop, channels, interaction routing, and reporting using common web frameworks like React.js and REST APIs.
</Paragraph>
<FlexvAlignContent="center">
<FlexmarginRight="space40">
<Buttonvariant="primary">
Launch Flex
</Button>
</Flex>
<Anchorhref="#">
View all projects
</Anchor>
</Flex>
</Card>
Providing clear actions while still reducing visual repetition
Each column in a table is required to have a column header. Sometimes those column headers can be visually hidden from sighted users if desired. To do so use the Screen Reader Only component to hide the cell content for that column header.
Another common use case is for providing correct context to repetitive actions. In the example below, the "Buy" button is clearly visually associated with the phone number via row highlighting. However, to a screen reader user, this association may not be as clear. To provide additional clarification we can add what you would be buying (Buy ) as visually hidden text to the button. This way, we can keep the same level of context for all users.
Use the Screen Reader Only component when you are required to provide additional or contextual information to a screen reader user which a sighted user maybe able to infer and when you cannot do so via semantic HTML.
Do
Use to provide additional text content to users of assistive technology
Don't
Don't use to hide interactive content
Usage Guide
API
Installation
yarnadd @twilio-paste/screen-reader-only - or - yarnadd @twilio-paste/core
73c596919#2269 Thanks @SiTaggart! - Fixed a regression with the compilation script that caused incompatible ESM module importing of JSON files.
7.0.1
Patch Changes
c867e3f48#2237 Thanks @SiTaggart! - Updated a build dependency (esbuild) which changes the output of our builds slightly, without materially changing anything about the code.
a12acb61#1158 Thanks @richbachman! - Pinned all twilio-paste package versions in order to keep them in sync with core when they are updated by changesets.