UNPKG

6.47 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2013-present, Facebook, Inc.
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 */
8
9'use strict';
10
11var DOMProperty = require('./DOMProperty');
12
13var MUST_USE_PROPERTY = DOMProperty.injection.MUST_USE_PROPERTY;
14var HAS_BOOLEAN_VALUE = DOMProperty.injection.HAS_BOOLEAN_VALUE;
15var HAS_NUMERIC_VALUE = DOMProperty.injection.HAS_NUMERIC_VALUE;
16var HAS_POSITIVE_NUMERIC_VALUE = DOMProperty.injection.HAS_POSITIVE_NUMERIC_VALUE;
17var HAS_OVERLOADED_BOOLEAN_VALUE = DOMProperty.injection.HAS_OVERLOADED_BOOLEAN_VALUE;
18
19var HTMLDOMPropertyConfig = {
20 isCustomAttribute: RegExp.prototype.test.bind(new RegExp('^(data|aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$')),
21 Properties: {
22 /**
23 * Standard Properties
24 */
25 accept: 0,
26 acceptCharset: 0,
27 accessKey: 0,
28 action: 0,
29 allowFullScreen: HAS_BOOLEAN_VALUE,
30 allowTransparency: 0,
31 alt: 0,
32 // specifies target context for links with `preload` type
33 as: 0,
34 async: HAS_BOOLEAN_VALUE,
35 autoComplete: 0,
36 // autoFocus is polyfilled/normalized by AutoFocusUtils
37 // autoFocus: HAS_BOOLEAN_VALUE,
38 autoPlay: HAS_BOOLEAN_VALUE,
39 capture: HAS_BOOLEAN_VALUE,
40 cellPadding: 0,
41 cellSpacing: 0,
42 charSet: 0,
43 challenge: 0,
44 checked: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
45 cite: 0,
46 classID: 0,
47 className: 0,
48 cols: HAS_POSITIVE_NUMERIC_VALUE,
49 colSpan: 0,
50 content: 0,
51 contentEditable: 0,
52 contextMenu: 0,
53 controls: HAS_BOOLEAN_VALUE,
54 controlsList: 0,
55 coords: 0,
56 crossOrigin: 0,
57 data: 0, // For `<object />` acts as `src`.
58 dateTime: 0,
59 'default': HAS_BOOLEAN_VALUE,
60 defer: HAS_BOOLEAN_VALUE,
61 dir: 0,
62 disabled: HAS_BOOLEAN_VALUE,
63 download: HAS_OVERLOADED_BOOLEAN_VALUE,
64 draggable: 0,
65 encType: 0,
66 form: 0,
67 formAction: 0,
68 formEncType: 0,
69 formMethod: 0,
70 formNoValidate: HAS_BOOLEAN_VALUE,
71 formTarget: 0,
72 frameBorder: 0,
73 headers: 0,
74 height: 0,
75 hidden: HAS_BOOLEAN_VALUE,
76 high: 0,
77 href: 0,
78 hrefLang: 0,
79 htmlFor: 0,
80 httpEquiv: 0,
81 icon: 0,
82 id: 0,
83 inputMode: 0,
84 integrity: 0,
85 is: 0,
86 keyParams: 0,
87 keyType: 0,
88 kind: 0,
89 label: 0,
90 lang: 0,
91 list: 0,
92 loop: HAS_BOOLEAN_VALUE,
93 low: 0,
94 manifest: 0,
95 marginHeight: 0,
96 marginWidth: 0,
97 max: 0,
98 maxLength: 0,
99 media: 0,
100 mediaGroup: 0,
101 method: 0,
102 min: 0,
103 minLength: 0,
104 // Caution; `option.selected` is not updated if `select.multiple` is
105 // disabled with `removeAttribute`.
106 multiple: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
107 muted: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
108 name: 0,
109 nonce: 0,
110 noValidate: HAS_BOOLEAN_VALUE,
111 open: HAS_BOOLEAN_VALUE,
112 optimum: 0,
113 pattern: 0,
114 placeholder: 0,
115 playsInline: HAS_BOOLEAN_VALUE,
116 poster: 0,
117 preload: 0,
118 profile: 0,
119 radioGroup: 0,
120 readOnly: HAS_BOOLEAN_VALUE,
121 referrerPolicy: 0,
122 rel: 0,
123 required: HAS_BOOLEAN_VALUE,
124 reversed: HAS_BOOLEAN_VALUE,
125 role: 0,
126 rows: HAS_POSITIVE_NUMERIC_VALUE,
127 rowSpan: HAS_NUMERIC_VALUE,
128 sandbox: 0,
129 scope: 0,
130 scoped: HAS_BOOLEAN_VALUE,
131 scrolling: 0,
132 seamless: HAS_BOOLEAN_VALUE,
133 selected: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
134 shape: 0,
135 size: HAS_POSITIVE_NUMERIC_VALUE,
136 sizes: 0,
137 span: HAS_POSITIVE_NUMERIC_VALUE,
138 spellCheck: 0,
139 src: 0,
140 srcDoc: 0,
141 srcLang: 0,
142 srcSet: 0,
143 start: HAS_NUMERIC_VALUE,
144 step: 0,
145 style: 0,
146 summary: 0,
147 tabIndex: 0,
148 target: 0,
149 title: 0,
150 // Setting .type throws on non-<input> tags
151 type: 0,
152 useMap: 0,
153 value: 0,
154 width: 0,
155 wmode: 0,
156 wrap: 0,
157
158 /**
159 * RDFa Properties
160 */
161 about: 0,
162 datatype: 0,
163 inlist: 0,
164 prefix: 0,
165 // property is also supported for OpenGraph in meta tags.
166 property: 0,
167 resource: 0,
168 'typeof': 0,
169 vocab: 0,
170
171 /**
172 * Non-standard Properties
173 */
174 // autoCapitalize and autoCorrect are supported in Mobile Safari for
175 // keyboard hints.
176 autoCapitalize: 0,
177 autoCorrect: 0,
178 // autoSave allows WebKit/Blink to persist values of input fields on page reloads
179 autoSave: 0,
180 // color is for Safari mask-icon link
181 color: 0,
182 // itemProp, itemScope, itemType are for
183 // Microdata support. See http://schema.org/docs/gs.html
184 itemProp: 0,
185 itemScope: HAS_BOOLEAN_VALUE,
186 itemType: 0,
187 // itemID and itemRef are for Microdata support as well but
188 // only specified in the WHATWG spec document. See
189 // https://html.spec.whatwg.org/multipage/microdata.html#microdata-dom-api
190 itemID: 0,
191 itemRef: 0,
192 // results show looking glass icon and recent searches on input
193 // search fields in WebKit/Blink
194 results: 0,
195 // IE-only attribute that specifies security restrictions on an iframe
196 // as an alternative to the sandbox attribute on IE<10
197 security: 0,
198 // IE-only attribute that controls focus behavior
199 unselectable: 0
200 },
201 DOMAttributeNames: {
202 acceptCharset: 'accept-charset',
203 className: 'class',
204 htmlFor: 'for',
205 httpEquiv: 'http-equiv'
206 },
207 DOMPropertyNames: {},
208 DOMMutationMethods: {
209 value: function (node, value) {
210 if (value == null) {
211 return node.removeAttribute('value');
212 }
213
214 // Number inputs get special treatment due to some edge cases in
215 // Chrome. Let everything else assign the value attribute as normal.
216 // https://github.com/facebook/react/issues/7253#issuecomment-236074326
217 if (node.type !== 'number' || node.hasAttribute('value') === false) {
218 node.setAttribute('value', '' + value);
219 } else if (node.validity && !node.validity.badInput && node.ownerDocument.activeElement !== node) {
220 // Don't assign an attribute if validation reports bad
221 // input. Chrome will clear the value. Additionally, don't
222 // operate on inputs that have focus, otherwise Chrome might
223 // strip off trailing decimal places and cause the user's
224 // cursor position to jump to the beginning of the input.
225 //
226 // In ReactDOMInput, we have an onBlur event that will trigger
227 // this function again when focus is lost.
228 node.setAttribute('value', '' + value);
229 }
230 }
231 }
232};
233
234module.exports = HTMLDOMPropertyConfig;
\No newline at end of file