-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 'class' and 'for' for DOM property names #1223
Conversation
React fixes inconsistencies in the DOM and avoids being held back by older browsers (to the extent possible). The only reason that the DOM authors chose `className` and `htmlFor` was because the JS engines of the time didn't support using `class` and `for` as unquoted property names. Changing React to use `class` and `for` agrees with our principles of improving the DOM and using modern JS, and is what most people expect when first starting with React.
@@ -162,7 +162,7 @@ var DOMPropertyOperations = { | |||
var propName = DOMProperty.getPropertyName[name]; | |||
var defaultValue = DOMProperty.getDefaultValueForProperty( | |||
node.nodeName, | |||
name | |||
propName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(A bug that no one noticed before.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix this independently? Also a new test? I'm not convinced yet that we'll take the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose so. #1225
That sure is a valid argument |
This would make facebook#1223 easier to deal with in older browsers. With this change, <div class="orange" /> compiles into React.DOM.div( {"class":"orange"} ); and `this.props.class` turns into `this.props["class"]`.
+1 |
Don't the reserved words ( |
Oh sweet. Good stuff. |
Finding a way to make HTML attribute names work would definitely make React with JSX more approachable for new developers. But it has to be consistent - non-camelCased attribute names need to work as would attribute names with hyphens. |
Unfortunately this won't work with object destructuring, like var {class, color} = this.props; |
React fixes inconsistencies in the DOM and avoids being held back by older browsers (to the extent possible). The only reason that the DOM authors chose
className
andhtmlFor
was because the JS engines of the time didn't support usingclass
andfor
as unquoted property names.Changing React to use
class
andfor
agrees with our principles of improving the DOM and using modern JS, and is what most people expect when first starting with React.