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

Commit 69169d6

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
1 parent 39911d3 commit 69169d6

File tree

3 files changed

+65
-27
lines changed

3 files changed

+65
-27
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: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
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: 3px !default;
9+
$checkbox-margin-end: 16px !default;
1110

12-
.md-inline-form {
13-
md-checkbox {
14-
margin: 19px 0 18px;
15-
}
16-
}
11+
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+
17+
$checkbox-text-margin: 36px !default;
18+
$checkbox-text-margin-wide: 48px !default;
19+
$checkbox-text-margin-extra-wide: 56px !default;
1720

1821
md-checkbox {
1922
box-sizing: border-box;
2023
display: inline-block;
21-
margin-bottom: $checkbox-margin;
24+
margin: $checkbox-margin;
2225
white-space: nowrap;
2326
cursor: pointer;
2427
outline: none;
2528
user-select: none;
2629
position: relative;
2730
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-
}
31+
min-height: $checkbox-width * 2;
32+
margin-left: $checkbox-margin;
33+
margin-right: $checkbox-margin;
3634

3735
&.md-focused:not([disabled]) {
3836
._md-container:before {
@@ -49,22 +47,60 @@ md-checkbox {
4947
}
5048
}
5149

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

52+
._md-container {
53+
top: $checkbox-height;
54+
}
55+
5856
._md-label {
5957
box-sizing: border-box;
6058
position: relative;
6159
display: inline-block;
6260
vertical-align: middle;
6361
white-space: normal;
6462
user-select: text;
63+
margin-top: 6px;
64+
margin-bottom: 6px;
65+
66+
@include rtl(margin-left, $checkbox-text-margin - $checkbox-margin, 0);
67+
@include rtl(margin-right, 0, $checkbox-text-margin - $checkbox-margin);
68+
69+
&:empty {
70+
display: none;
71+
}
72+
73+
}
74+
75+
&[md-spacing="wide"]{
76+
._md-label {
77+
@include rtl(margin-left, $checkbox-text-margin-wide - $checkbox-margin, 0);
78+
@include rtl(margin-right, 0, $checkbox-text-margin-wide - $checkbox-margin);
79+
}
80+
}
6581

66-
@include rtl(margin-left, $checkbox-text-margin + $checkbox-width, 0);
67-
@include rtl(margin-right, 0, $checkbox-text-margin + $checkbox-width);
82+
&[md-spacing="extra-wide"]{
83+
._md-label {
84+
@include rtl(margin-left, $checkbox-text-margin-extra-wide - $checkbox-margin, 0);
85+
@include rtl(margin-right, 0, $checkbox-text-margin-extra-wide - $checkbox-margin);
86+
}
87+
}
88+
}
89+
90+
91+
.layout-row,
92+
.layout-xs-row, .layout-gt-xs-row,
93+
.layout-sm-row, .layout-gt-sm-row,
94+
.layout-md-row, .layout-gt-md-row,
95+
.layout-lg-row, .layout-gt-lg-row,
96+
.layout-xl-row {
97+
& > md-checkbox:not(:last-child), {
98+
@include rtl(margin-left, $checkbox-margin, $checkbox-margin-end);
99+
@include rtl(margin-right, $checkbox-margin-end, $checkbox-margin);
100+
}
68101

102+
.md-inline-form & > md-checkbox {
103+
margin-top: 19px;
104+
margin-bottom: auto;
69105
}
70106
}

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)