UNPKG

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