@@ -30,10 +30,18 @@ import {MatSort, MatSortable} from './sort';
3030import { MatSortHeaderIntl } from './sort-header-intl' ;
3131import { getSortHeaderNotContainedWithinSortError } from './sort-errors' ;
3232import { AnimationCurves , AnimationDurations } from '@angular/material/core' ;
33+ import { CanDisable , mixinDisabled } from '@angular/material/core' ;
34+
3335
3436const SORT_ANIMATION_TRANSITION =
3537 AnimationDurations . ENTERING + ' ' + AnimationCurves . STANDARD_CURVE ;
3638
39+ // Boilerplate for applying mixins to the sort header.
40+ /** @docs -private */
41+ export class MatSortHeaderBase { }
42+ export const _MatSortHeaderMixinBase = mixinDisabled ( MatSortHeaderBase ) ;
43+
44+
3745/**
3846 * Applies sorting behavior (click to change sort) and styles to an element, including an
3947 * arrow to display the current sort direction.
@@ -50,12 +58,14 @@ const SORT_ANIMATION_TRANSITION =
5058 templateUrl : 'sort-header.html' ,
5159 styleUrls : [ 'sort-header.css' ] ,
5260 host : {
53- '(click)' : '_sort.sort(this )' ,
61+ '(click)' : '_handleClick( )' ,
5462 '[class.mat-sort-header-sorted]' : '_isSorted()' ,
63+ '[class.mat-sort-header-disabled]' : '_isDisabled()' ,
5564 } ,
5665 encapsulation : ViewEncapsulation . None ,
5766 preserveWhitespaces : false ,
5867 changeDetection : ChangeDetectionStrategy . OnPush ,
68+ inputs : [ 'disabled' ] ,
5969 animations : [
6070 trigger ( 'indicator' , [
6171 state ( 'asc' , style ( { transform : 'translateY(0px)' } ) ) ,
@@ -93,7 +103,7 @@ const SORT_ANIMATION_TRANSITION =
93103 ] )
94104 ]
95105} )
96- export class MatSortHeader implements MatSortable {
106+ export class MatSortHeader extends _MatSortHeaderMixinBase implements MatSortable , CanDisable {
97107 private _rerenderSubscription : Subscription ;
98108
99109 /**
@@ -118,13 +128,15 @@ export class MatSortHeader implements MatSortable {
118128 changeDetectorRef : ChangeDetectorRef ,
119129 @Optional ( ) public _sort : MatSort ,
120130 @Optional ( ) public _cdkColumnDef : CdkColumnDef ) {
131+
132+ super ( ) ;
133+
121134 if ( ! _sort ) {
122135 throw getSortHeaderNotContainedWithinSortError ( ) ;
123136 }
124137
125- this . _rerenderSubscription = merge ( _sort . sortChange , _intl . changes ) . subscribe ( ( ) => {
126- changeDetectorRef . markForCheck ( ) ;
127- } ) ;
138+ this . _rerenderSubscription = merge ( _sort . sortChange , _sort . _stateChanges , _intl . changes )
139+ . subscribe ( ( ) => changeDetectorRef . markForCheck ( ) ) ;
128140 }
129141
130142 ngOnInit ( ) {
@@ -140,9 +152,20 @@ export class MatSortHeader implements MatSortable {
140152 this . _rerenderSubscription . unsubscribe ( ) ;
141153 }
142154
155+ /** Handles click events on the header. */
156+ _handleClick ( ) {
157+ if ( ! this . _isDisabled ( ) ) {
158+ this . _sort . sort ( this ) ;
159+ }
160+ }
161+
143162 /** Whether this MatSortHeader is currently sorted in either ascending or descending order. */
144163 _isSorted ( ) {
145164 return this . _sort . active == this . id &&
146165 ( this . _sort . direction === 'asc' || this . _sort . direction === 'desc' ) ;
147166 }
167+
168+ _isDisabled ( ) {
169+ return this . _sort . disabled || this . disabled ;
170+ }
148171}
0 commit comments