Skip to content

fix(select): Arrow position/animation for appearance="standard" #12045

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 2 commits into from
Aug 23, 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
55 changes: 55 additions & 0 deletions src/demo-app/select/select-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,61 @@
</mat-card-content>
</mat-card>

<mat-card>
<mat-card-subtitle>Appearance comparison</mat-card-subtitle>
<mat-card-content>
<p>
<mat-form-field>
<mat-label>Legacy</mat-label>
<mat-select [(value)]="currentAppearanceValue">
<mat-option>None</mat-option>
<mat-option *ngFor="let creature of digimon" [value]="creature.value">
{{ creature.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
</p>

<p>
<mat-form-field appearance="standard">
<mat-label>Standard</mat-label>
<mat-select [(value)]="currentAppearanceValue">
<mat-option>None</mat-option>
<mat-option *ngFor="let creature of digimon" [value]="creature.value">
{{ creature.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
</p>

<p>
<mat-form-field appearance="fill">
<mat-label>Fill</mat-label>
<mat-select [(value)]="currentAppearanceValue">
<mat-option>None</mat-option>
<mat-option *ngFor="let creature of digimon" [value]="creature.value">
{{ creature.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
</p>

<p>
<mat-form-field appearance="outline">
<mat-label>Outline</mat-label>
<mat-select [(value)]="currentAppearanceValue">
<mat-option>None</mat-option>
<mat-option *ngFor="let creature of digimon" [value]="creature.value">
{{ creature.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
</p>

<button mat-button (click)="toggleSelected()">TOGGLE SELECTED</button>
</mat-card-content>
</mat-card>

<div *ngIf="showSelect">
<mat-card>
<mat-card-subtitle>formControl</mat-card-subtitle>
Expand Down
5 changes: 5 additions & 0 deletions src/demo-app/select/select-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
}
21 changes: 18 additions & 3 deletions src/lib/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,31 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
display: table-cell;
vertical-align: middle;

// When used in a box or standard appearance form-field the arrow should be shifted up 50%.
.mat-form-field-appearance-fill &,
.mat-form-field-appearance-standard & {
// When used in a box appearance form-field the arrow should be shifted up 50%.
.mat-form-field-appearance-fill & {
transform: translateY(-50%);
}

// When used in a outline form-field the arrow should be shifted up 25%.
.mat-form-field-appearance-outline & {
transform: translateY(-25%);
}

// When used in a standard appearance form-field the arrow should be shifted up 50%,
// but only if it's not empty
.mat-form-field-appearance-standard .mat-select:not(.mat-select-empty) & {
transform: translateY(-50%);
}

// Animate the arrow position, but only when the transitioning to empty (animate the arrow down)
// This is in line with the mat-form-field label animation
.mat-form-field-appearance-standard .mat-select.mat-select-empty & {
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function;
}

._mat-animation-noopable.mat-form-field-appearance-standard .mat-select.mat-select-empty & {
transition: none;
}
}

.mat-select-arrow {
Expand Down
1 change: 1 addition & 0 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class MatSelectTrigger {}
'[class.mat-select-disabled]': 'disabled',
'[class.mat-select-invalid]': 'errorState',
'[class.mat-select-required]': 'required',
'[class.mat-select-empty]': 'empty',
Copy link
Contributor

Choose a reason for hiding this comment

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

iirc, form-field has an empty class that you can probably use instead of adding a new one here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, just checked this out, but the .mat-form-field-empty is only set on the floating label, not the mat-form-field itself. What would be the best change @mmalerba?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok, in that case we can just leave it as is

'class': 'mat-select',
'(keydown)': '_handleKeydown($event)',
'(focus)': '_onFocus()',
Expand Down