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