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

Commit 3610828

Browse files
committed
fix(checkbox) rework checkbox to match Material Design spec
automatic 16px horizontal padding when in row configuration change checkbox size from 20px to 18px blank checkboxes are sized properly add md-spacing options for different spacing styles add alignment math support custom margins for md-checkbox
1 parent cef9c44 commit 3610828

File tree

3 files changed

+85
-28
lines changed

3 files changed

+85
-28
lines changed

src/components/checkbox/checkbox.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ angular
3131
* @param {expression=} md-indeterminate This determines when the checkbox should be rendered as 'indeterminate'.
3232
* If a truthy expression or no value is passed in the checkbox renders in the md-indeterminate state.
3333
* If falsy expression is passed in it just looks like a normal unchecked checkbox.
34-
* The indeterminate, checked, and unchecked states are mutually exclusive. A box cannot be in any two states at the same time.
35-
* Adding the 'md-indeterminate' attribute overrides any checked/unchecked rendering logic.
34+
* The indeterminate, checked, and unchecked states are mutually exclusive. A box cannot be in any two states at the same time.
35+
* Adding the 'md-indeterminate' attribute overrides any checked/unchecked rendering logic.
3636
* When using the 'md-indeterminate' attribute use 'ng-checked' to define rendering logic instead of using 'ng-model'.
37-
* @param {expression=} ng-checked If this expression evaluates as truthy, the 'md-checked' css class is added to the checkbox and it
37+
* @param {expression=} ng-checked If this expression evaluates as truthy, the 'md-checked' css class is added to the checkbox and it
3838
* will appear checked.
39+
* @param md-spacing {string=} Override spacing between icon and text. Default is 36px. Use `wide` for 48px.
40+
* Use `extra-wide` for 56px.
3941
*
4042
* @usage
4143
* <hljs lang="html">

src/components/checkbox/checkbox.scss

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
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: 8px !default;
10+
$container-checkbox-margin: 3px !default;
1111

12-
.md-inline-form {
13-
md-checkbox {
14-
margin: 19px 0 18px;
15-
}
16-
}
12+
// md-spacing values (horizontal spacing with icons)
13+
// normal = 36px (Angular Material default)
14+
// wide = 48px (Material Design Spec dense)
15+
// extra-wide = 56px (Material Design Spec default)
16+
$checkbox-text-margin: 36px !default;
17+
$checkbox-text-margin-wide: 48px !default;
18+
$checkbox-text-margin-extra-wide: 56px !default;
19+
20+
// from input.scss
21+
$input-container-margin-top: 18px !default;
22+
$input-container-padding-top: 2px !default;
23+
$input-padding-top: 2px !default;
24+
$input-padding-bottom: 1px !default;
25+
$input-border: 1px !default;
26+
27+
$md-inline-alignment: $input-container-margin-top + $input-container-padding-top
28+
+ $input-padding-top + $input-padding-bottom + $input-border
29+
- $checkbox-text-margin-top !default;
1730

1831
md-checkbox {
1932
box-sizing: border-box;
2033
display: inline-block;
21-
margin-bottom: $checkbox-margin;
2234
white-space: nowrap;
2335
cursor: pointer;
2436
outline: none;
2537
user-select: none;
2638
position: relative;
2739
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);
31-
32-
&:last-of-type {
33-
margin-left: 0;
34-
margin-right: 0;
35-
}
40+
min-height: $checkbox-width * 2;
3641

3742
&.md-focused:not([disabled]) {
3843
._md-container:before {
@@ -49,22 +54,72 @@ md-checkbox {
4954
}
5055
}
5156

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

59+
._md-container {
60+
// Use auto for compatibility with md-checkbox padding
61+
top: auto;
62+
@include rtl(left, initial, auto);
63+
@include rtl(right, auto, initial);
64+
margin: $container-checkbox-margin;
65+
margin-top: $checkbox-height + $container-checkbox-margin;
66+
}
67+
5868
._md-label {
5969
box-sizing: border-box;
6070
position: relative;
6171
display: inline-block;
6272
vertical-align: middle;
6373
white-space: normal;
6474
user-select: text;
75+
margin-top: $checkbox-text-margin-top;
76+
margin-bottom: auto;
6577

66-
@include rtl(margin-left, $checkbox-text-margin + $checkbox-width, 0);
67-
@include rtl(margin-right, 0, $checkbox-text-margin + $checkbox-width);
78+
@include rtl(margin-left, $checkbox-text-margin, 0);
79+
@include rtl(margin-right, 0, $checkbox-text-margin);
6880

81+
&:empty {
82+
// clamp to checkbox-container margins
83+
@include rtl(margin-left, $checkbox-height + ($container-checkbox-margin * 2), 0);
84+
@include rtl(margin-right, 0, $checkbox-height + ($container-checkbox-margin * 2));
85+
}
86+
87+
}
88+
89+
[md-spacing="wide"] &,
90+
&[md-spacing="wide"] {
91+
._md-label {
92+
@include rtl(margin-left, $checkbox-text-margin-wide, 0);
93+
@include rtl(margin-right, 0, $checkbox-text-margin-wide);
94+
}
95+
}
96+
97+
[md-spacing="extra-wide"] &,
98+
&[md-spacing="extra-wide"]{
99+
._md-label {
100+
@include rtl(margin-left, $checkbox-text-margin-extra-wide, 0);
101+
@include rtl(margin-right, 0, $checkbox-text-margin-extra-wide);
102+
}
103+
}
104+
}
105+
106+
107+
.layout-row,
108+
.layout-xs-row, .layout-gt-xs-row,
109+
.layout-sm-row, .layout-gt-sm-row,
110+
.layout-md-row, .layout-gt-md-row,
111+
.layout-lg-row, .layout-gt-lg-row,
112+
.layout-xl-row {
113+
& > md-checkbox:not(:last-child), {
114+
@include rtl(margin-right, $checkbox-margin-end, 0);
115+
@include rtl(margin-left, 0, $checkbox-margin-end);
116+
}
117+
118+
&.md-inline-form,
119+
.md-inline-form & {
120+
> md-checkbox {
121+
margin-top: $md-inline-alignment;
122+
margin-bottom: auto;
123+
}
69124
}
70125
}

src/core/style/variables.scss

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

130130

131131
// Shared Checkbox variables
132-
$checkbox-width: 20px !default;
132+
$checkbox-width: 18px !default;
133133
$checkbox-height: $checkbox-width !default;
134134
$checkbox-border-radius: 2px !default;
135135
$checkbox-border-width: 2px !default;

0 commit comments

Comments
 (0)