Skip to content

fix(menu): align appearance with spec #5361

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
Jul 14, 2017
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: 2 additions & 2 deletions src/lib/autocomplete/autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ $mat-autocomplete-panel-below-offset: 6px !default;
$mat-autocomplete-panel-above-offset: -24px !default;

.mat-autocomplete-panel {
@include mat-menu-base();
@include mat-menu-base(8);
visibility: hidden;

max-width: none;
max-height: $mat-autocomplete-panel-max-height;
position: relative;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/style/_menu-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ $mat-menu-side-padding: 16px !default;
$mat-menu-icon-margin: 16px !default;


@mixin mat-menu-base() {
@include mat-elevation(8);
@mixin mat-menu-base($elevation) {
@include mat-elevation($elevation);
min-width: $mat-menu-overlay-min-width;
max-width: $mat-menu-overlay-max-width;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/menu/_menu-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$background: map-get($theme, background);
$foreground: map-get($theme, foreground);

.mat-menu-content {
.mat-menu-panel {
background: mat-color($background, 'card');
}

Expand Down
27 changes: 14 additions & 13 deletions src/lib/menu/menu-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ import{

// TODO(kara): switch to :enter and :leave once Mobile Safari is sorted out.
export const transformMenu: AnimationTriggerMetadata = trigger('transformMenu', [
state('showing', style({
state('void', style({
opacity: 0,
transform: 'scale(0, 0)'
})),
state('enter-start', style({
opacity: 1,
transform: `scale(1)`
transform: `scale(1, 0.5)`
})),
transition('void => *', [
style({
opacity: 0,
transform: `scale(0)`
}),
animate(`200ms cubic-bezier(0.25, 0.8, 0.25, 1)`)
]),
transition('* => void', [
animate('50ms 100ms linear', style({opacity: 0}))
])
state('enter', style({
transform: 'scale(1, 1)'
})),
transition('void => enter-start', animate('100ms linear')),
transition('enter-start => enter', animate('300ms cubic-bezier(0.25, 0.8, 0.25, 1)')),
transition('* => void', animate('150ms 50ms linear', style({opacity: 0})))
]);


/**
* This animation fades in the background color and content of the menu panel
* after its containing element is scaled in.
Expand All @@ -56,6 +57,6 @@ export const fadeInItems: AnimationTriggerMetadata = trigger('fadeInItems', [
state('showing', style({opacity: 1})),
transition('void => *', [
style({opacity: 0}),
animate(`200ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)`)
animate(`400ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)`)
])
]);
21 changes: 21 additions & 0 deletions src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ViewEncapsulation,
ElementRef,
} from '@angular/core';
import {AnimationEvent} from '@angular/animations';
import {MenuPositionX, MenuPositionY} from './menu-positions';
import {throwMdMenuInvalidPositionX, throwMdMenuInvalidPositionY} from './menu-errors';
import {MdMenuItem} from './menu-item';
Expand Down Expand Up @@ -53,6 +54,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
/** Config object to be passed into the menu's ngClass */
_classList: any = {};

/** Current state of the panel animation. */
_panelAnimationState: 'void' | 'enter-start' | 'enter' = 'void';

/** Position of the menu in the X axis. */
@Input()
get xPosition() { return this._xPosition; }
Expand Down Expand Up @@ -156,4 +160,21 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
this._classList['mat-menu-below'] = posY === 'below';
}

/** Starts the enter animation. */
_startAnimation() {
this._panelAnimationState = 'enter-start';
}

/** Resets the panel animation to its initial state. */
_resetAnimation() {
this._panelAnimationState = 'void';
}

/** Callback that is invoked when the panel animation completes. */
_onAnimationDone(event: AnimationEvent) {
// After the initial expansion is done, trigger the second phase of the enter animation.
if (event.toState === 'enter-start') {
this._panelAnimationState = 'enter';
}
}
}
9 changes: 9 additions & 0 deletions src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '../core';
import {Subscription} from 'rxjs/Subscription';
import {MenuPositionX, MenuPositionY} from './menu-positions';
import {MdMenu} from './menu-directive';

// TODO(andrewseguin): Remove the kebab versions in favor of camelCased attribute selectors

Expand Down Expand Up @@ -110,6 +111,10 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
this._createOverlay().attach(this._portal);
this._subscribeToBackdrop();
this._initMenu();

if (this.menu instanceof MdMenu) {
this.menu._startAnimation();
}
}
}

Expand All @@ -119,6 +124,10 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
this._overlayRef.detach();
this._backdropSubscription.unsubscribe();
this._resetMenu();

if (this.menu instanceof MdMenu) {
this.menu._resetAnimation();
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/lib/menu/menu.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<ng-template>
<div class="mat-menu-panel" [ngClass]="_classList" (keydown)="_handleKeydown($event)"
(click)="_emitCloseEvent()" [@transformMenu]="'showing'" role="menu">
<div
class="mat-menu-panel"
[ngClass]="_classList"
(keydown)="_handleKeydown($event)"
(click)="_emitCloseEvent()"
[@transformMenu]="_panelAnimationState"
(@transformMenu.done)="_onAnimationDone($event)"
role="menu">
<div class="mat-menu-content" [@fadeInItems]="'showing'">
<ng-content></ng-content>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/menu/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
@import '../core/a11y/a11y';

$mat-menu-vertical-padding: 8px !default;
$mat-menu-border-radius: 2px !default;

.mat-menu-panel {
@include mat-menu-base();
@include mat-menu-base(2);
Copy link
Contributor

@kara kara Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment clarifying where this elevation number comes from? I couldn't find any guidance in the spec.

Copy link
Member Author

@crisbeto crisbeto Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nowhere in the spec, this one looked closest to the designs.

@include mat-menu-positions();
max-height: calc(100vh - #{$mat-menu-item-height});
border-radius: $mat-menu-border-radius;

@include cdk-high-contrast {
outline: solid 1px;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ $mat-select-panel-max-height: 256px !default;
}

.mat-select-panel {
@include mat-menu-base();
@include mat-menu-base(8);
padding-top: 0;
padding-bottom: 0;
max-height: $mat-select-panel-max-height;
Expand Down