-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
propsToAccessibilityComponent.js
53 lines (47 loc) · 1.16 KB
/
propsToAccessibilityComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright (c) Nicolas Gallagher.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import propsToAriaRole from './propsToAriaRole';
const roleComponents = {
article: 'article',
banner: 'header',
blockquote: 'blockquote',
code: 'code',
complementary: 'aside',
contentinfo: 'footer',
deletion: 'del',
emphasis: 'em',
figure: 'figure',
insertion: 'ins',
form: 'form',
list: 'ul',
listitem: 'li',
main: 'main',
navigation: 'nav',
region: 'section',
strong: 'strong'
};
const emptyObject = {};
const propsToAccessibilityComponent = (props: Object = emptyObject): void | string => {
// special-case for "label" role which doesn't map to an ARIA role
if (props.accessibilityRole === 'label') {
return 'label';
}
const role = propsToAriaRole(props);
if (role) {
if (role === 'heading') {
const level = props.accessibilityLevel || props['aria-level'];
if (level != null) {
return `h${level}`;
}
return 'h1';
}
return roleComponents[role];
}
};
export default propsToAccessibilityComponent;