@@ -72,65 +72,40 @@ const SORT_ANIMATION_TRANSITION =
72
72
transition ( 'active-asc <=> active-desc' , animate ( SORT_ANIMATION_TRANSITION ) )
73
73
] ) ,
74
74
75
+ // Arrow opacity
76
+ trigger ( 'arrowOpacity' , [
77
+ state ( 'desc-to-active, asc-to-active, active' , style ( { opacity : 1 } ) ) ,
78
+ state ( 'desc-to-peek, asc-to-peek, peek' , style ( { opacity : .54 } ) ) ,
79
+ state ( 'peek-to-desc, active-to-desc, desc, peek-to-asc, active-to-asc, asc' , style ( { opacity : 0 } ) ) ,
80
+ transition ( '* => asc, * => desc, * => active, * => peek' , animate ( '0ms' ) ) ,
81
+ transition ( '* <=> *' , animate ( SORT_ANIMATION_TRANSITION ) )
82
+ ] ) ,
83
+
75
84
// Arrow position (translation)
76
85
trigger ( 'arrowPosition' , [
77
86
// Hidden Above => Peek Center
78
- transition ( '* => desc-to-peek' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
79
- style ( { transform : 'translateY(-25%)' , opacity : 0 } ) ,
80
- style ( { transform : 'translateY(0)' , opacity : .54 } )
87
+ transition ( '* => desc-to-peek, * => desc-to-active ' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
88
+ style ( { transform : 'translateY(-25%)' } ) ,
89
+ style ( { transform : 'translateY(0)' } )
81
90
] ) ) ) ,
82
91
// Peek Center => Hidden Below
83
- transition ( '* => peek-to-desc' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
84
- style ( { transform : 'translateY(0)' , opacity : .54 } ) ,
85
- style ( { transform : 'translateY(25%)' , opacity : 0 } )
92
+ transition ( '* => peek-to-desc, * => active-to-desc ' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
93
+ style ( { transform : 'translateY(0)' } ) ,
94
+ style ( { transform : 'translateY(25%)' } )
86
95
] ) ) ) ,
87
96
// Hidden Below => Peek Center
88
- transition ( '* => asc-to-peek' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
89
- style ( { transform : 'translateY(25%)' , opacity : 0 } ) ,
90
- style ( { transform : 'translateY(0)' , opacity : .54 } )
97
+ transition ( '* => asc-to-peek, * => asc-to-active ' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
98
+ style ( { transform : 'translateY(25%)' } ) ,
99
+ style ( { transform : 'translateY(0)' } )
91
100
] ) ) ) ,
92
101
// Peek Center => Hidden Above
93
- transition ( 'active-to-desc => peek-to-asc' , animate ( '0ms' ) ) ,
94
- transition ( '* => peek-to-asc' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
95
- style ( { transform : 'translateY(0)' , opacity : .54 } ) ,
96
- style ( { transform : 'translateY(-25%)' , opacity : 0 } )
97
- ] ) ) ) ,
98
- state ( 'desc-to-peek, asc-to-peek, peek' , style ( { transform : 'translateY(0)' , opacity : .54 } ) ) ,
99
- state ( 'peek-to-desc, active-to-desc, desc' , style ( { transform : 'translateY(-25%)' , opacity : 0 } ) ) ,
100
- state ( 'peek-to-asc, active-to-asc, asc' , style ( { transform : 'translateY(25%)' , opacity : 0 } ) ) ,
101
-
102
- // Hidden Above => Active Center
103
- transition ( 'peek => desc-to-active' , animate ( '0ms' ) ) ,
104
- transition ( 'active => desc-to-active' , animate ( '0ms' ) ) ,
105
- transition ( 'asc-to-peek => desc-to-active' , animate ( '0ms' ) ) ,
106
- transition ( 'desc-to-peek => desc-to-active' , animate ( '0ms' ) ) ,
107
- transition ( 'asc-to-active => desc-to-active' , animate ( '0ms' ) ) ,
108
- transition ( '* => desc-to-active' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
109
- style ( { transform : 'translateY(-25%)' , opacity : 0 } ) ,
110
- style ( { transform : 'translateY(0)' , opacity : 1 } )
111
- ] ) ) ) ,
112
- // Active Center => Hidden Below
113
- transition ( 'desc => active-to-desc' , animate ( '0ms' ) ) ,
114
- transition ( 'peek-to-desc => active-to-desc' , animate ( '0ms' ) ) ,
115
- transition ( '* => active-to-desc' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
116
- style ( { transform : 'translateY(0)' , opacity : 1 } ) ,
117
- style ( { transform : 'translateY(25%)' , opacity : 0 } )
102
+ transition ( '* => peek-to-asc, * => active-to-asc' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
103
+ style ( { transform : 'translateY(0)' } ) ,
104
+ style ( { transform : 'translateY(-25%)' } )
118
105
] ) ) ) ,
119
- // Hidden Below => Active Center
120
- transition ( 'peek => asc-to-active' , animate ( '0ms' ) ) ,
121
- transition ( 'active => asc-to-active' , animate ( '0ms' ) ) ,
122
- transition ( 'asc-to-peek => asc-to-active' , animate ( '0ms' ) ) ,
123
- transition ( 'desc-to-peek => asc-to-active' , animate ( '0ms' ) ) ,
124
- transition ( '* => asc-to-active' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
125
- style ( { transform : 'translateY(25%)' , opacity : 0 } ) ,
126
- style ( { transform : 'translateY(0)' , opacity : 1 } )
127
- ] ) ) ) ,
128
- // Active Center => Hidden Above
129
- transition ( '* => active-to-asc' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
130
- style ( { transform : 'translateY(0)' , opacity : 1 } ) ,
131
- style ( { transform : 'translateY(-25%)' , opacity : 0 } )
132
- ] ) ) ) ,
133
- state ( 'desc-to-active, asc-to-active, active' , style ( { transform : 'translateY(0)' , opacity : 1 } ) ) ,
106
+ state ( 'desc-to-peek, asc-to-peek, peek, desc-to-active, asc-to-active, active' , style ( { transform : 'translateY(0)' } ) ) ,
107
+ state ( 'peek-to-desc, active-to-desc, desc' , style ( { transform : 'translateY(-25%)' } ) ) ,
108
+ state ( 'peek-to-asc, active-to-asc, asc' , style ( { transform : 'translateY(25%)' } ) ) ,
134
109
] )
135
110
]
136
111
} )
@@ -189,16 +164,26 @@ export class MatSortHeader implements MatSortable {
189
164
this . _rerenderSubscription = merge ( _sort . sortChange , _intl . changes ) . subscribe ( ( ) => {
190
165
if ( this . _isSorted ( ) ) {
191
166
this . _updateArrowDirection ( ) ;
167
+ } if ( ! this . _isSorted ( ) ) {
168
+ const activeStates = [ 'active' , 'asc-to-active' , 'desc-to-active' ] ;
169
+ const isActive = activeStates . indexOf ( this . trigger ) != - 1 ;
170
+ if ( isActive ) {
171
+ this . _updateTrigger ( false , 'active' ) ;
172
+ }
192
173
}
193
174
175
+
194
176
changeDetectorRef . markForCheck ( ) ;
195
177
} ) ;
196
178
}
197
179
198
- _updateTrigger ( enter : boolean , source : string ) {
199
- const startState = enter ? this . _arrowDirection : source ;
200
- const endState = enter ? source : this . _arrowDirection ;
201
- this . trigger = this . animating ? endState : `${ startState } -to-${ endState } ` ;
180
+ _updateTrigger ( enter : boolean , source : string , disableAnimation ?: boolean ) {
181
+ const states = enter ?
182
+ [ this . _arrowDirection , source ] :
183
+ [ source , this . _arrowDirection ] ;
184
+
185
+ disableAnimation = disableAnimation || this . animating ;
186
+ this . trigger = disableAnimation ? states [ 1 ] : `${ states [ 0 ] } -to-${ states [ 1 ] } ` ;
202
187
console . log ( this . trigger ) ;
203
188
}
204
189
@@ -231,42 +216,10 @@ export class MatSortHeader implements MatSortable {
231
216
this . _rerenderSubscription . unsubscribe ( ) ;
232
217
}
233
218
234
- _getArrowDisplayState ( ) {
235
- let displayState = 'hidden' ;
236
-
237
- if ( this . _showIndicatorHint ) {
238
- displayState = 'hint' ;
239
- }
240
-
241
- if ( this . _isSorted ( ) ) {
242
- displayState = 'active' ;
243
- }
244
-
245
- return displayState ;
246
- }
247
-
248
- /**
249
- * Returns the direction that the indicator should be pointing. If it is sorted, then it should
250
- * point in the direction of the current sort. Otherwise it should point towards the first sort
251
- * direction.
252
- */
253
- _getArrowPosition ( ) {
254
- return `${ this . _getArrowDisplayState ( ) } -${ this . _arrowDirection } ` ;
255
- }
256
-
257
219
_getArrowDirection ( ) {
258
220
return `${ this . _isSorted ( ) ? 'active-' : '' } ${ this . _arrowDirection } ` ;
259
221
}
260
222
261
- /**
262
- * Returns the direction that the indicator should be pointing. If it is sorted, then it should
263
- * point in the direction of the current sort. Otherwise it should point towards the first sort
264
- * direction.
265
- */
266
- _getArrowPosition2 ( ) {
267
- return ( this . showIndicatorHint || this . _isSorted ( ) ) ? 'center' : this . _arrowDirection ;
268
- }
269
-
270
223
_updateArrowDirection ( ) {
271
224
this . _arrowDirection = this . start || this . _sort . start ;
272
225
@@ -278,9 +231,11 @@ export class MatSortHeader implements MatSortable {
278
231
279
232
/** Triggers the sort on this sort header and removes the indicator hint. */
280
233
_handleClick ( ) {
234
+ let arrowDisplayed = this . showIndicatorHint || this . _isSorted ( ) ;
235
+
281
236
this . _sort . sort ( this ) ;
282
237
283
- this . _updateTrigger ( this . _isSorted ( ) , 'active' ) ;
238
+ this . _updateTrigger ( this . _isSorted ( ) , 'active' , arrowDisplayed && this . _isSorted ( ) ) ;
284
239
285
240
this . _showIndicatorHint = false ;
286
241
}
0 commit comments