1 | import * as ts from 'typescript';
|
2 | import { getJsxAttributesFromJsxElement, getStringLiteral } from '../JsxAttribute';
|
3 |
|
4 | const typeString: string = 'type';
|
5 | const listString: string = 'list';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function getImplicitRoleForInput(node: ts.Node): string {
|
11 | const attributes: { [propName: string]: ts.JsxAttribute } = getJsxAttributesFromJsxElement(node);
|
12 | const typeAttribute: ts.JsxAttribute = attributes[typeString];
|
13 |
|
14 | if (typeAttribute) {
|
15 | const value: string = getStringLiteral(typeAttribute) || '';
|
16 |
|
17 |
|
18 | switch (value.toUpperCase()) {
|
19 | case 'BUTTON':
|
20 | case 'IMAGE':
|
21 | case 'RESET':
|
22 | case 'SUBMIT':
|
23 | return 'button';
|
24 | case 'CHECKBOX':
|
25 | return 'checkbox';
|
26 | case 'NUMBER':
|
27 | return 'spinbutton';
|
28 | case 'PASSWORD':
|
29 | return 'textbox';
|
30 | case 'RADIO':
|
31 | return 'radio';
|
32 | case 'RANGE':
|
33 | return 'slider';
|
34 | case 'SEARCH':
|
35 | return attributes[listString] ? 'combobox' : 'searchbox';
|
36 | case 'EMAIL':
|
37 | case 'TEL':
|
38 | case 'URL':
|
39 | case 'TEXT':
|
40 | return attributes[listString] ? 'combobox' : 'textbox';
|
41 | case 'COLOR':
|
42 | case 'DATE':
|
43 | case 'DATETIME':
|
44 | case 'FILE':
|
45 | case 'HIDDEN':
|
46 | case 'MONTH':
|
47 | case 'TIME':
|
48 | case 'WEEK':
|
49 | return undefined;
|
50 | default:
|
51 | return 'textbox';
|
52 | }
|
53 | }
|
54 |
|
55 |
|
56 | return 'textbox';
|
57 | }
|
58 |
|
59 | export { getImplicitRoleForInput as input };
|