2

If HTML5 specifies that there is no value for the "checked" attribute that is reliably interpreted as the checkbox being unchecked*, is the behavior of the following JSX code potentially inconsistent between browsers? (It seems to work as expected for me in Chrome and IE.)

<input type="checkbox" checked={node.props.checked} />

If so, what is the standard way to accomplish this, considering that the following JSX is invalid?

<input type="checkbox" {node.props.checked? "checked" : ""} />

What values for checked and selected are false?

1 Answer 1

3

You will need to conditionally add the entire checked attribute, not just the value of the attribute. That way, if you don't add the attribute at all, you will reliably get an unchecked checkbox.

If you are using ReactJS, then according to this answer:

React is intelligent enough to omit the attribute if the value you pass to it is not truthy.

1
  • 1
    accepted and upvoted, although my upvote is not visible since I have <15 rep. Thank you. Commented Dec 9, 2017 at 0:55

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.