Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit c893050

Browse files
clshortfuseSplaktar
authored andcommitted
fix(checkbox) update CSS to match spec
Checkbox did not support a11y minimum touch target and the box was larger than spec. - Change checkbox size from 20px to 18px - Keep horizontal size flush when text is blank - Add md-dense support for checkbox - Add inline alignment math to SCSS - Increase size of md-checkbox to properly support touch - Add demo for md-dense support Fixes #9351. Fixes #9927. Closes #8713. BREAKING CHANGE: The default size and spacing for `md-checkbox` has been updated to align with the Material Design specification. Additionally, many new Sass variables have been added for customizing the size and spacing of `md-checkbox`. The `md-dense` class is now supported. After updating to this version, you may need to adjust the layout of your app due to the larger touch-friendly size of checkbox. You may also want to make use of `md-dense` in cases where space is limited.
1 parent 96ec741 commit c893050

File tree

3 files changed

+103
-19
lines changed

3 files changed

+103
-19
lines changed

src/components/checkbox/checkbox.scss

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
1-
//$checkbox-width: 20px !default;
1+
//$checkbox-width: 18px !default;
22
//$checkbox-height: $checkbox-width !default;
33
//$checkbox-border-radius: 2px !default;
44
//$checkbox-border-width: 2px !default;
55
//
66
// ^^ defined in _variables.scss
77
//
8-
$checkbox-margin: 16px !default;
9-
$checkbox-text-margin: 10px !default;
10-
$checkbox-top: 12px !default;
8+
$checkbox-margin-end: 16px !default;
9+
$checkbox-text-margin-top: 10px !default;
10+
$container-checkbox-margin: 3px !default;
11+
12+
$checkbox-min-height: 48px !default;
13+
$checkbox-min-height-dense: 36px !default;
14+
$checkbox-text-margin: 36px !default;
15+
16+
// from input.scss
17+
$input-container-margin-top: 18px !default;
18+
$input-container-padding-top: 2px !default;
19+
$input-padding-top: 2px !default;
20+
$input-padding-bottom: 1px !default;
21+
$input-border: 1px !default;
22+
23+
$md-inline-alignment: $input-container-margin-top + $input-container-padding-top
24+
+ $input-padding-top + $input-padding-bottom + $input-border
25+
- $checkbox-text-margin-top !default;
1126

1227
.md-inline-form {
1328
md-checkbox {
14-
margin: 19px 0 18px;
29+
margin-top: $md-inline-alignment;
30+
margin-bottom: auto;
1531
}
1632
}
1733

1834
md-checkbox {
1935
box-sizing: border-box;
2036
display: inline-block;
21-
margin-bottom: $checkbox-margin;
2237
white-space: nowrap;
2338
cursor: pointer;
2439
outline: none;
2540
user-select: none;
2641
position: relative;
2742
min-width: $checkbox-width;
28-
min-height: $checkbox-width;
29-
@include rtl(margin-left, 0, $checkbox-margin);
30-
@include rtl(margin-right, $checkbox-margin, 0);
43+
@include dense(min-height, $checkbox-min-height, $checkbox-min-height-dense);
44+
@include rtl(margin-left, 0, $checkbox-margin-end);
45+
@include rtl(margin-right, $checkbox-margin-end, 0);
3146

3247
&:last-of-type {
3348
margin-left: 0;
3449
margin-right: 0;
3550
}
36-
3751
&.md-focused:not([disabled]) {
3852
.md-container:before {
3953
left: -8px;
@@ -49,22 +63,34 @@ md-checkbox {
4963
}
5064
}
5165

52-
&.md-align-top-left > div.md-container {
53-
top: $checkbox-top;
54-
}
55-
5666
@include checkbox-container;
5767

68+
.md-container {
69+
// Use auto for compatibility with md-checkbox padding
70+
top: auto;
71+
left: auto;
72+
right: auto;
73+
margin: $container-checkbox-margin;
74+
margin-top: $checkbox-height + $container-checkbox-margin;
75+
}
76+
5877
.md-label {
5978
box-sizing: border-box;
6079
position: relative;
6180
display: inline-block;
6281
vertical-align: middle;
6382
white-space: normal;
6483
user-select: text;
84+
margin-top: $checkbox-text-margin-top;
85+
margin-bottom: auto;
6586

66-
@include rtl(margin-left, $checkbox-text-margin + $checkbox-width, 0);
67-
@include rtl(margin-right, 0, $checkbox-text-margin + $checkbox-width);
87+
@include rtl-prop(margin-left, margin-right, $checkbox-text-margin, 0);
88+
89+
&:empty {
90+
// clamp to checkbox-container margins
91+
@include rtl(margin-left, $checkbox-height + ($container-checkbox-margin * 2), 0);
92+
@include rtl(margin-right, 0, $checkbox-height + ($container-checkbox-margin * 2));
93+
}
6894

6995
}
70-
}
96+
}

