Skip to content

Commit 70bd5fc

Browse files
yhorbachovjelbourn
authored andcommitted
feat(sort): add sorting indicator animation (#5831)
1 parent 950edcc commit 70bd5fc

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/lib/sort/sort-header.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
<div *ngIf="_isSorted()"
99
class="mat-sort-header-arrow"
10-
[class.mat-sort-header-asc]="_sort.direction == 'asc'"
11-
[class.mat-sort-header-desc]="_sort.direction == 'desc'">
10+
[@indicatorRotate]="_sort.direction">
1211
<div class="mat-sort-header-stem"></div>
1312
<div class="mat-sort-header-pointer-left"></div>
1413
<div class="mat-sort-header-pointer-right"></div>

src/lib/sort/sort-header.scss

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,17 @@ $mat-sort-header-arrow-thickness: 2px;
2525
}
2626

2727
.mat-sort-header-arrow {
28-
display: none;
2928
height: $mat-sort-header-arrow-container-size;
3029
width: $mat-sort-header-arrow-container-size;
3130
position: relative;
3231
margin: 0 0 0 $mat-sort-header-arrow-margin;
32+
transform: rotate(45deg);
3333

3434
.mat-sort-header-position-before & {
3535
margin: 0 $mat-sort-header-arrow-margin 0 0;
3636
}
3737
}
3838

39-
.mat-sort-header-asc {
40-
display: block;
41-
transform: rotate(45deg);
42-
}
43-
44-
.mat-sort-header-desc {
45-
display: block;
46-
transform: rotate(225deg);
47-
top: $mat-sort-header-arrow-thickness;
48-
}
49-
5039
.mat-sort-header-stem {
5140
background: currentColor;
5241
transform: rotate(135deg);

src/lib/sort/sort-header.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ import {
1515
ViewEncapsulation
1616
} from '@angular/core';
1717
import {coerceBooleanProperty} from '@angular/cdk/coercion';
18+
import {
19+
trigger,
20+
state,
21+
style,
22+
animate,
23+
transition
24+
} from '@angular/animations';
1825
import {CdkColumnDef} from '@angular/cdk/table';
1926
import {Subscription} from 'rxjs/Subscription';
2027
import {merge} from 'rxjs/observable/merge';
2128
import {MdSort, MdSortable} from './sort';
2229
import {MdSortHeaderIntl} from './sort-header-intl';
2330
import {getMdSortHeaderNotContainedWithinMdSortError} from './sort-errors';
2431

32+
2533
/**
2634
* Applies sorting behavior (click to change sort) and styles to an element, including an
2735
* arrow to display the current sort direction.
@@ -42,6 +50,13 @@ import {getMdSortHeaderNotContainedWithinMdSortError} from './sort-errors';
4250
},
4351
encapsulation: ViewEncapsulation.None,
4452
changeDetection: ChangeDetectionStrategy.OnPush,
53+
animations: [
54+
trigger('indicatorRotate', [
55+
state('asc', style({transform: 'rotate(45deg)'})),
56+
state('desc', style({transform: 'rotate(225deg)'})),
57+
transition('asc <=> desc', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)'))
58+
])
59+
]
4560
})
4661
export class MdSortHeader implements MdSortable {
4762
private _rerenderSubscription: Subscription;

src/lib/sort/sort.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing';
22
import {Component, ElementRef, ViewChild} from '@angular/core';
33
import {By} from '@angular/platform-browser';
4+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
45
import {MdSort, MdSortHeader, Sort, SortDirection, MdSortModule, MdSortHeaderIntl} from './index';
56
import {DataSource, CollectionViewer} from '@angular/cdk/collections';
67
import {CdkTableModule} from '@angular/cdk/table';
@@ -21,7 +22,7 @@ describe('MdSort', () => {
2122

2223
beforeEach(async(() => {
2324
TestBed.configureTestingModule({
24-
imports: [MdSortModule, MdTableModule, CdkTableModule],
25+
imports: [MdSortModule, MdTableModule, CdkTableModule, NoopAnimationsModule],
2526
declarations: [
2627
SimpleMdSortApp,
2728
CdkTableMdSortApp,

0 commit comments

Comments
 (0)