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

Commit eb51e32

Browse files
authored
fix(checkbox): Add --disabled modifier to checkbox root element to prevent hover state (#533)
1 parent be85871 commit eb51e32

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

demos/checkbox.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ <h2>CSS Only</h2>
8181
<button type="button" onclick="document.querySelector('.mdc-form-field').classList.toggle('mdc-form-field--align-end');">Toggle Align End</button>
8282
<button type="button" onclick="document.getElementById('basic-checkbox').disabled = !document.getElementById('basic-checkbox').disabled;">Toggle Disabled</button>
8383
</section>
84+
85+
<section>
86+
<h2>CSS Only - Disabled</h2>
87+
<div class="mdc-form-field">
88+
<div class="mdc-checkbox mdc-checkbox--disabled">
89+
<input type="checkbox"
90+
id="basic-disabled-checkbox"
91+
class="mdc-checkbox__native-control"
92+
disabled />
93+
<div class="mdc-checkbox__background">
94+
<svg class="mdc-checkbox__checkmark"
95+
viewBox="0 0 24 24">
96+
<path class="mdc-checkbox__checkmark__path"
97+
fill="none"
98+
stroke="white"
99+
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
100+
</svg>
101+
<div class="mdc-checkbox__mixedmark"></div>
102+
</div>
103+
</div>
104+
<label for="basic-disabled-checkbox" id="basic-disabled-checkbox-label">This is my disabled checkbox</label>
105+
</div>
106+
</section>
107+
84108
<section>
85109
<h2>With Javascript</h2>
86110
<div class="mdc-form-field">

demos/radio.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ <h2>CSS Only</h2>
6969
</div>
7070
</section>
7171

72+
<section>
73+
<h2>CSS Only - Disabled</h2>
74+
<div class="mdc-form-field">
75+
<div class="mdc-radio mdc-radio--disabled" data-demo-no-js>
76+
<input class="mdc-radio__native-control" type="radio" id="ex2-radio1" checked name="ex2" disabled>
77+
<div class="mdc-radio__background">
78+
<div class="mdc-radio__outer-circle"></div>
79+
<div class="mdc-radio__inner-circle"></div>
80+
</div>
81+
</div>
82+
<label id="ex2-radio1-label" for="ex2-radio1">Radio 1</label>
83+
</div>
84+
<div class="mdc-form-field">
85+
<div class="mdc-radio mdc-radio--disabled" data-demo-no-js>
86+
<input class="mdc-radio__native-control" type="radio" id="ex2-radio2" name="ex2" disabled>
87+
<div class="mdc-radio__background">
88+
<div class="mdc-radio__outer-circle"></div>
89+
<div class="mdc-radio__inner-circle"></div>
90+
</div>
91+
</div>
92+
<label id="ex2-radio2-label" for="ex2-radio2">Radio 2</label>
93+
</div>
94+
</section>
95+
7296
<section>
7397
<h2>With Javascript</h2>
7498
<div class="mdc-form-field">

packages/mdc-checkbox/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ easily position checkboxes and their labels.
6363
</div>
6464
```
6565

66+
#### Disabled Checkboxes
67+
68+
```html
69+
<div class="mdc-checkbox mdc-checkbox--disabled">
70+
<input type="checkbox"
71+
id="basic-disabled-checkbox"
72+
class="mdc-checkbox__native-control"
73+
disabled />
74+
<div class="mdc-checkbox__background">
75+
<svg class="mdc-checkbox__checkmark"
76+
viewBox="0 0 24 24">
77+
<path class="mdc-checkbox__checkmark__path"
78+
fill="none"
79+
stroke="white"
80+
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
81+
</svg>
82+
<div class="mdc-checkbox__mixedmark"></div>
83+
</div>
84+
</div>
85+
<label for="basic-disabled-checkbox" id="basic-disabled-checkbox-label">This is my disabled checkbox</label>
86+
```
87+
88+
Note that `mdc-checkbox--disabled` is necessary on the root element to prevent hover states from activating.
89+
6690
### Using the JS Component
6791

6892
MDC Checkbox ships with a Component / Foundation combo which progressively enhances the checkbox

packages/mdc-checkbox/mdc-checkbox.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ fieldset:disabled .mdc-checkbox__native-control,
252252
}
253253
}
254254

255+
.mdc-checkbox--disabled {
256+
cursor: default;
257+
pointer-events: none;
258+
}
259+
255260
.mdc-checkbox--upgraded {
256261
.mdc-checkbox__background,
257262
.mdc-checkbox__checkmark,

packages/mdc-radio/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ npm install --save @material/radio
4848
```
4949

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

5354
### Using the JS Component
5455

0 commit comments

Comments
 (0)