-
-
Notifications
You must be signed in to change notification settings - Fork 635
/
Copy pathinput.js
54 lines (50 loc) · 1.43 KB
/
input.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
54
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
/**
* Returns the implicit role for an input tag.
*
* @see https://www.w3.org/TR/html-aria/#el-input-text-list
* `input` with type = text, search, tel, url, email, or with a missing or invalid type
* with a list attribute will have an implicit role=combobox.
*/
export default function getImplicitRoleForInput(attributes) {
const type = getProp(attributes, 'type');
const hasListAttribute = !!getProp(attributes, 'list');
if (type) {
const value = getLiteralPropValue(type) || '';
switch (typeof value === 'string' && value.toUpperCase()) {
case 'COLOR':
case 'DATE':
case 'DATETIME-LOCAL':
case 'FILE':
case 'HIDDEN':
case 'MONTH':
case 'PASSWORD':
case 'TIME':
case 'WEEK':
/** No corresponding role */
return '';
case 'BUTTON':
case 'IMAGE':
case 'RESET':
case 'SUBMIT':
return 'button';
case 'CHECKBOX':
return 'checkbox';
case 'RADIO':
return 'radio';
case 'RANGE':
return 'slider';
case 'NUMBER':
return 'spinbutton';
case 'SEARCH':
return hasListAttribute ? 'combobox' : 'searchbox';
case 'EMAIL':
case 'TEL':
case 'TEXT':
case 'URL':
default:
return hasListAttribute ? 'combobox' : 'textbox';
}
}
return hasListAttribute ? 'combobox' : 'textbox';
}