Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(checkbox): Add --disabled modifier to checkbox root element to pr…
Browse files Browse the repository at this point in the history
…event hover state (#533)
  • Loading branch information
amsheehan authored Apr 26, 2017
1 parent be85871 commit eb51e32
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
24 changes: 24 additions & 0 deletions demos/checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ <h2>CSS Only</h2>
<button type="button" onclick="document.querySelector('.mdc-form-field').classList.toggle('mdc-form-field--align-end');">Toggle Align End</button>
<button type="button" onclick="document.getElementById('basic-checkbox').disabled = !document.getElementById('basic-checkbox').disabled;">Toggle Disabled</button>
</section>

<section>
<h2>CSS Only - Disabled</h2>
<div class="mdc-form-field">
<div class="mdc-checkbox mdc-checkbox--disabled">
<input type="checkbox"
id="basic-disabled-checkbox"
class="mdc-checkbox__native-control"
disabled />
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
viewBox="0 0 24 24">
<path class="mdc-checkbox__checkmark__path"
fill="none"
stroke="white"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
</div>
<label for="basic-disabled-checkbox" id="basic-disabled-checkbox-label">This is my disabled checkbox</label>
</div>
</section>

<section>
<h2>With Javascript</h2>
<div class="mdc-form-field">
Expand Down
24 changes: 24 additions & 0 deletions demos/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ <h2>CSS Only</h2>
</div>
</section>

<section>
<h2>CSS Only - Disabled</h2>
<div class="mdc-form-field">
<div class="mdc-radio mdc-radio--disabled" data-demo-no-js>
<input class="mdc-radio__native-control" type="radio" id="ex2-radio1" checked name="ex2" disabled>
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
<label id="ex2-radio1-label" for="ex2-radio1">Radio 1</label>
</div>
<div class="mdc-form-field">
<div class="mdc-radio mdc-radio--disabled" data-demo-no-js>
<input class="mdc-radio__native-control" type="radio" id="ex2-radio2" name="ex2" disabled>
<div class="mdc-radio__background">
<div class="mdc-radio__outer-circle"></div>
<div class="mdc-radio__inner-circle"></div>
</div>
</div>
<label id="ex2-radio2-label" for="ex2-radio2">Radio 2</label>
</div>
</section>

<section>
<h2>With Javascript</h2>
<div class="mdc-form-field">
Expand Down
24 changes: 24 additions & 0 deletions packages/mdc-checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ easily position checkboxes and their labels.
</div>
```

#### Disabled Checkboxes

```html
<div class="mdc-checkbox mdc-checkbox--disabled">
<input type="checkbox"
id="basic-disabled-checkbox"
class="mdc-checkbox__native-control"
disabled />
<div class="mdc-checkbox__background">
<svg class="mdc-checkbox__checkmark"
viewBox="0 0 24 24">
<path class="mdc-checkbox__checkmark__path"
fill="none"
stroke="white"
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
</div>
<label for="basic-disabled-checkbox" id="basic-disabled-checkbox-label">This is my disabled checkbox</label>
```

Note that `mdc-checkbox--disabled` is necessary on the root element to prevent hover states from activating.

### Using the JS Component

MDC Checkbox ships with a Component / Foundation combo which progressively enhances the checkbox
Expand Down
5 changes: 5 additions & 0 deletions packages/mdc-checkbox/mdc-checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ fieldset:disabled .mdc-checkbox__native-control,
}
}

.mdc-checkbox--disabled {
cursor: default;
pointer-events: none;
}

.mdc-checkbox--upgraded {
.mdc-checkbox__background,
.mdc-checkbox__checkmark,
Expand Down
3 changes: 2 additions & 1 deletion packages/mdc-radio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ npm install --save @material/radio
```

Note that `mdc-radio--disabled` is necessary on the root element in order to avoid having the ripple
elements intercept pointer events when using JS.
elements intercept pointer events when using JS. When using the CSS-only variation, this is also
necessary to prevent hover states from activating.

### Using the JS Component

Expand Down

0 comments on commit eb51e32

Please sign in to comment.