From 9474556259782f645bebb50054a05a9d96c8fb5d Mon Sep 17 00:00:00 2001 From: Dennis Duda Date: Tue, 3 Jul 2018 20:30:22 +0200 Subject: [PATCH 1/2] fix(select): Arrow position/animation for appearance="standard" (#11925) This commit aims to fix the arrow positioning of mat-selects with appearance="standard". Since the label moves down whenever the selected value is empty, the arrow looks out of place. I added an animation that matches the speed of the label animation: Going from filled to empty transitions the arrow down so that it sits level with the label. Going from empty to filled snaps the arrow back up, matching the label's behavior. To test/compare the different appearances I added another card to the demo-app with all of them. --- src/demo-app/select/select-demo.html | 53 ++++++++++++++++++++++++++++ src/lib/select/select-animations.ts | 13 +++++++ src/lib/select/select.html | 3 +- src/lib/select/select.scss | 5 ++- src/lib/select/select.ts | 3 +- 5 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/demo-app/select/select-demo.html b/src/demo-app/select/select-demo.html index f70788bb70b9..9e22fc2e096f 100644 --- a/src/demo-app/select/select-demo.html +++ b/src/demo-app/select/select-demo.html @@ -144,6 +144,59 @@ + + Appearance comparison + +

+ + Legacy + + None + + {{ creature.viewValue }} + + + +

+ +

+ + Standard + + None + + {{ creature.viewValue }} + + + +

+ +

+ + Fill + + None + + {{ creature.viewValue }} + + + +

+ +

+ + Outline + + None + + {{ creature.viewValue }} + + + +

+ +
+
formControl diff --git a/src/lib/select/select-animations.ts b/src/lib/select/select-animations.ts index f08e995c45fe..e11bcbe650d2 100644 --- a/src/lib/select/select-animations.ts +++ b/src/lib/select/select-animations.ts @@ -27,6 +27,7 @@ import { export const matSelectAnimations: { readonly transformPanel: AnimationTriggerMetadata; readonly fadeInContent: AnimationTriggerMetadata; + readonly transformArrow: AnimationTriggerMetadata; } = { /** * This animation transforms the select's overlay panel on and off the page. @@ -73,6 +74,18 @@ export const matSelectAnimations: { style({opacity: 0}), animate('150ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)') ]) + ]), + + /** + * This animation moves the panel toggle arrow up whenever the select is not empty to match the + * visual middle. This affects only mat-selects with appearance='standard'. + */ + transformArrow: trigger('transformArrow', [ + state('empty', style({})), + state('showing', style({transform: 'translateY(-50%)'})), + transition('showing => empty', [ + animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)') + ]) ]) }; diff --git a/src/lib/select/select.html b/src/lib/select/select.html index 4e9f6cf841a8..24b6f131bdad 100644 --- a/src/lib/select/select.html +++ b/src/lib/select/select.html @@ -12,7 +12,8 @@
-
+
Date: Sun, 8 Jul 2018 13:24:07 +0200 Subject: [PATCH 2/2] select-arrow: Replaced angular animation with simple css animation --- src/demo-app/select/select-demo.html | 94 ++++++++++++++-------------- src/demo-app/select/select-demo.ts | 5 ++ src/lib/select/select-animations.ts | 13 ---- src/lib/select/select.html | 3 +- src/lib/select/select.scss | 16 +++++ src/lib/select/select.ts | 4 +- 6 files changed, 72 insertions(+), 63 deletions(-) diff --git a/src/demo-app/select/select-demo.html b/src/demo-app/select/select-demo.html index 9e22fc2e096f..2b2cf07d1e1c 100644 --- a/src/demo-app/select/select-demo.html +++ b/src/demo-app/select/select-demo.html @@ -144,57 +144,59 @@ - + Appearance comparison + +

+ + Legacy + + None + + {{ creature.viewValue }} + + + +

-

- - Legacy - - None - - {{ creature.viewValue }} - - - -

- -

- - Standard - - None - - {{ creature.viewValue }} - - - -

+

+ + Standard + + None + + {{ creature.viewValue }} + + + +

-

- - Fill - - None - - {{ creature.viewValue }} - - - -

+

+ + Fill + + None + + {{ creature.viewValue }} + + + +

-

- - Outline - - None - - {{ creature.viewValue }} - - - -

+

+ + Outline + + None + + {{ creature.viewValue }} + + + +

+ +
diff --git a/src/demo-app/select/select-demo.ts b/src/demo-app/select/select-demo.ts index b399954f9b39..56f0305af7c5 100644 --- a/src/demo-app/select/select-demo.ts +++ b/src/demo-app/select/select-demo.ts @@ -29,6 +29,7 @@ export class SelectDemo { currentPokemon: string[]; currentPokemonFromGroup: string; currentDigimon: string; + currentAppearanceValue: string | null; latestChangeEvent: MatSelectChange; floatLabel = 'auto'; foodControl = new FormControl('pizza-1'); @@ -135,4 +136,8 @@ export class SelectDemo { compareByReference(o1: any, o2: any) { return o1 === o2; } + + toggleSelected() { + this.currentAppearanceValue = this.currentAppearanceValue ? null : this.digimon[0].value; + } } diff --git a/src/lib/select/select-animations.ts b/src/lib/select/select-animations.ts index e11bcbe650d2..f08e995c45fe 100644 --- a/src/lib/select/select-animations.ts +++ b/src/lib/select/select-animations.ts @@ -27,7 +27,6 @@ import { export const matSelectAnimations: { readonly transformPanel: AnimationTriggerMetadata; readonly fadeInContent: AnimationTriggerMetadata; - readonly transformArrow: AnimationTriggerMetadata; } = { /** * This animation transforms the select's overlay panel on and off the page. @@ -74,18 +73,6 @@ export const matSelectAnimations: { style({opacity: 0}), animate('150ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)') ]) - ]), - - /** - * This animation moves the panel toggle arrow up whenever the select is not empty to match the - * visual middle. This affects only mat-selects with appearance='standard'. - */ - transformArrow: trigger('transformArrow', [ - state('empty', style({})), - state('showing', style({transform: 'translateY(-50%)'})), - transition('showing => empty', [ - animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)') - ]) ]) }; diff --git a/src/lib/select/select.html b/src/lib/select/select.html index 24b6f131bdad..4e9f6cf841a8 100644 --- a/src/lib/select/select.html +++ b/src/lib/select/select.html @@ -12,8 +12,7 @@
-
+