Skip to content

Commit 7400476

Browse files
committed
Support "for", "class", "http-equiv", and "accept-charset"
This commit updates the HTML property config and UnknownPropertyHook developer warnings such that is no longer required to specify "className" instead of "class", "htmlFor" instead of "for", and so on. Both forms are supported. When both are specified within props, React provides the warning: "className and class were listed as properties on <div />. Both write to the same attribute; use one or the other."
1 parent 3b43f31 commit 7400476

File tree

5 files changed

+254
-66
lines changed

5 files changed

+254
-66
lines changed

scripts/fiber/tests-passing.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,6 @@ src/renderers/dom/shared/__tests__/ReactDOM-test.js
761761
* calls focus() on autoFocus elements after they have been mounted to the DOM
762762

763763
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
764-
* should handle className
765764
* should gracefully handle various style value types
766765
* should not update styles when mutating a proxy style object
767766
* should throw when mutating style objects
@@ -844,8 +843,6 @@ src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
844843
* should warn about incorrect casing on event handlers (ssr)
845844
* should warn about incorrect casing on properties
846845
* should warn about incorrect casing on event handlers
847-
* should warn about class
848-
* should warn about class (ssr)
849846
* should warn about props that are no longer supported
850847
* should warn about props that are no longer supported (ssr)
851848
* gives source code refs for unknown prop warning
@@ -855,6 +852,22 @@ src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
855852
* should suggest property name if available
856853
* renders innerHTML and preserves whitespace
857854
* render and then updates innerHTML and preserves whitespace
855+
* should correctly assign the class attribute
856+
* should correctly assign the className attribute
857+
* supports the class attribute with string rendering
858+
* removes className when set to null
859+
* removes class when set to null
860+
* switches from class to className
861+
* switches from className to class
862+
* warns when className and class are added to an element
863+
* should correctly assign the for attribute
864+
* should correctly assign the htmlFor attribute
865+
* supports the for attribute with string rendering
866+
* removes htmlFor when set to null
867+
* removes for when set to null
868+
* switches from for to htmlFor
869+
* switches from htmlFor to for
870+
* warns when htmlFor and for are added to an element
858871

859872
src/renderers/dom/shared/__tests__/ReactDOMComponentTree-test.js
860873
* finds nodes for instances

src/renderers/dom/shared/DOMProperty.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ var DOMPropertyInjection = {
118118
if (DOMAttributeNames.hasOwnProperty(propName)) {
119119
var attributeName = DOMAttributeNames[propName];
120120
propertyInfo.attributeName = attributeName;
121-
if (__DEV__) {
122-
DOMProperty.getPossibleStandardName[attributeName] = propName;
123-
}
124121
}
125122

126123
if (DOMAttributeNamespaces.hasOwnProperty(propName)) {

src/renderers/dom/shared/HTMLDOMPropertyConfig.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var HTMLDOMPropertyConfig = {
3131
*/
3232
accept: 0,
3333
acceptCharset: 0,
34+
'accept-charset': 0,
3435
accessKey: 0,
3536
action: 0,
3637
allowFullScreen: HAS_BOOLEAN_VALUE,
@@ -51,6 +52,7 @@ var HTMLDOMPropertyConfig = {
5152
checked: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
5253
cite: 0,
5354
classID: 0,
55+
class: 0,
5456
className: 0,
5557
cols: HAS_POSITIVE_NUMERIC_VALUE,
5658
colSpan: 0,
@@ -83,8 +85,10 @@ var HTMLDOMPropertyConfig = {
8385
high: 0,
8486
href: 0,
8587
hrefLang: 0,
88+
for: 0,
8689
htmlFor: 0,
8790
httpEquiv: 0,
91+
'http-equiv': 0,
8892
id: 0,
8993
inputMode: 0,
9094
integrity: 0,
@@ -212,7 +216,12 @@ var HTMLDOMPropertyConfig = {
212216
htmlFor: 'for',
213217
httpEquiv: 'http-equiv',
214218
},
215-
DOMPropertyNames: {},
219+
DOMPropertyNames: {
220+
'accept-charset': 'acceptCharset',
221+
class: 'className',
222+
for: 'htmlFor',
223+
'http-equiv': 'httpEquiv',
224+
},
216225
DOMMutationMethods: {
217226
value: function(node, value) {
218227
if (value == null) {

0 commit comments

Comments
 (0)