@@ -139,7 +139,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
139
139
private _disableClear : boolean ;
140
140
141
141
constructor ( public _intl : MatSortHeaderIntl ,
142
- changeDetectorRef : ChangeDetectorRef ,
142
+ private _changeDetectorRef : ChangeDetectorRef ,
143
143
@Optional ( ) public _sort : MatSort ,
144
144
@Inject ( 'MAT_SORT_HEADER_COLUMN_DEF' ) @Optional ( )
145
145
public _columnDef : MatSortHeaderColumnDef ,
@@ -155,20 +155,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
155
155
throw getSortHeaderNotContainedWithinSortError ( ) ;
156
156
}
157
157
158
- this . _rerenderSubscription = merge ( _sort . sortChange , _sort . _stateChanges , _intl . changes )
159
- . subscribe ( ( ) => {
160
- if ( this . _isSorted ( ) ) {
161
- this . _updateArrowDirection ( ) ;
162
- }
163
-
164
- // If this header was recently active and now no longer sorted, animate away the arrow.
165
- if ( ! this . _isSorted ( ) && this . _viewState && this . _viewState . toState === 'active' ) {
166
- this . _disableViewStateAnimation = false ;
167
- this . _setAnimationTransitionState ( { fromState : 'active' , toState : this . _arrowDirection } ) ;
168
- }
169
-
170
- changeDetectorRef . markForCheck ( ) ;
171
- } ) ;
158
+ this . _handleStateChanges ( ) ;
172
159
}
173
160
174
161
ngOnInit ( ) {
@@ -234,23 +221,9 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
234
221
235
222
/** Triggers the sort on this sort header and removes the indicator hint. */
236
223
_handleClick ( ) {
237
- if ( this . _isDisabled ( ) ) { return ; }
238
-
239
- this . _sort . sort ( this ) ;
240
-
241
- // Do not show the animation if the header was already shown in the right position.
242
- if ( this . _viewState . toState === 'hint' || this . _viewState . toState === 'active' ) {
243
- this . _disableViewStateAnimation = true ;
224
+ if ( ! this . _isDisabled ( ) ) {
225
+ this . _sort . sort ( this ) ;
244
226
}
245
-
246
- // If the arrow is now sorted, animate the arrow into place. Otherwise, animate it away into
247
- // the direction it is facing.
248
- const viewState : ArrowViewStateTransition = this . _isSorted ( ) ?
249
- { fromState : this . _arrowDirection , toState : 'active' } :
250
- { fromState : 'active' , toState : this . _arrowDirection } ;
251
- this . _setAnimationTransitionState ( viewState ) ;
252
-
253
- this . _showIndicatorHint = false ;
254
227
}
255
228
256
229
/** Whether this MatSortHeader is currently sorted in either ascending or descending order. */
@@ -307,6 +280,32 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
307
280
return ! this . _isDisabled ( ) || this . _isSorted ( ) ;
308
281
}
309
282
283
+ /** Handles changes in the sorting state. */
284
+ private _handleStateChanges ( ) {
285
+ this . _rerenderSubscription =
286
+ merge ( this . _sort . sortChange , this . _sort . _stateChanges , this . _intl . changes ) . subscribe ( ( ) => {
287
+ if ( this . _isSorted ( ) ) {
288
+ this . _updateArrowDirection ( ) ;
289
+
290
+ // Do not show the animation if the header was already shown in the right position.
291
+ if ( this . _viewState . toState === 'hint' || this . _viewState . toState === 'active' ) {
292
+ this . _disableViewStateAnimation = true ;
293
+ }
294
+
295
+ this . _setAnimationTransitionState ( { fromState : this . _arrowDirection , toState : 'active' } ) ;
296
+ this . _showIndicatorHint = false ;
297
+ }
298
+
299
+ // If this header was recently active and now no longer sorted, animate away the arrow.
300
+ if ( ! this . _isSorted ( ) && this . _viewState && this . _viewState . toState === 'active' ) {
301
+ this . _disableViewStateAnimation = false ;
302
+ this . _setAnimationTransitionState ( { fromState : 'active' , toState : this . _arrowDirection } ) ;
303
+ }
304
+
305
+ this . _changeDetectorRef . markForCheck ( ) ;
306
+ } ) ;
307
+ }
308
+
310
309
static ngAcceptInputType_disableClear : BooleanInput ;
311
310
static ngAcceptInputType_disabled : BooleanInput ;
312
311
}
0 commit comments