@@ -141,7 +141,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
141
141
private _disableClear : boolean ;
142
142
143
143
constructor ( public _intl : MatSortHeaderIntl ,
144
- changeDetectorRef : ChangeDetectorRef ,
144
+ private _changeDetectorRef : ChangeDetectorRef ,
145
145
// `MatSort` is not optionally injected, but just asserted manually w/ better error.
146
146
// tslint:disable-next-line: lightweight-tokens
147
147
@Optional ( ) public _sort : MatSort ,
@@ -159,20 +159,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
159
159
throw getSortHeaderNotContainedWithinSortError ( ) ;
160
160
}
161
161
162
- this . _rerenderSubscription = merge ( _sort . sortChange , _sort . _stateChanges , _intl . changes )
163
- . subscribe ( ( ) => {
164
- if ( this . _isSorted ( ) ) {
165
- this . _updateArrowDirection ( ) ;
166
- }
167
-
168
- // If this header was recently active and now no longer sorted, animate away the arrow.
169
- if ( ! this . _isSorted ( ) && this . _viewState && this . _viewState . toState === 'active' ) {
170
- this . _disableViewStateAnimation = false ;
171
- this . _setAnimationTransitionState ( { fromState : 'active' , toState : this . _arrowDirection } ) ;
172
- }
173
-
174
- changeDetectorRef . markForCheck ( ) ;
175
- } ) ;
162
+ this . _handleStateChanges ( ) ;
176
163
}
177
164
178
165
ngOnInit ( ) {
@@ -238,27 +225,17 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
238
225
239
226
/** Triggers the sort on this sort header and removes the indicator hint. */
240
227
_toggleOnInteraction ( ) {
241
-
242
228
this . _sort . sort ( this ) ;
243
229
244
230
// Do not show the animation if the header was already shown in the right position.
245
231
if ( this . _viewState . toState === 'hint' || this . _viewState . toState === 'active' ) {
246
232
this . _disableViewStateAnimation = true ;
247
233
}
248
-
249
- // If the arrow is now sorted, animate the arrow into place. Otherwise, animate it away into
250
- // the direction it is facing.
251
- const viewState : ArrowViewStateTransition = this . _isSorted ( ) ?
252
- { fromState : this . _arrowDirection , toState : 'active' } :
253
- { fromState : 'active' , toState : this . _arrowDirection } ;
254
- this . _setAnimationTransitionState ( viewState ) ;
255
-
256
- this . _showIndicatorHint = false ;
257
234
}
258
235
259
236
_handleClick ( ) {
260
237
if ( ! this . _isDisabled ( ) ) {
261
- this . _toggleOnInteraction ( ) ;
238
+ this . _sort . sort ( this ) ;
262
239
}
263
240
}
264
241
@@ -325,6 +302,32 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
325
302
return ! this . _isDisabled ( ) || this . _isSorted ( ) ;
326
303
}
327
304
305
+ /** Handles changes in the sorting state. */
306
+ private _handleStateChanges ( ) {
307
+ this . _rerenderSubscription =
308
+ merge ( this . _sort . sortChange , this . _sort . _stateChanges , this . _intl . changes ) . subscribe ( ( ) => {
309
+ if ( this . _isSorted ( ) ) {
310
+ this . _updateArrowDirection ( ) ;
311
+
312
+ // Do not show the animation if the header was already shown in the right position.
313
+ if ( this . _viewState . toState === 'hint' || this . _viewState . toState === 'active' ) {
314
+ this . _disableViewStateAnimation = true ;
315
+ }
316
+
317
+ this . _setAnimationTransitionState ( { fromState : this . _arrowDirection , toState : 'active' } ) ;
318
+ this . _showIndicatorHint = false ;
319
+ }
320
+
321
+ // If this header was recently active and now no longer sorted, animate away the arrow.
322
+ if ( ! this . _isSorted ( ) && this . _viewState && this . _viewState . toState === 'active' ) {
323
+ this . _disableViewStateAnimation = false ;
324
+ this . _setAnimationTransitionState ( { fromState : 'active' , toState : this . _arrowDirection } ) ;
325
+ }
326
+
327
+ this . _changeDetectorRef . markForCheck ( ) ;
328
+ } ) ;
329
+ }
330
+
328
331
static ngAcceptInputType_disableClear : BooleanInput ;
329
332
static ngAcceptInputType_disabled : BooleanInput ;
330
333
}
0 commit comments