You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`@react-three/a11y` brings accessibility to WebGL, with easy to use components [react-three-fiber](https://github.com/pmndrs/react-three-fiber) components to enable focus indication, keyboard tab navigation, and screen reader support.
8
12
9
13
# How to use
10
14
11
-
## Initial setup
15
+
First, place the `A11yAnnouncer` component next to the R3F Canvas component. This is critical, because it will manage the screen-reader and help emulate focus!
12
16
13
-
Install the @react-three/a11y package
17
+
```jsx
18
+
import { A11yAnnouncer } from'@react-three/a11y'
14
19
15
-
```bash
16
-
npm install @react-three/a11y
20
+
functionApp() {
21
+
return (
22
+
<>
23
+
<Canvas />
24
+
<A11yAnnouncer />
25
+
</>
26
+
)
27
+
}
17
28
```
18
29
19
-
Now, you'll have to import the `A11yAnnouncer` component. We usually place it next to the R3F Canvas component.
30
+
To add some accessibility features to your scene you'll have to wrap objects you want to make focusable with the `A11y`component:
20
31
21
32
```jsx
22
-
import { A11yAnnouncer } from"@react-three/a11y"
23
-
{...}
24
-
<Canvas>
25
-
{...}
26
-
</Canvas>
27
-
<A11yAnnouncer />
28
-
```
33
+
import { A11y } from'@react-three/a11y'
29
34
30
-
This will both help us emulate focus inside the canvas and provide some text to screen readers when necessary.
31
-
32
-
To add some accessibility features to your 3D Objects/Groups you'll have to wrap the 3D objects you want to make focusable with the `A11y` component:
At this point both _My3DComponent_ and _AGroupOf3DComponent_ can receive focus.
52
-
More accurately, the emulated "focus" will be on the parent `A11y` that will act as a provider and let its children access the state.
53
-
But even if they're focusable, nothing will be displayed / read etc without a few more attributes.
40
+
At this point both `MyComponent` can receive focus. More accurately, the emulated "focus" will be on the parent `A11y` that will act as a provider and let its children access its state. But even if objects are focusable, nothing will be displayed or read without a few more attributes.
54
41
55
42
## Accessing the hover, focused & pressed state
56
43
57
44
For each child wrapped in a `A11y` component, you can access the `focus` / `hover` / `pressed` state like so:
<A11y role="content" description="A rotating red square">
144
-
//will read "A rotating red square" to screen readers on focus / hover
145
-
<My3DSquare />
146
-
</A11y>
147
-
{...}
148
-
<A11y role="content" description="A bouncing blue sphere" showAltText={true}>
149
-
//will read "A bouncing blue sphere" to screen readers on focus / hover while also showing it on mouseover
150
-
<My3DSphere />
151
-
</A11y>
152
-
{...}
153
-
</Canvas>
154
-
<A11yAnnouncer />
91
+
// Reads "A rotating red square" to screen readers on focus / hover
92
+
<A11y role="content" description="A rotating red square".../>
93
+
// Reads "A bouncing blue sphere" to screen readers on focus / hover while also showing it on mouseover
94
+
<A11y role="content" description="A bouncing blue sphere" showAltText .../>
155
95
```
156
96
157
97
If your `A11y` component has the `role="button"`, you can use three more props:
@@ -161,28 +101,16 @@ If your `A11y` component has the `role="button"`, you can use three more props:
161
101
-`pressedDescription`: When set, it turns your button in a togglable button. Which means it now has a on/off state. This description will replace the one passed via `description` when the toggle is active.
0 commit comments