Skip to content

Commit 10ac2be

Browse files
robertmesserlejelbourn
authored andcommitted
feat(checkbox): drive component with native checkbox (#415)
Also fixes lack of visual focus state. closes #250
1 parent 7323e89 commit 10ac2be

File tree

8 files changed

+220
-223
lines changed

8 files changed

+220
-223
lines changed

src/components/checkbox/checkbox.html

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
<div class="md-checkbox-layout">
1+
<label class="md-checkbox-layout">
22
<div class="md-checkbox-inner-container">
3+
<input class="md-checkbox-input" type="checkbox"
4+
[id]="inputId"
5+
[checked]="checked"
6+
[disabled]="disabled"
7+
[name]="name"
8+
[tabIndex]="tabindex"
9+
[indeterminate]="indeterminate"
10+
[attr.aria-label]="ariaLabel"
11+
[attr.aria-labelledby]="ariaLabelledby"
12+
(focus)="onInputFocus()"
13+
(blur)="onInputBlur()"
14+
(change)="onInteractionEvent($event)">
15+
<div class="md-ink-ripple"></div>
316
<div class="md-checkbox-frame"></div>
417
<div class="md-checkbox-background">
518
<svg version="1.1"
@@ -16,7 +29,7 @@
1629
<div class="md-checkbox-mixedmark"></div>
1730
</div>
1831
</div>
19-
<label [id]="labelId">
32+
<span class="md-checkbox-label">
2033
<ng-content></ng-content>
21-
</label>
22-
</div>
34+
</span>
35+
</label>

src/components/checkbox/checkbox.scss

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import "default-theme";
22
@import "theme-functions";
33
@import "variables";
4+
@import "mixins";
45

56
/** The width/height of the checkbox element. */
67
$md-checkbox-size: $md-toggle-size !default;
@@ -217,11 +218,8 @@ $_md-checkbox-indeterminate-checked-easing-function: cubic-bezier(0.14, 0, 0, 1)
217218
}
218219

219220
md-checkbox {
220-
cursor: pointer;
221-
222-
&:focus {
223-
// TODO(traviskaufman): Add ink ripple on focus state, once ripple is implemented.
224-
outline: none;
221+
&, label {
222+
cursor: pointer;
225223
}
226224
}
227225

@@ -251,7 +249,7 @@ md-checkbox {
251249
}
252250

253251
// TODO(kara): Remove this style when fixing vertical baseline
254-
.md-checkbox-layout label {
252+
.md-checkbox-layout .md-checkbox-label {
255253
line-height: 24px;
256254
}
257255

@@ -461,3 +459,11 @@ md-checkbox {
461459
}
462460
}
463461
}
462+
463+
// Underlying native input element.
464+
// Visually hidden but still able to respond to focus.
465+
.md-checkbox-input {
466+
@include md-visually-hidden;
467+
}
468+
469+
@include md-temporary-ink-ripple(checkbox);

0 commit comments

Comments
 (0)