-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Support "for", "class", "http-equiv", and "accept-charset" #10169
Conversation
Are we intending to discourage and eventually deprecate the old |
Yes, I think we want to transition to just |
@gaearon 👍 On another note, I'm curious, what's the plan with dropping the whitelist then? From what I understand this has been the plan all along in the minds of some, but this seems like definitively moving towards keeping the whitelist or otherwise there will be churn going back. |
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."
7400476
to
2795381
Compare
Ack. Lint fixed. |
@gaearon I can update the warning to recommend using the attribute name, but I think we should only recommend it when both are specified. What do you think? |
I agree. |
Could you elaborate on that? I’m not super familiar with this code. From my understanding additions to whitelist are temporary to calm down the warnings, but #7311 would make it possible to later remove them. Do I misunderstand this? |
@gaearon Since way back there has been a discussion towards doing away with |
@gaearon Perhaps I should've read the linked PR more first :) but yeah, if the intention is to follow the attribute naming convention it makes sense to do this. If the idea is to follow the property naming convention it doesn't make sense to do this IMHO. |
@syranide I'm in favor of following the attribute route, keeping the authoring as similar to static HTML as possible. All attributes that we require the property name for, we convert into the attribute name to write as an attribute anyway. For me, I would like the roadmap to be:
|
@gaearon have to shift gears, but I can update that warning later today. |
After some discussion in facebook#10169 (comment), we have elected to move forward with using attribute names as the standard way of defining React props on html fields. This commit updates the warning associated with instances where a property _and_ attribute name are given such that it recommends using the attribute.
expect(container.firstChild.className).toBe('cleric'); | ||
expectDev(console.error.calls.count()).toBe(1); | ||
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe( | ||
'Warning: class and className were listed as properties on a <div />. Use "class".\n in div (at **)', |
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.
@gaearon how's this sound? too direct?
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.
Also, I've just added quotes around class and className for consistency.
This being on the roadmap raises several questions for me:
|
That's a good question, I think it would make sense to adopt one strategy or the other. Having a mix of attribute and property names doesn't seem acceptable IMO. If we implement this change I think it follows that we would eventually implement the same change for all attributes.
At least with the current spec, JSX can't be 100% compatible with HTML due to other differences, like self-closing tags. But that doesn't mean we can't make it more compatible. |
Please add support for string styles -
This would be last thing which limits jsx from using html inside render function |
Some discussion on this: https://twitter.com/dan_abramov/status/890191815567175680 |
Oof. I have a lot of tweets to read. |
In the end we discussed against doing this, at least for now. I previously thought const {class, someOtherProp} = this.props; // breaks If we allowed both, it would put third party components in an awkward situation where they are expected to support both. It gets brittle and confusing. |
Noooo I guess it makes sense, but I looked forward to this. |
I wanted to do it, but it doesn’t make as much sense to me now. |
I realize this is like 6 years old but if anyone finds this in the future (probably from the same StackOverflow link) and happens to know better... could you tell me why they didn't do something like this? function createElement(tag, attributes, ...children) {
attributes.className = attributes['class'] =
attributes.className || attributes['class'];
// ...
} This seems to dispute @gaearon's claim
|
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
className
andclass
,htmlFor
andfor
, are supported. I do not want this to be a breaking change.When both are specified within props, React provides the warning:
This required updating some tests that were dependent using
className
vsclass
for developer warnings.This feature is implemented separately from #7311 but there should be no functional conflict.
Related issues: #5926, #4331