-
-
Notifications
You must be signed in to change notification settings - Fork 796
Feat: Add Screen Reader and ARIA support #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7ba870a
Introduce pagintion component
chrstnb 84ce367
Add screen reader mode
chrstnb 42b13ed
Remove unused
chrstnb 5e71b44
Remove accidental update
chrstnb f6336fa
Revert "Introduce pagintion component"
chrstnb 01e1dab
Fix formatting
chrstnb 98646f2
Updates to screen reader mode
chrstnb 7f5c519
Update readme format
chrstnb e318296
Update table component handling
chrstnb 827314d
Ensure accessibilityRoles are rendered properly
chrstnb 824a2b2
Revert borders example
chrstnb c6d490a
Add'l cleanup
chrstnb f42a17a
Remove async issue
chrstnb 92fd698
Make some changes
chrstnb 4d1831d
Updates to aria labels
chrstnb b300c3e
Merge remote-tracking branch 'upstream/master' into aria-labels
chrstnb fc36057
Revert unnecessary changes
chrstnb 3d8d689
Additional updates
chrstnb d019f84
Add test to screen reader mode
chrstnb 254c505
Address comments
chrstnb 441497a
Fix linter error
chrstnb a7e1f7f
Address comments
chrstnb 13818bb
Update readme.md
sindresorhus 800f5a0
Update readme.md
sindresorhus aae26b9
Address comments and add some gemini-generated changes
chrstnb 5e8e5f8
merge
chrstnb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React, {useState} from 'react'; | ||
| import {render, Text, Box, useInput} from 'ink'; | ||
|
|
||
| function AriaExample() { | ||
| const [checked, setChecked] = useState(false); | ||
|
|
||
| useInput(key => { | ||
| if (key === ' ') { | ||
| setChecked(!checked); | ||
| } | ||
| }); | ||
|
|
||
| return ( | ||
| <Box flexDirection="column"> | ||
| <Text> | ||
| Press spacebar to toggle the checkbox. This example is best experienced | ||
| with a screen reader. | ||
| </Text> | ||
| <Box marginTop={1}> | ||
| <Box aria-role="checkbox" aria-state={{checked}}> | ||
| <Text>{checked ? '[x]' : '[ ]'}</Text> | ||
| </Box> | ||
| </Box> | ||
| <Box marginTop={1}> | ||
| <Text aria-hidden="true">This text is hidden from screen readers.</Text> | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| render(<AriaExample />); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './aria.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './select-input.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import React, {useState} from 'react'; | ||
| import {render, Text, Box, useInput, useIsScreenReaderEnabled} from 'ink'; | ||
|
|
||
| const items = ['Red', 'Green', 'Blue', 'Yellow', 'Magenta', 'Cyan']; | ||
|
|
||
| function SelectInput() { | ||
| const [selectedIndex, setSelectedIndex] = useState(0); | ||
| const isScreenReaderEnabled = useIsScreenReaderEnabled(); | ||
|
|
||
| useInput((input, key) => { | ||
| if (key.upArrow) { | ||
| setSelectedIndex(previousIndex => | ||
| previousIndex === 0 ? items.length - 1 : previousIndex - 1, | ||
| ); | ||
| } | ||
|
|
||
| if (key.downArrow) { | ||
| setSelectedIndex(previousIndex => | ||
| previousIndex === items.length - 1 ? 0 : previousIndex + 1, | ||
| ); | ||
| } | ||
|
|
||
| if (isScreenReaderEnabled) { | ||
| const number = Number.parseInt(input, 10); | ||
| if (!Number.isNaN(number) && number > 0 && number <= items.length) { | ||
| setSelectedIndex(number - 1); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return ( | ||
| <Box flexDirection="column" aria-role="list"> | ||
| <Text>Select a color:</Text> | ||
| {items.map((item, index) => { | ||
| const isSelected = index === selectedIndex; | ||
| const label = isSelected ? `> ${item}` : ` ${item}`; | ||
| const screenReaderLabel = `${index + 1}. ${item}`; | ||
|
|
||
| return ( | ||
| <Box | ||
| key={item} | ||
| aria-role="listitem" | ||
| aria-state={{selected: isSelected}} | ||
| aria-label={isScreenReaderEnabled ? screenReaderLabel : undefined} | ||
| > | ||
| <Text color={isSelected ? 'blue' : undefined}>{label}</Text> | ||
| </Box> | ||
| ); | ||
| })} | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| render(<SelectInput />); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import {createContext} from 'react'; | ||
|
|
||
| export const accessibilityContext = createContext({ | ||
| isScreenReaderEnabled: false, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.