Below is a screenshot from Gmail. The first checkbox is in the indeterminate state because only some of the emails have been checked.
The indeterminate state can't be set via an HTML attribute. Instead, we have to set it through JavaScript:
checkboxElement.indeterminate = true;
In a feature I was recently building, I decided to use a modifier to bind the indeterminate state of a checkbox to some tracked state, as modifiers are the basic primitive for interacting with the DOM.
I named the modifier indeterminate
and its usage is as follows:
<input
type="checkbox"
checked=
/>
To generate the modifier, I ran the following in Terminal:
ember g modifier indeterminate
And here is the implemenation:
app/modifiers/indeterminate.js
import { modifier } from "ember-modifier";
export default modifier(function indeterminate(checkboxElement, [value]) {
checkboxElement.indeterminate = value;
});