@@ -30,10 +30,18 @@ import {MatSort, MatSortable} from './sort';
30
30
import { MatSortHeaderIntl } from './sort-header-intl' ;
31
31
import { getSortHeaderNotContainedWithinSortError } from './sort-errors' ;
32
32
import { AnimationCurves , AnimationDurations } from '@angular/material/core' ;
33
+ import { CanDisable , mixinDisabled } from '@angular/material/core' ;
34
+
33
35
34
36
const SORT_ANIMATION_TRANSITION =
35
37
AnimationDurations . ENTERING + ' ' + AnimationCurves . STANDARD_CURVE ;
36
38
39
+ // Boilerplate for applying mixins to the sort header.
40
+ /** @docs -private */
41
+ export class MatSortHeaderBase { }
42
+ export const _MatSortHeaderMixinBase = mixinDisabled ( MatSortHeaderBase ) ;
43
+
44
+
37
45
/**
38
46
* Applies sorting behavior (click to change sort) and styles to an element, including an
39
47
* arrow to display the current sort direction.
@@ -50,12 +58,14 @@ const SORT_ANIMATION_TRANSITION =
50
58
templateUrl : 'sort-header.html' ,
51
59
styleUrls : [ 'sort-header.css' ] ,
52
60
host : {
53
- '(click)' : '_sort.sort(this )' ,
61
+ '(click)' : '_handleClick( )' ,
54
62
'[class.mat-sort-header-sorted]' : '_isSorted()' ,
63
+ '[class.mat-sort-header-disabled]' : '_isDisabled()' ,
55
64
} ,
56
65
encapsulation : ViewEncapsulation . None ,
57
66
preserveWhitespaces : false ,
58
67
changeDetection : ChangeDetectionStrategy . OnPush ,
68
+ inputs : [ 'disabled' ] ,
59
69
animations : [
60
70
trigger ( 'indicator' , [
61
71
state ( 'asc' , style ( { transform : 'translateY(0px)' } ) ) ,
@@ -93,7 +103,7 @@ const SORT_ANIMATION_TRANSITION =
93
103
] )
94
104
]
95
105
} )
96
- export class MatSortHeader implements MatSortable {
106
+ export class MatSortHeader extends _MatSortHeaderMixinBase implements MatSortable , CanDisable {
97
107
private _rerenderSubscription : Subscription ;
98
108
99
109
/**
@@ -118,13 +128,15 @@ export class MatSortHeader implements MatSortable {
118
128
changeDetectorRef : ChangeDetectorRef ,
119
129
@Optional ( ) public _sort : MatSort ,
120
130
@Optional ( ) public _cdkColumnDef : CdkColumnDef ) {
131
+
132
+ super ( ) ;
133
+
121
134
if ( ! _sort ) {
122
135
throw getSortHeaderNotContainedWithinSortError ( ) ;
123
136
}
124
137
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 ( ) ) ;
128
140
}
129
141
130
142
ngOnInit ( ) {
@@ -140,9 +152,20 @@ export class MatSortHeader implements MatSortable {
140
152
this . _rerenderSubscription . unsubscribe ( ) ;
141
153
}
142
154
155
+ /** Handles click events on the header. */
156
+ _handleClick ( ) {
157
+ if ( ! this . _isDisabled ( ) ) {
158
+ this . _sort . sort ( this ) ;
159
+ }
160
+ }
161
+
143
162
/** Whether this MatSortHeader is currently sorted in either ascending or descending order. */
144
163
_isSorted ( ) {
145
164
return this . _sort . active == this . id &&
146
165
( this . _sort . direction === 'asc' || this . _sort . direction === 'desc' ) ;
147
166
}
167
+
168
+ _isDisabled ( ) {
169
+ return this . _sort . disabled || this . disabled ;
170
+ }
148
171
}
0 commit comments