Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Clarify warnings on "true" / "false" values in DOM boolean props
  • Loading branch information
motiz88 committed Aug 12, 2018
commit f70a0eb8016ac93c94e833b8ec79fdd94254025e
2 changes: 2 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,7 @@ describe('ReactDOMComponent', () => {
el = ReactTestUtils.renderIntoDocument(<div hidden="false" />);
}).toWarnDev(
'Received the string `false` for the boolean attribute `hidden`. ' +
'The browser will interpret it as a truthy value. ' +
'Did you mean hidden={false}?',
);

Expand All @@ -2525,6 +2526,7 @@ describe('ReactDOMComponent', () => {
el = ReactTestUtils.renderIntoDocument(<div hidden="true" />);
}).toWarnDev(
'Received the string `true` for the boolean attribute `hidden`. ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add Although this works, it will not work as expected if you pass the string "false". to the true case.

'Although this works, it will not work as expected if you pass the string "false". ' +
'Did you mean hidden={true}?',
);

Expand Down
4 changes: 4 additions & 0 deletions packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,13 @@ if (__DEV__) {
warning(
false,
'Received the string `%s` for the boolean attribute `%s`. ' +
'%s ' +
'Did you mean %s={%s}?',
value,
name,
value === 'false'
? 'The browser will interpret it as a truthy value.'
: 'Although this works, it will not work as expected if you pass the string "false".',
name,
value,
);
Expand Down