Document how React treats different attributes #80
Comments
|
It looks like this blog post: https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html addresses a lot of the concerns in this particular issue. Do we want to create a new docs page that summarizes what the blog post talks about and reference the blog post? |
|
Perhaps, or perhaps we could add to this page: https://reactjs.org/docs/dom-elements.html To be honest, I moved this issue from the old repo over the weekend along with a lot of others. I didn't read too deeply into it. Would you be interested in working on this @mrscobbler ? |
|
Sure! I can work on it. I think adding to the existing page would be great. |
|
This issue is all yours! I've added an "in-progress" label so that others will know not to start work on the issue. If you change your mind about the issue, no worries! Just let me know so that I can remove the label and free it up for someone else to claim. Cheers! |
|
Hey @mrscobbler! Just wanting to confirm that this issue is still being worked on. No hurry of course. I'm just going through in-progress issues to see if any have been dropped. |
|
Yes! Still planning on working on it. I'll make sure to comment on this if for some reason I can't get to it. |
|
Great! Thanks! |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

This issue was originally reported by @MMeent via facebook/react/issues/9220
Please refer to the original issue for the related discussion thread.
Text of original issue:
As of #9106 there are quite a lot of tests for HTML's boolean properties on tags. According to these tests HTML properties should get rendered into empty strings or not set, e.g.
<div hidden={true} />should render to<div hidden="" />and<div hidden={false} />should render to<div />.But when I look further, there are other tests which do similar things:
<a href={true} />should render to<a href="true" />. This means that if I taketrueas my property value, I will not know what the result will be.The issue being: React currently does not have a clearly-defined and documented way with which they handle their props. Could the docs be updated to specify which type of prop will result in what? e.g. "any number gets parsed to a string (using Number.toString()), an object gets stringified by using
arg => Object.entries(arg).map(([key, val]) =>${key}: ${val};).join(), and booleans toggle the property."In short, these are the bugs/undocumented features/contradictions that the tests expect to happen, plus my expectations:
prop={true}gets parsed toprop=""orprop="true"for select propertiesexpected: either
prop=""orprop="prop", not both // as per checked=checked HTML standardprop=""gets parsed asprop=""orexpected:
prop=""prop="prop"might get parsed as eitherprop="prop",prop=""or evenexpected:
prop="prop"prop="foo"=>prop=""orprop="foo"expected:
prop="foo"prop={false}=>orprop="false"expected:
prop={['foo', 'bar']}=>prop=""orprop="foo,bar"(hand-tested, no automatic test available)expected:
prop="foo bar"prop={{foo: 'bar', baz: 5}}=>prop=""orprop="foo: bar; baz: 5;"orprop="[object Object]"(hand-tested, no automatic test available)expected:
prop="foo: bar; baz: 5"// as per style object transformHacky showcase: https://jsfiddle.net/ox8a7vfe/3/
Are these features or are these bugs?
If they are bugs, and work is going to be done on the props value parsing, then the following might be a nice addition:
prop={{foo: true, bar: true, baz: false}}=>prop="foo bar"// render alltruekeys, disregardfalsekeys, like classNames.The text was updated successfully, but these errors were encountered: