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
Copy file name to clipboardExpand all lines: README.md
+29-21Lines changed: 29 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ function App() {
27
27
}
28
28
```
29
29
30
-
To add some accessibility features to your scene you'll have to wrap objects you want to make focusable with the `A11y` component:
30
+
To add accessibility features to your scene you'll have to wrap components you want to make focusable with the `A11y` component:
31
31
32
32
```jsx
33
33
import { A11y } from'@react-three/a11y'
@@ -37,17 +37,16 @@ import { A11y } from '@react-three/a11y'
37
37
</A11y>
38
38
```
39
39
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.
40
+
`MyComponent` can now receive focus. More accurately, the emulated "focus" will handled at the `A11y`components which acts as a provider for children to access its state. But even if objects are focusable, nothing will be displayed or shown by default.
41
41
42
42
## Accessing the hover, focused & pressed state
43
43
44
-
For each child wrapped in a`A11y` component, you can access the `focus` / `hover`/`pressed` state like so:
44
+
For each child wrapped in the`A11y` component, you can access the `focus`, `hover`and`pressed` state like so:
45
45
46
46
```jsx
47
47
import { useA11y } from'@react-three/a11y'
48
48
49
49
functionBox(props) {
50
-
//useA11y gives us access to hover, focus and pressed states
51
50
consta11y=useA11y()
52
51
return (
53
52
<mesh {...props}>
@@ -58,14 +57,6 @@ function Box(props) {
58
57
}
59
58
```
60
59
61
-
## The role attribute
62
-
63
-
Like in HTML, you can focus different kind of elements and expect different things depending on what you're focusing:
The `focusCall` prop of `A11y` will be called each time this component receives focus (usually through tab navigation).
@@ -109,29 +100,46 @@ If your `A11y` component has the `role="button"`, you can use three more props:
109
100
description="This button can enable dark theme. Dark theme is off"
110
101
pressedDescription="This button can disable dark theme. Dark theme is on"
111
102
activationMsg="Dark theme enabled"
112
-
deactivationMsg="Dark theme disabled"
113
-
.../>
103
+
deactivationMsg="Dark theme disabled".../>
114
104
```
115
105
116
106
## The three roles of the `A11y` component
117
107
118
-
#### `content`
108
+
Like in HTML, you can focus different kind of elements and expect different things depending on what you're focusing.
109
+
110
+
#### Content
111
+
112
+
```jsx
113
+
<A11y role="content".../>
114
+
```
115
+
116
+
Uses the `default` cursor. This role is meant to provide information to screen readers or to serve as a step for a user to navigate your site using Tab for instance. It's not meant to trigger anything on click or to be activable with the Keyboard. Therefore it won't show a pointer cursor on hover.
119
117
120
-
Uses `cursor: default`.
118
+
#### Buttons
121
119
122
-
This role is meant to provide information to screen readers or to serve as a step for a user to navigate your site using Tab for instance. It's not meant to trigger anything on click or to be activable with the Keyboard. Therefore it won't show a pointer cursor on hover.
123
120
124
-
#### `button`
121
+
```jsx
122
+
<A11y
123
+
role="button"
124
+
activationMsg="Button activated"
125
+
deactivationMsg="Button deactivated"
126
+
pressedDescription="Button pressed".../>
127
+
```
125
128
126
-
Uses `cursor: pointer`. Special attributes: activationMsg, deactivationMsg, pressedDescription
129
+
Uses the `pointer` cursor. Special attributes: `activationMsg`, `deactivationMsg` and `pressedDescription`.
127
130
128
131
This role is meant to emulate the behaviour of a button or a togglable button. It will display a cursor pointer when your cursor is over the linked 3D object. It will call a function on click but also on any kind of action that would trigger a focused button (Enter, Double-Tap, ...). It is also actionnable by user using a screen reader.
129
132
130
133
You can turn it into a button with aria-pressed by providing the following properties deactivationMsg, pressedDescription in addition to the usual description and activationMsg properties.
131
134
132
-
#### `link`
135
+
#### Links
136
+
137
+
138
+
```jsx
139
+
<A11y role="link" href="https://url.com".../>
140
+
```
133
141
134
-
Uses `cursor: pointer`. Special attributes: href.
142
+
Uses this `pointer` cursor. Special attributes: `href`.
135
143
136
144
This role is meant to emulate the behaviour of a regular html link. It should be used in combination with something that will trigger navigation on click. Just like the button one, it is accessible to all kind of user.
0 commit comments