Skip to content

feat(select): align panel appearance and animation with 2018 material design spec #12975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/demo-app/select/select-demo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
padding-right: 0.25em;
}
}

.demo-card {
margin-bottom: 30px;
}
6 changes: 2 additions & 4 deletions src/lib/select/_select-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
$accent: map-get($theme, accent);
$warn: map-get($theme, warn);

.mat-select-content, .mat-select-panel-done-animating {
background: mat-color($background, card);
}

.mat-select-value {
color: mat-color($foreground, text);
}
Expand All @@ -32,6 +28,8 @@
}

.mat-select-panel {
background: mat-color($background, card);

.mat-option.mat-selected:not(.mat-option-multiple) {
background: mat-color($background, hover, 0.12);
}
Expand Down
16 changes: 5 additions & 11 deletions src/lib/select/select-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import {
style,
transition,
trigger,
query,
animateChild,
group,
} from '@angular/animations';

/**
Expand All @@ -39,7 +36,7 @@ export const matSelectAnimations: {
*/
transformPanel: trigger('transformPanel', [
state('void', style({
transform: 'scaleY(0)',
transform: 'scaleY(0.8)',
minWidth: '100%',
opacity: 0
})),
Expand All @@ -53,19 +50,16 @@ export const matSelectAnimations: {
minWidth: 'calc(100% + 64px)', // 64px = 48px padding on the left + 16px padding on the right
transform: 'scaleY(1)'
})),
transition('void => *', group([
query('@fadeInContent', animateChild()),
animate('150ms cubic-bezier(0.25, 0.8, 0.25, 1)')
])),
transition('* => void', [
animate('250ms 100ms linear', style({opacity: 0}))
])
transition('void => *', animate('120ms cubic-bezier(0, 0, 0.2, 1)')),
transition('* => void', animate('100ms 25ms linear', style({opacity: 0})))
]),

/**
* This animation fades in the background color and text content of the
* select's options. It is time delayed to occur 100ms after the overlay
* panel has transformed in.
* @deprecated Not used anymore. To be removed.
* @breaking-change 8.0.0
*/
fadeInContent: trigger('fadeInContent', [
state('showing', style({opacity: 1})),
Expand Down
9 changes: 1 addition & 8 deletions src/lib/select/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,8 @@
[@transformPanel]="multiple ? 'showing-multiple' : 'showing'"
(@transformPanel.done)="_panelDoneAnimatingStream.next($event.toState)"
[style.transformOrigin]="_transformOrigin"
[class.mat-select-panel-done-animating]="_panelDoneAnimating"
[style.font-size.px]="_triggerFontSize"
(keydown)="_handleKeydown($event)">

<div
class="mat-select-content"
[@fadeInContent]="'showing'"
(@fadeInContent.done)="_onFadeInDone()">
<ng-content></ng-content>
</div>
<ng-content></ng-content>
</div>
</ng-template>
3 changes: 2 additions & 1 deletion src/lib/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
}

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

@include cdk-high-contrast {
outline: solid 1px;
Expand Down
16 changes: 0 additions & 16 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1672,14 +1672,11 @@ describe('MatSelect', () => {

describe('animations', () => {
let fixture: ComponentFixture<BasicSelect>;
let trigger: HTMLElement;
let formField: HTMLElement;

beforeEach(fakeAsync(() => {
fixture = TestBed.createComponent(BasicSelect);
fixture.detectChanges();

trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
formField = fixture.debugElement.query(By.css('.mat-form-field')).nativeElement;
}));

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

it('should add a class to the panel when the menu is done animating', fakeAsync(() => {
trigger.click();
fixture.detectChanges();

const panel = overlayContainerElement.querySelector('.mat-select-panel')!;

expect(panel.classList).not.toContain('mat-select-panel-done-animating');

flush();
fixture.detectChanges();

expect(panel.classList).toContain('mat-select-panel-done-animating');
}));
});

describe('keyboard scrolling', () => {
Expand Down
16 changes: 1 addition & 15 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ export class MatSelectTrigger {}
'(blur)': '_onBlur()',
},
animations: [
matSelectAnimations.transformPanel,
matSelectAnimations.fadeInContent
matSelectAnimations.transformPanel
],
providers: [
{provide: MatFormFieldControl, useExisting: MatSelect},
Expand Down Expand Up @@ -280,9 +279,6 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
/** The value of the select panel's transform-origin property. */
_transformOrigin: string = 'top';

/** Whether the panel's animation is done. */
_panelDoneAnimating: boolean = false;

/** Emits when the panel element is finished transforming in. */
_panelDoneAnimatingStream = new Subject<string>();

Expand Down Expand Up @@ -520,7 +516,6 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
this.openedChange.emit(true);
} else {
this.openedChange.emit(false);
this._panelDoneAnimating = false;
this.overlayDir.offsetX = 0;
this._changeDetectorRef.markForCheck();
}
Expand Down Expand Up @@ -743,15 +738,6 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
}
}

/**
* When the panel content is done fading in, the _panelDoneAnimating property is
* set so the proper class can be added to the panel.
*/
_onFadeInDone(): void {
this._panelDoneAnimating = this.panelOpen;
this._changeDetectorRef.markForCheck();
}

_onFocus() {
if (!this.disabled) {
this._focused = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.example-panel-red .mat-select-content {
.example-panel-red .mat-select-panel {
background: rgba(255, 0, 0, 0.5);
}

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

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