src/components/checkbox/demoBasicUsage/index.html

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,64 @@
5757
</div>
5858
</div>
5959
</fieldset>
60-
60+
</div>
61+
<br/>
62+
<div layout='row'>
63+
<fieldset class="standard">
64+
<legend>Default Spacing</legend>
65+
<div>
66+
<md-checkbox ng-model="data.cb1" aria-label="Checkbox 1">
67+
Checkbox 1: {{ data.cb1 }}
68+
</md-checkbox>
69+
<div>
70+
<md-checkbox
71+
ng-model="data.cb2"
72+
aria-label="Checkbox 2"
73+
ng-true-value="'yup'"
74+
ng-false-value="'nope'"
75+
class="md-warn md-align-top-left" flex>
76+
Checkbox 2 (md-warn) <br/>
77+
<span class="ipsum">
78+
Duis placerat lectus et justo mollis, nec sodales orci congue. Vestibulum semper non urna ac suscipit.
79+
Vestibulum tempor, ligula id laoreet hendrerit, massa augue iaculis magna,
80+
sit amet dapibus tortor ligula non nibh.
81+
</span>
82+
<br/>
83+
{{ data.cb2 }}
84+
</md-checkbox>
85+
</div>
86+
<md-checkbox ng-disabled="true" aria-label="Disabled checkbox" ng-model="data.cb3">
87+
Checkbox: Disabled
88+
</md-checkbox>
89+
</div>
90+
</fieldset>
91+
<fieldset class="standard md-dense">
92+
<legend>Dense Spacing with "md-dense"</legend>
93+
<div>
94+
<md-checkbox ng-model="data.cb1" aria-label="Checkbox 1">
95+
Checkbox 1: {{ data.cb1 }}
96+
</md-checkbox>
97+
<div>
98+
<md-checkbox
99+
ng-model="data.cb2"
100+
aria-label="Checkbox 2"
101+
ng-true-value="'yup'"
102+
ng-false-value="'nope'"
103+
class="md-warn md-align-top-left" flex>
104+
Checkbox 2 (md-warn) <br/>
105+
<span class="ipsum">
106+
Duis placerat lectus et justo mollis, nec sodales orci congue. Vestibulum semper non urna ac suscipit.
107+
Vestibulum tempor, ligula id laoreet hendrerit, massa augue iaculis magna,
108+
sit amet dapibus tortor ligula non nibh.
109+
</span>
110+
<br/>
111+
{{ data.cb2 }}
112+
</md-checkbox>
113+
</div>
114+
<md-checkbox ng-disabled="true" aria-label="Disabled checkbox" ng-model="data.cb3">
115+
Checkbox: Disabled
116+
</md-checkbox>
117+
</div>
118+
</fieldset>
61119
</div>
62120
</div>

src/core/style/_variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ $button-fab-padding: rem(1.60) !default;
127127

128128

129129
// Shared Checkbox variables
130-
$checkbox-width: 20px !default;
130+
$checkbox-width: 18px !default;
131131
$checkbox-height: $checkbox-width !default;
132132
$checkbox-border-radius: 2px !default;
133133
$checkbox-border-width: 2px !default;

0 commit comments

Comments
 (0)