Last active
November 13, 2019 23:29
-
-
Save adrianorsouza/36be27060437fa8ef4ad8e1d4cbadeb7 to your computer and use it in GitHub Desktop.
react checkbox indeterminate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://davidwalsh.name/react-indeterminate | |
// To add the indeterminate property to the checkbox, I needed to take advantage of the ref attribute: | |
const { value, checked, indeterminate } = this.props | |
return render( | |
<input | |
type="checkbox" | |
value={value} | |
checked={checked} | |
ref={el => el && (el.indeterminate = indeterminate)} | |
/> | |
) | |
// https://stackoverflow.com/a/52859693/2845262 | |
ReactDOM.render( | |
<label> | |
<input | |
type="checkbox" | |
ref={input => { | |
if (input) { | |
input.indeterminate = true; | |
} | |
}} | |
/> | |
{' '} | |
Un test | |
</label>, | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment