Skip to content

Instantly share code, notes, and snippets.

@adrianorsouza
Last active November 13, 2019 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianorsouza/36be27060437fa8ef4ad8e1d4cbadeb7 to your computer and use it in GitHub Desktop.
Save adrianorsouza/36be27060437fa8ef4ad8e1d4cbadeb7 to your computer and use it in GitHub Desktop.
react checkbox indeterminate
// 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