Skip to content

Commit 5cdc4fd

Browse files
willshowellkara
authored andcommitted
style(chips): clean up alignment and theming (#5760)
1 parent addf1ce commit 5cdc4fd

File tree

4 files changed

+46
-37
lines changed

4 files changed

+46
-37
lines changed

src/demo-app/chips/chips-demo.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,4 @@
2424
md-chip-list input {
2525
width: 150px;
2626
}
27-
28-
.mat-chip-remove.mat-icon {
29-
font-size: 16px;
30-
width: 1em;
31-
height: 1em;
32-
vertical-align: middle;
33-
cursor: pointer;
34-
}
3527
}

src/lib/chips/_chips-theme.scss

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
// TODO(crisbeto): these values don't correspond to any of the typography breakpoints.
66
$mat-chip-font-size: 13px;
7-
$mat-chip-line-height: 16px;
7+
$mat-chip-line-height: 18px;
8+
$mat-chip-remove-font-size: 18px;
89

910
@mixin mat-chips-theme-color($color) {
10-
@include mat-chips-color(mat-contrast($color, 500), mat-color($color, 500));
11+
@include mat-chips-color(mat-color($color, default-contrast), mat-color($color));
1112
}
1213

1314
@mixin mat-chips-color($foreground, $background) {
@@ -32,25 +33,15 @@ $mat-chip-line-height: 16px;
3233
$background: map-get($theme, background);
3334
$foreground: map-get($theme, foreground);
3435

35-
// Use spec-recommended color for regular foreground, and utilise contrast color for a grey very
36-
// close to the selected spec since no guidance is provided and to ensure palette consistency.
37-
$light-foreground: rgba(0, 0, 0, 0.87);
38-
$light-selected-foreground: mat-contrast($mat-grey, 600);
36+
$unselected-background: mat-color($background, unselected-chip);
37+
$unselected-foreground: mat-color($foreground, text);
3938

40-
// The spec only provides guidance for light-themed chips. When inside of a dark theme, fall back
41-
// to standard background and foreground colors.
42-
$unselected-background: if($is-dark-theme, mat-color($background, card), #e0e0e0);
43-
$unselected-foreground: if($is-dark-theme, mat-color($foreground, text), $light-foreground);
44-
45-
$selected-background: if($is-dark-theme, mat-color($background, app-bar), #808080);
46-
$selected-foreground: if($is-dark-theme, mat-color($foreground, text), $light-selected-foreground);
4739

4840
.mat-chip:not(.mat-basic-chip) {
4941
@include mat-chips-color($unselected-foreground, $unselected-background);
5042
}
5143

5244
.mat-chip.mat-chip-selected {
53-
@include mat-chips-color($selected-foreground, $selected-background);
5445

5546
&.mat-primary {
5647
@include mat-chips-theme-color($primary);
@@ -70,5 +61,9 @@ $mat-chip-line-height: 16px;
7061
.mat-chip {
7162
font-size: $mat-chip-font-size;
7263
line-height: $mat-chip-line-height;
64+
65+
.mat-chip-remove.mat-icon {
66+
font-size: $mat-chip-remove-font-size;
67+
}
7368
}
7469
}

src/lib/chips/chips.scss

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
@import '../core/a11y/a11y';
2+
@import '../core/style/elevation';
23

3-
$mat-chip-vertical-padding: 8px;
4+
$mat-chip-vertical-padding: 7px;
45
$mat-chip-horizontal-padding: 12px;
5-
$mat-chip-remove-margin: -4px;
6+
$mat-chip-remove-margin-before: 6px;
7+
$mat-chip-remove-margin-after: -4px;
68

7-
$mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
9+
$mat-chips-chip-margin: 8px;
810

911
.mat-chip-list-wrapper {
1012
display: flex;
@@ -14,9 +16,11 @@ $mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
1416
}
1517

1618
.mat-chip:not(.mat-basic-chip) {
17-
display: inline-block;
19+
display: inline-flex;
1820
padding: $mat-chip-vertical-padding $mat-chip-horizontal-padding $mat-chip-vertical-padding $mat-chip-horizontal-padding;
1921
border-radius: $mat-chip-horizontal-padding * 2;
22+
align-items: center;
23+
cursor: default;
2024

2125
// Apply a margin to adjacent sibling chips.
2226
& + & {
@@ -25,18 +29,28 @@ $mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
2529
[dir='rtl'] & {
2630
margin: 0 $mat-chips-chip-margin 0 0;
2731
}
32+
}
2833

29-
.mat-input-prefix & {
30-
&:last-child {
31-
margin-right: $mat-chips-chip-margin;
32-
}
34+
.mat-input-prefix & {
35+
&:last-child {
36+
margin-right: $mat-chips-chip-margin;
37+
}
3338

34-
[dir='rtl'] &:last-child {
35-
margin-left: $mat-chips-chip-margin;
36-
}
39+
[dir='rtl'] &:last-child {
40+
margin-left: $mat-chips-chip-margin;
3741
}
3842
}
3943

44+
.mat-chip-remove.mat-icon {
45+
width: 1em;
46+
height: 1em;
47+
}
48+
49+
&:focus {
50+
@include mat-elevation(3);
51+
outline: none;
52+
}
53+
4054
@include cdk-high-contrast {
4155
outline: solid 1px;
4256
}
@@ -48,11 +62,11 @@ $mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
4862
.mat-chip:not(.mat-basic-chip) {
4963
display: block;
5064
margin: 0;
51-
margin-bottom: $mat-chip-vertical-padding;
65+
margin-bottom: $mat-chips-chip-margin;
5266

5367
[dir='rtl'] & {
5468
margin: 0;
55-
margin-bottom: $mat-chip-vertical-padding;
69+
margin-bottom: $mat-chips-chip-margin;
5670
}
5771

5872
&:last-child, [dir='rtl'] &:last-child {
@@ -62,9 +76,15 @@ $mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
6276
}
6377

6478
.mat-input-prefix .mat-chip-list-wrapper {
65-
margin-bottom: $mat-chip-vertical-padding;
79+
margin-bottom: $mat-chips-chip-margin;
6680
}
6781

6882
.mat-chip-remove {
69-
margin: 0 $mat-chip-remove-margin 0 0;
83+
margin-right: $mat-chip-remove-margin-after;
84+
margin-left: $mat-chip-remove-margin-before;
85+
86+
[dir='rtl'] & {
87+
margin-right: $mat-chip-remove-margin-before;
88+
margin-left: $mat-chip-remove-margin-after;
89+
}
7090
}

src/lib/core/theming/_palette.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ $mat-light-theme-background: (
659659
selected-button: map_get($mat-grey, 300),
660660
selected-disabled-button: map_get($mat-grey, 400),
661661
disabled-button-toggle: map_get($mat-grey, 200),
662+
unselected-chip: map_get($mat-grey, 300),
662663
);
663664

664665
// Background palette for dark themes.
@@ -675,6 +676,7 @@ $mat-dark-theme-background: (
675676
selected-button: map_get($mat-grey, 900),
676677
selected-disabled-button: map_get($mat-grey, 800),
677678
disabled-button-toggle: map_get($mat-grey, 1000),
679+
unselected-chip: map_get($mat-grey, 700),
678680
);
679681

680682
// Foreground palette for light themes.

0 commit comments

Comments
 (0)