Skip to content

Commit 18d0fa8

Browse files
crisbetojosephperrott
authored andcommitted
feat(select): align panel appearance and animation with 2018 material design spec (#12975)
1 parent bd21f21 commit 18d0fa8

File tree

8 files changed

+18
-58
lines changed

8 files changed

+18
-58
lines changed

src/demo-app/select/select-demo.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@
1212
padding-right: 0.25em;
1313
}
1414
}
15+
16+
.demo-card {
17+
margin-bottom: 30px;
18+
}

src/lib/select/_select-theme.scss

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
$accent: map-get($theme, accent);
1212
$warn: map-get($theme, warn);
1313

14-
.mat-select-content, .mat-select-panel-done-animating {
15-
background: mat-color($background, card);
16-
}
17-
1814
.mat-select-value {
1915
color: mat-color($foreground, text);
2016
}
@@ -32,6 +28,8 @@
3228
}
3329

3430
.mat-select-panel {
31+
background: mat-color($background, card);
32+
3533
.mat-option.mat-selected:not(.mat-option-multiple) {
3634
background: mat-color($background, hover, 0.12);
3735
}

src/lib/select/select-animations.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import {
1313
style,
1414
transition,
1515
trigger,
16-
query,
17-
animateChild,
18-
group,
1916
} from '@angular/animations';
2017

2118
/**
@@ -39,7 +36,7 @@ export const matSelectAnimations: {
3936
*/
4037
transformPanel: trigger('transformPanel', [
4138
state('void', style({
42-
transform: 'scaleY(0)',
39+
transform: 'scaleY(0.8)',
4340
minWidth: '100%',
4441
opacity: 0
4542
})),
@@ -53,19 +50,16 @@ export const matSelectAnimations: {
5350
minWidth: 'calc(100% + 64px)', // 64px = 48px padding on the left + 16px padding on the right
5451
transform: 'scaleY(1)'
5552
})),
56-
transition('void => *', group([
57-
query('@fadeInContent', animateChild()),
58-
animate('150ms cubic-bezier(0.25, 0.8, 0.25, 1)')
59-
])),
60-
transition('* => void', [
61-
animate('250ms 100ms linear', style({opacity: 0}))
62-
])
53+
transition('void => *', animate('120ms cubic-bezier(0, 0, 0.2, 1)')),
54+
transition('* => void', animate('100ms 25ms linear', style({opacity: 0})))
6355
]),
6456

6557
/**
6658
* This animation fades in the background color and text content of the
6759
* select's options. It is time delayed to occur 100ms after the overlay
6860
* panel has transformed in.
61+
* @deprecated Not used anymore. To be removed.
62+
* @breaking-change 8.0.0
6963
*/
7064
fadeInContent: trigger('fadeInContent', [
7165
state('showing', style({opacity: 1})),

src/lib/select/select.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,8 @@
3737
[@transformPanel]="multiple ? 'showing-multiple' : 'showing'"
3838
(@transformPanel.done)="_panelDoneAnimatingStream.next($event.toState)"
3939
[style.transformOrigin]="_transformOrigin"
40-
[class.mat-select-panel-done-animating]="_panelDoneAnimating"
4140
[style.font-size.px]="_triggerFontSize"
4241
(keydown)="_handleKeydown($event)">
43-
44-
<div
45-
class="mat-select-content"
46-
[@fadeInContent]="'showing'"
47-
(@fadeInContent.done)="_onFadeInDone()">
48-
<ng-content></ng-content>
49-
</div>
42+
<ng-content></ng-content>
5043
</div>
5144
</ng-template>

src/lib/select/select.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
8383
}
8484

8585
.mat-select-panel {
86-
@include mat-menu-base(8);
86+
@include mat-menu-base(4);
8787
padding-top: 0;
8888
padding-bottom: 0;
8989
max-height: $mat-select-panel-max-height;
9090
min-width: 100%; // prevents some animation twitching and test inconsistencies in IE11
91+
border-radius: 4px;
9192

9293
@include cdk-high-contrast {
9394
outline: solid 1px;

src/lib/select/select.spec.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,14 +1672,11 @@ describe('MatSelect', () => {
16721672

16731673
describe('animations', () => {
16741674
let fixture: ComponentFixture<BasicSelect>;
1675-
let trigger: HTMLElement;
16761675
let formField: HTMLElement;
16771676

16781677
beforeEach(fakeAsync(() => {
16791678
fixture = TestBed.createComponent(BasicSelect);
16801679
fixture.detectChanges();
1681-
1682-
trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
16831680
formField = fixture.debugElement.query(By.css('.mat-form-field')).nativeElement;
16841681
}));
16851682

@@ -1702,19 +1699,6 @@ describe('MatSelect', () => {
17021699
'Expected placeholder to animate back down to normal position.');
17031700
}));
17041701

1705-
it('should add a class to the panel when the menu is done animating', fakeAsync(() => {
1706-
trigger.click();
1707-
fixture.detectChanges();
1708-
1709-
const panel = overlayContainerElement.querySelector('.mat-select-panel')!;
1710-
1711-
expect(panel.classList).not.toContain('mat-select-panel-done-animating');
1712-
1713-
flush();
1714-
fixture.detectChanges();
1715-
1716-
expect(panel.classList).toContain('mat-select-panel-done-animating');
1717-
}));
17181702
});
17191703

17201704
describe('keyboard scrolling', () => {

src/lib/select/select.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ export class MatSelectTrigger {}
218218
'(blur)': '_onBlur()',
219219
},
220220
animations: [
221-
matSelectAnimations.transformPanel,
222-
matSelectAnimations.fadeInContent
221+
matSelectAnimations.transformPanel
223222
],
224223
providers: [
225224
{provide: MatFormFieldControl, useExisting: MatSelect},
@@ -280,9 +279,6 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
280279
/** The value of the select panel's transform-origin property. */
281280
_transformOrigin: string = 'top';
282281

283-
/** Whether the panel's animation is done. */
284-
_panelDoneAnimating: boolean = false;
285-
286282
/** Emits when the panel element is finished transforming in. */
287283
_panelDoneAnimatingStream = new Subject<string>();
288284

@@ -520,7 +516,6 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
520516
this.openedChange.emit(true);
521517
} else {
522518
this.openedChange.emit(false);
523-
this._panelDoneAnimating = false;
524519
this.overlayDir.offsetX = 0;
525520
this._changeDetectorRef.markForCheck();
526521
}
@@ -743,15 +738,6 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
743738
}
744739
}
745740

746-
/**
747-
* When the panel content is done fading in, the _panelDoneAnimating property is
748-
* set so the proper class can be added to the panel.
749-
*/
750-
_onFadeInDone(): void {
751-
this._panelDoneAnimating = this.panelOpen;
752-
this._changeDetectorRef.markForCheck();
753-
}
754-
755741
_onFocus() {
756742
if (!this.disabled) {
757743
this._focused = true;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
.example-panel-red .mat-select-content {
1+
.example-panel-red .mat-select-panel {
22
background: rgba(255, 0, 0, 0.5);
33
}
44

5-
.example-panel-green .mat-select-content {
5+
.example-panel-green .mat-select-panel {
66
background: rgba(0, 255, 0, 0.5);
77
}
88

9-
.example-panel-blue .mat-select-content {
9+
.example-panel-blue .mat-select-panel {
1010
background: rgba(0, 0, 255, 0.5);
1111
}

0 commit comments

Comments
 (0)