UNPKG

11.7 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import {NativeSyntheticEvent} from '../../Types/CoreEventTypes';
11
12/**
13 * @see https://reactnative.dev/docs/accessibility#accessibility-properties
14 */
15export interface AccessibilityProps
16 extends AccessibilityPropsAndroid,
17 AccessibilityPropsIOS {
18 /**
19 * When true, indicates that the view is an accessibility element.
20 * By default, all the touchable elements are accessible.
21 */
22 accessible?: boolean | undefined;
23
24 /**
25 * Provides an array of custom actions available for accessibility.
26 */
27 accessibilityActions?: ReadonlyArray<AccessibilityActionInfo> | undefined;
28
29 /**
30 * Overrides the text that's read by the screen reader when the user interacts with the element. By default, the
31 * label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
32 */
33 accessibilityLabel?: string | undefined;
34
35 /**
36 * Alias for accessibilityLabel https://reactnative.dev/docs/view#accessibilitylabel
37 * https://github.com/facebook/react-native/issues/34424
38 */
39 'aria-label'?: string | undefined;
40
41 /**
42 * Accessibility Role tells a person using either VoiceOver on iOS or TalkBack on Android the type of element that is focused on.
43 */
44 accessibilityRole?: AccessibilityRole | undefined;
45 /**
46 * Accessibility State tells a person using either VoiceOver on iOS or TalkBack on Android the state of the element currently focused on.
47 */
48 accessibilityState?: AccessibilityState | undefined;
49
50 /**
51 * alias for accessibilityState
52 *
53 * see https://reactnative.dev/docs/accessibility#accessibilitystate
54 */
55 'aria-busy'?: boolean | undefined;
56 'aria-checked'?: boolean | 'mixed' | undefined;
57 'aria-disabled'?: boolean | undefined;
58 'aria-expanded'?: boolean | undefined;
59 'aria-selected'?: boolean | undefined;
60
61 /**
62 * An accessibility hint helps users understand what will happen when they perform an action on the accessibility element when that result is not obvious from the accessibility label.
63 */
64 accessibilityHint?: string | undefined;
65 /**
66 * Represents the current value of a component. It can be a textual description of a component's value, or for range-based components, such as sliders and progress bars,
67 * it contains range information (minimum, current, and maximum).
68 */
69 accessibilityValue?: AccessibilityValue | undefined;
70
71 'aria-valuemax'?: AccessibilityValue['max'] | undefined;
72 'aria-valuemin'?: AccessibilityValue['min'] | undefined;
73 'aria-valuenow'?: AccessibilityValue['now'] | undefined;
74 'aria-valuetext'?: AccessibilityValue['text'] | undefined;
75 /**
76 * When `accessible` is true, the system will try to invoke this function when the user performs an accessibility custom action.
77 */
78 onAccessibilityAction?:
79 | ((event: AccessibilityActionEvent) => void)
80 | undefined;
81
82 /**
83 * [Android] Controlling if a view fires accessibility events and if it is reported to accessibility services.
84 */
85 importantForAccessibility?:
86 | ('auto' | 'yes' | 'no' | 'no-hide-descendants')
87 | undefined;
88
89 /**
90 * A value indicating whether the accessibility elements contained within
91 * this accessibility element are hidden.
92 */
93 'aria-hidden'?: boolean | undefined;
94
95 'aria-modal'?: boolean | undefined;
96
97 /**
98 * Indicates to accessibility services to treat UI component like a specific role.
99 */
100 role?: Role | undefined;
101}
102
103export type AccessibilityActionInfo = Readonly<{
104 name: AccessibilityActionName | string;
105 label?: string | undefined;
106}>;
107
108export type AccessibilityActionName =
109 /**
110 * Generated when a screen reader user double taps the component.
111 */
112 | 'activate'
113 /**
114 * Generated when a screen reader user increments an adjustable component.
115 */
116 | 'increment'
117 /**
118 * Generated when a screen reader user decrements an adjustable component.
119 */
120 | 'decrement'
121 /**
122 * Generated when a TalkBack user places accessibility focus on the component and double taps and holds one finger on the screen.
123 * @platform android
124 */
125 | 'longpress'
126 /**
127 * Generated when a VoiceOver user places focus on or inside the component and double taps with two fingers.
128 * @platform ios
129 * */
130 | 'magicTap'
131 /**
132 * Generated when a VoiceOver user places focus on or inside the component and performs a two finger scrub gesture (left, right, left).
133 * @platform ios
134 * */
135 | 'escape';
136
137export type AccessibilityActionEvent = NativeSyntheticEvent<
138 Readonly<{
139 actionName: string;
140 }>
141>;
142
143export interface AccessibilityState {
144 /**
145 * When true, informs accessible tools if the element is disabled
146 */
147 disabled?: boolean | undefined;
148 /**
149 * When true, informs accessible tools if the element is selected
150 */
151 selected?: boolean | undefined;
152 /**
153 * For items like Checkboxes and Toggle switches, reports their state to accessible tools
154 */
155 checked?: boolean | 'mixed' | undefined;
156 /**
157 * When present, informs accessible tools if the element is busy
158 */
159 busy?: boolean | undefined;
160 /**
161 * When present, informs accessible tools the element is expanded or collapsed
162 */
163 expanded?: boolean | undefined;
164}
165
166export interface AccessibilityValue {
167 /**
168 * The minimum value of this component's range. (should be an integer)
169 */
170 min?: number | undefined;
171
172 /**
173 * The maximum value of this component's range. (should be an integer)
174 */
175 max?: number | undefined;
176
177 /**
178 * The current value of this component's range. (should be an integer)
179 */
180 now?: number | undefined;
181
182 /**
183 * A textual description of this component's value. (will override minimum, current, and maximum if set)
184 */
185 text?: string | undefined;
186}
187
188export type AccessibilityRole =
189 | 'none'
190 | 'button'
191 | 'togglebutton'
192 | 'link'
193 | 'search'
194 | 'image'
195 | 'keyboardkey'
196 | 'text'
197 | 'adjustable'
198 | 'imagebutton'
199 | 'header'
200 | 'summary'
201 | 'alert'
202 | 'checkbox'
203 | 'combobox'
204 | 'menu'
205 | 'menubar'
206 | 'menuitem'
207 | 'progressbar'
208 | 'radio'
209 | 'radiogroup'
210 | 'scrollbar'
211 | 'spinbutton'
212 | 'switch'
213 | 'tab'
214 | 'tabbar'
215 | 'tablist'
216 | 'timer'
217 | 'list'
218 | 'toolbar';
219
220export interface AccessibilityPropsAndroid {
221 /**
222 * Identifies the element that labels the element it is applied to. When the assistive technology focuses on the component with this props,
223 * the text is read aloud. The value should should match the nativeID of the related element.
224 *
225 * @platform android
226 */
227 accessibilityLabelledBy?: string | string[] | undefined;
228
229 /**
230 * Identifies the element that labels the element it is applied to. When the assistive technology focuses on the component with this props,
231 * the text is read aloud. The value should should match the nativeID of the related element.
232 *
233 * @platform android
234 */
235 'aria-labelledby'?: string | undefined;
236
237 /**
238 * Indicates to accessibility services whether the user should be notified
239 * when this view changes. Works for Android API >= 19 only.
240 *
241 * @platform android
242 *
243 * See https://reactnative.dev/docs/view#accessibilityliveregion
244 */
245 accessibilityLiveRegion?: 'none' | 'polite' | 'assertive' | undefined;
246
247 /**
248 * Indicates to accessibility services whether the user should be notified
249 * when this view changes. Works for Android API >= 19 only.
250 *
251 * @platform android
252 *
253 * See https://reactnative.dev/docs/view#accessibilityliveregion
254 */
255 'aria-live'?: ('polite' | 'assertive' | 'off') | undefined;
256
257 /**
258 * Controls how view is important for accessibility which is if it fires accessibility events
259 * and if it is reported to accessibility services that query the screen.
260 * Works for Android only. See http://developer.android.com/reference/android/R.attr.html#importantForAccessibility for references.
261 *
262 * Possible values:
263 * 'auto' - The system determines whether the view is important for accessibility - default (recommended).
264 * 'yes' - The view is important for accessibility.
265 * 'no' - The view is not important for accessibility.
266 * 'no-hide-descendants' - The view is not important for accessibility, nor are any of its descendant views.
267 *
268 * @platform android
269 */
270 importantForAccessibility?:
271 | 'auto'
272 | 'yes'
273 | 'no'
274 | 'no-hide-descendants'
275 | undefined;
276}
277
278export interface AccessibilityPropsIOS {
279 /**
280 * A Boolean value indicating whether the accessibility elements contained within this accessibility element
281 * are hidden to the screen reader.
282 * @platform ios
283 */
284 accessibilityElementsHidden?: boolean | undefined;
285
286 /**
287 * A Boolean value indicating whether VoiceOver should ignore the elements within views that are siblings of the receiver.
288 * @platform ios
289 */
290 accessibilityViewIsModal?: boolean | undefined;
291
292 /**
293 * When accessible is true, the system will invoke this function when the user performs the escape gesture (scrub with two fingers).
294 * @platform ios
295 */
296 onAccessibilityEscape?: (() => void) | undefined;
297
298 /**
299 * When `accessible` is true, the system will try to invoke this function when the user performs accessibility tap gesture.
300 * @platform ios
301 */
302 onAccessibilityTap?: (() => void) | undefined;
303
304 /**
305 * When accessible is true, the system will invoke this function when the user performs the magic tap gesture.
306 * @platform ios
307 */
308 onMagicTap?: (() => void) | undefined;
309
310 /**
311 * https://reactnative.dev/docs/accessibility#accessibilityignoresinvertcolorsios
312 * @platform ios
313 */
314 accessibilityIgnoresInvertColors?: boolean | undefined;
315
316 /**
317 * By using the accessibilityLanguage property, the screen reader will understand which language to use while reading the element's label, value and hint. The provided string value must follow the BCP 47 specification (https://www.rfc-editor.org/info/bcp47).
318 * https://reactnative.dev/docs/accessibility#accessibilitylanguage-ios
319 * @platform ios
320 */
321 accessibilityLanguage?: string | undefined;
322
323 /**
324 * A Boolean value that indicates whether or not to show the item in the large content viewer.
325 * Available on iOS 13.0+
326 * https://reactnative.dev/docs/accessibility#accessibilityshowslargecontentviewer
327 * @platform ios
328 */
329 accessibilityShowsLargeContentViewer?: boolean | undefined;
330
331 /**
332 * When `accessibilityShowsLargeContentViewer` is set, this string will be used as title for the large content viewer.
333 * https://reactnative.dev/docs/accessibility#accessibilitylargecontenttitle
334 * @platform ios
335 */
336 accessibilityLargeContentTitle?: string | undefined;
337}
338
339export type Role =
340 | 'alert'
341 | 'alertdialog'
342 | 'application'
343 | 'article'
344 | 'banner'
345 | 'button'
346 | 'cell'
347 | 'checkbox'
348 | 'columnheader'
349 | 'combobox'
350 | 'complementary'
351 | 'contentinfo'
352 | 'definition'
353 | 'dialog'
354 | 'directory'
355 | 'document'
356 | 'feed'
357 | 'figure'
358 | 'form'
359 | 'grid'
360 | 'group'
361 | 'heading'
362 | 'img'
363 | 'link'
364 | 'list'
365 | 'listitem'
366 | 'log'
367 | 'main'
368 | 'marquee'
369 | 'math'
370 | 'menu'
371 | 'menubar'
372 | 'menuitem'
373 | 'meter'
374 | 'navigation'
375 | 'none'
376 | 'note'
377 | 'option'
378 | 'presentation'
379 | 'progressbar'
380 | 'radio'
381 | 'radiogroup'
382 | 'region'
383 | 'row'
384 | 'rowgroup'
385 | 'rowheader'
386 | 'scrollbar'
387 | 'searchbox'
388 | 'separator'
389 | 'slider'
390 | 'spinbutton'
391 | 'status'
392 | 'summary'
393 | 'switch'
394 | 'tab'
395 | 'table'
396 | 'tablist'
397 | 'tabpanel'
398 | 'term'
399 | 'timer'
400 | 'toolbar'
401 | 'tooltip'
402 | 'tree'
403 | 'treegrid'
404 | 'treeitem';
405
\No newline at end of file