-
Notifications
You must be signed in to change notification settings - Fork 326
/
filter-input-attributes.ts
92 lines (86 loc) · 1.71 KB
/
filter-input-attributes.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Attributes allowed on input elements
*/
const allowedAttributes: string[] = [
'autoCapitalize',
'autoComplete',
'autoCorrect',
'autoFocus',
'disabled',
'form',
'formAction',
'formEncType',
'formMethod',
'formNoValidate',
'formTarget',
'height',
'inputMode',
'maxLength',
'name',
'onClick',
'onContextMenu',
'onCopy',
'onCut',
'onDoubleClick',
'onMouseDown',
'onMouseEnter',
'onMouseLeave',
'onMouseMove',
'onMouseOut',
'onMouseOver',
'onMouseUp',
'onPaste',
'pattern',
'placeholder',
'readOnly',
'required',
'size',
'spellCheck',
'tabIndex',
'title',
'aria-atomic',
'aria-busy',
'aria-controls',
'aria-current',
'aria-describedby',
'aria-details',
'aria-disabled',
'aria-dropeffect',
'aria-errormessage',
'aria-flowto',
'aria-grabbed',
'aria-haspopup',
'aria-hidden',
'aria-invalid',
'aria-keyshortcuts',
'aria-label',
'aria-labelledby',
'aria-live',
'aria-owns',
'aria-relevant',
'aria-roledescription',
'aria-activedescendant',
'aria-autocomplete',
'aria-multiline',
'aria-placeholder',
'aria-readonly',
'aria-required'
];
/* eslint-disable @typescript-eslint/no-explicit-any */
interface Props {
[key: string]: any;
}
/**
* Filter the properties for only allowed input properties
*/
export default function (props: Props): {[key: string]: any} {
const attributes: {[key: string]: any} = {};
Object.keys(props).forEach((attribute) => {
const isDataAttribute = attribute.startsWith('data-');
const isAllowedAttribute = allowedAttributes.includes(attribute);
if (isAllowedAttribute || isDataAttribute) {
attributes[attribute] = props[attribute];
}
});
return attributes;
}