Skip to content

Commit 252d6e9

Browse files
authored
docs: update screenreader text example to keep screenreader focus indicator on screen
Updating the text screenreader story to keep the focus indicator of screenreaders on-screen.
1 parent e785cf3 commit 252d6e9

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/styleguide/src/lib/Typography/Text/Text.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Text has some special props with common use cases to make your life easier.
9595

9696
<Canvas of={TextStories.Screenreader} />
9797

98+
If you need the focus indicator of a screenreader to stay on the screen, you can wrap the screenreader `Text` inside a parent element, like `Box` and set its `aria-labeledby` attribute to that matches the `id` of the `Text`. Depending on your use case, you might need to also set `aria-hidden` on the `Text` in order for the screenreader to not read the same text twice. Inspect the example above to see how it works.
99+
98100
### Highlight
99101

100102
<Canvas of={TextStories.Highlight} />

packages/styleguide/src/lib/Typography/Text/Text.stories.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Column, LayoutGrid, Text } from '@codecademy/gamut';
1+
import { Box, Column, LayoutGrid, Text } from '@codecademy/gamut';
22
// eslint-disable-next-line gamut/import-paths
33
import {
44
typographyElementVariants,
@@ -131,11 +131,15 @@ export const Screenreader: Story = {
131131
</Text>
132132
</Column>
133133
<Column size={9}>
134-
<Text screenreader={variant}>
135-
{variant
136-
? 'Visible only to screenreaders'
137-
: 'When set to "false", this text is visible to non-screenreaders.'}
138-
</Text>
134+
{variant ? (
135+
<Box aria-labelledby="example-sr-text" role="note" width={4}>
136+
<Text aria-hidden id="example-sr-text" screenreader>
137+
Visible only to screenreaders
138+
</Text>
139+
</Box>
140+
) : (
141+
<Text>This text is visible to non-screenreaders.</Text>
142+
)}
139143
</Column>
140144
</Fragment>
141145
))}

0 commit comments

Comments
 (0)