Skip to content

Commit b468050

Browse files
committed
fix(form-field): correct prefix & suffix icons as well as select arrow for various form field appearances (#9743)
1 parent 42cbdfd commit b468050

File tree

10 files changed

+89
-33
lines changed

10 files changed

+89
-33
lines changed

src/demo-app/input/input-demo.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
.demo-card {
1212
margin: 16px;
13+
14+
mat-card-content {
15+
font-size: 16px;
16+
}
1317
}
1418

1519
.demo-text-align-end {

src/lib/button/button.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@
6767
}
6868
}
6969

70+
// Align icon-buttons correctly inside of standard, fill, and outline form-field appearances.
71+
.mat-form-field:not(.mat-form-field-appearance-legacy) {
72+
.mat-form-field-prefix,
73+
.mat-form-field-suffix {
74+
.mat-icon-button {
75+
display: block;
76+
font-size: inherit;
77+
width: 2.5em;
78+
height: 2.5em;
79+
}
80+
}
81+
}
82+
7083
// The text and icon should be vertical aligned inside a button
7184
.mat-button, .mat-raised-button, .mat-icon-button, .mat-fab, .mat-mini-fab {
7285
color: currentColor;

src/lib/chips/chip-list.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {Directionality} from '@angular/cdk/bidi';
1111
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1212
import {SelectionModel} from '@angular/cdk/collections';
1313
import {BACKSPACE} from '@angular/cdk/keycodes';
14-
import {startWith} from 'rxjs/operators/startWith';
1514
import {
1615
AfterContentInit,
1716
ChangeDetectionStrategy,
@@ -21,7 +20,6 @@ import {
2120
DoCheck,
2221
ElementRef,
2322
EventEmitter,
24-
Inject,
2523
Input,
2624
OnDestroy,
2725
OnInit,
@@ -31,16 +29,12 @@ import {
3129
Self,
3230
ViewEncapsulation,
3331
} from '@angular/core';
34-
import {
35-
ControlValueAccessor,
36-
FormGroupDirective,
37-
NgControl,
38-
NgForm
39-
} from '@angular/forms';
40-
import {ErrorStateMatcher, mixinErrorState, CanUpdateErrorState} from '@angular/material/core';
32+
import {ControlValueAccessor, FormGroupDirective, NgControl, NgForm} from '@angular/forms';
33+
import {CanUpdateErrorState, ErrorStateMatcher, mixinErrorState} from '@angular/material/core';
4134
import {MatFormFieldControl} from '@angular/material/form-field';
4235
import {Observable} from 'rxjs/Observable';
4336
import {merge} from 'rxjs/observable/merge';
37+
import {startWith} from 'rxjs/operators/startWith';
4438
import {Subscription} from 'rxjs/Subscription';
4539
import {MatChip, MatChipEvent, MatChipSelectionChange} from './chip';
4640
import {MatChipInput} from './chip-input';
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
.mat-datepicker-toggle-default-icon {
2-
.mat-form-field-prefix &,
3-
.mat-form-field-suffix & {
4-
width: 1em;
1+
.mat-form-field-appearance-legacy {
2+
.mat-form-field-prefix,
3+
.mat-form-field-suffix {
4+
.mat-datepicker-toggle-default-icon {
5+
width: 1em;
6+
}
7+
}
8+
}
9+
10+
.mat-form-field:not(.mat-form-field-appearance-legacy) {
11+
.mat-form-field-prefix,
12+
.mat-form-field-suffix {
13+
.mat-datepicker-toggle-default-icon {
14+
display: block;
15+
width: 1.5em;
16+
height: 1.5em;
17+
}
18+
19+
.mat-icon-button .mat-datepicker-toggle-default-icon {
20+
margin: auto;
21+
}
522
}
623
}

src/lib/form-field/_form-field-outline-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$is-dark-theme: map-get($theme, is-dark);
1515

1616
$label-disabled-color: mat-color($foreground, disabled-text);
17-
$outline-color: mat-color($foreground, divider, if($is-dark-theme, 0.30, 0.12));
17+
$outline-color: mat-color($foreground, divider, if($is-dark-theme, 0.3, 0.12));
1818
$outline-color-hover: mat-color($foreground, divider, if($is-dark-theme, 1, 0.87));
1919
$outline-color-primary: mat-color($primary);
2020
$outline-color-accent: mat-color($accent);

src/lib/form-field/form-field-legacy.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ $mat-form-field-legacy-underline-height: 1px !default;
1414
-ms-transform: none;
1515
}
1616

17+
.mat-form-field-prefix,
18+
.mat-form-field-suffix {
19+
// Allow icons in a prefix or suffix to adapt to the correct size.
20+
.mat-icon {
21+
width: 1em;
22+
}
23+
24+
// Allow icon buttons in a prefix or suffix to adapt to the correct size.
25+
.mat-icon-button {
26+
font: inherit;
27+
vertical-align: baseline;
28+
29+
.mat-icon {
30+
font-size: inherit;
31+
}
32+
}
33+
}
34+
1735
// The underline is what's shown under the control, its prefix and its suffix.
1836
// The ripple is the blue animation coming on top of it.
1937
.mat-form-field-underline {

src/lib/form-field/form-field-outline.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ $mat-form-field-outline-subscript-padding:
3333
margin-top: -$mat-form-field-outline-label-overlap;
3434
}
3535

36+
.mat-form-field-prefix,
37+
.mat-form-field-suffix {
38+
top: $mat-form-field-outline-label-overlap;
39+
}
40+
3641
.mat-form-field-outline {
3742
display: flex;
3843
position: absolute;
@@ -52,7 +57,7 @@ $mat-form-field-outline-subscript-padding:
5257
border-radius: $mat-form-field-outline-border-radius 0 0 $mat-form-field-outline-border-radius;
5358
border-right-style: none;
5459

55-
[dir="rtl"] & {
60+
[dir='rtl'] & {
5661
border-right-style: solid;
5762
border-left-style: none;
5863
border-radius: 0 $mat-form-field-outline-border-radius $mat-form-field-outline-border-radius
@@ -65,7 +70,7 @@ $mat-form-field-outline-subscript-padding:
6570
border-left-style: none;
6671
flex-grow: 1;
6772

68-
[dir="rtl"] & {
73+
[dir='rtl'] & {
6974
border-left-style: solid;
7075
border-right-style: none;
7176
border-radius: $mat-form-field-outline-border-radius 0 0

src/lib/form-field/form-field.scss

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,7 @@ $mat-form-field-default-infix-width: 180px !default;
4343
.mat-form-field-suffix {
4444
white-space: nowrap;
4545
flex: none;
46-
47-
// Allow icons in a prefix or suffix to adapt to the correct size.
48-
.mat-icon {
49-
width: 1em;
50-
}
51-
52-
// Allow icon buttons in a prefix or suffix to adapt to the correct size.
53-
.mat-icon-button {
54-
font: inherit;
55-
vertical-align: baseline;
56-
57-
.mat-icon {
58-
font-size: inherit;
59-
}
60-
}
46+
position: relative;
6147
}
6248

6349
.mat-form-field-infix {

src/lib/icon/icon.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ $mat-icon-size: 24px !default;
1111
height: $mat-icon-size;
1212
width: $mat-icon-size;
1313
}
14+
15+
.mat-form-field:not(.mat-form-field-appearance-legacy) {
16+
.mat-form-field-prefix,
17+
.mat-form-field-suffix {
18+
.mat-icon {
19+
display: block;
20+
}
21+
22+
.mat-icon-button .mat-icon {
23+
margin: auto;
24+
}
25+
}
26+
}

src/lib/select/select.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
4646
display: table-cell;
4747
vertical-align: middle;
4848

49-
// When used in a box appearance form-field the arrow should be centered in the box.
50-
.mat-form-field-appearance-fill & {
49+
// When used in a box or standard appearance form-field the arrow should be shifted up 50%.
50+
.mat-form-field-appearance-fill &,
51+
.mat-form-field-appearance-standard & {
5152
transform: translateY(-50%);
5253
}
54+
55+
// When used in a outline form-field the arrow should be shifted up 25%.
56+
.mat-form-field-appearance-outline & {
57+
transform: translateY(-25%);
58+
}
5359
}
5460

5561
.mat-select-arrow {

0 commit comments

Comments
 (0)