-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from bamlab/feat/accessibility
Feat: add rudimentary accessibility support
- Loading branch information
Showing
13 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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,17 @@ | ||
# Accessibility | ||
|
||
For now, accessibility support is experimental with the library. | ||
Here's a video of what we could achieve. | ||
|
||
![talkback](./talkback.gif) | ||
|
||
Since we bypass the native focus, and the screen readers rely on the native elements, it's | ||
a difficult topic. | ||
|
||
We export a hook that returns you props that you can provide to your focusable elements. | ||
The main caveat is that your elements will still be focusable, but the user will need to press | ||
enter to grab focus on an element, which is not standard at all. | ||
|
||
We could not find a way to properly intercept the accessibility focus event, even with a React Native patch. | ||
|
||
Help is welcome 🙂 |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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 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 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 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
22 changes: 22 additions & 0 deletions
22
packages/lib/src/spatial-navigation/hooks/useSpatialNavigatorFocusableAccessibilityProps.ts
This file contains 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,22 @@ | ||
import { useParentId } from '../context/ParentIdContext'; | ||
import { useSpatialNavigator } from '../context/SpatialNavigatorContext'; | ||
|
||
export const useSpatialNavigatorFocusableAccessibilityProps = () => { | ||
const spatialNavigator = useSpatialNavigator(); | ||
const id = useParentId(); | ||
|
||
return { | ||
accessible: true, | ||
accessibilityRole: 'button' as const, | ||
accessibilityActions: [{ name: 'activate' }] as const, | ||
onAccessibilityAction: () => { | ||
const currentNode = spatialNavigator.getCurrentFocusNode(); | ||
|
||
if (currentNode?.id === id) { | ||
spatialNavigator.getCurrentFocusNode()?.onSelect?.(currentNode); | ||
} else { | ||
spatialNavigator.grabFocus(id); | ||
} | ||
}, | ||
}; | ||
}; |