@@ -30,11 +30,9 @@ import {
30
30
ViewEncapsulation ,
31
31
} from '@angular/core' ;
32
32
import {
33
- CanDisable ,
34
33
CanDisableRipple ,
35
34
MatLine ,
36
35
MatLineSetter ,
37
- mixinDisabled ,
38
36
mixinDisableRipple ,
39
37
} from '@angular/material/core' ;
40
38
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
@@ -43,7 +41,7 @@ import {Subscription} from 'rxjs';
43
41
44
42
/** @docs -private */
45
43
export class MatSelectionListBase { }
46
- export const _MatSelectionListMixinBase = mixinDisableRipple ( mixinDisabled ( MatSelectionListBase ) ) ;
44
+ export const _MatSelectionListMixinBase = mixinDisableRipple ( MatSelectionListBase ) ;
47
45
48
46
/** @docs -private */
49
47
export class MatListOptionBase { }
@@ -238,6 +236,15 @@ export class MatListOption extends _MatListOptionMixinBase
238
236
this . _changeDetector . markForCheck ( ) ;
239
237
return true ;
240
238
}
239
+
240
+ /**
241
+ * Notifies Angular that the option needs to be checked in the next change detection run. Mainly
242
+ * used to trigger an update of the list option if the disabled state of the selection list
243
+ * changed.
244
+ */
245
+ _markForCheck ( ) {
246
+ this . _changeDetector . markForCheck ( ) ;
247
+ }
241
248
}
242
249
243
250
@@ -265,7 +272,7 @@ export class MatListOption extends _MatListOptionMixinBase
265
272
changeDetection : ChangeDetectionStrategy . OnPush
266
273
} )
267
274
export class MatSelectionList extends _MatSelectionListMixinBase implements FocusableOption ,
268
- CanDisable , CanDisableRipple , AfterContentInit , ControlValueAccessor , OnDestroy {
275
+ CanDisableRipple , AfterContentInit , ControlValueAccessor , OnDestroy {
269
276
270
277
/** The FocusKeyManager which handles focus. */
271
278
_keyManager : FocusKeyManager < MatListOption > ;
@@ -287,6 +294,22 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
287
294
*/
288
295
@Input ( ) compareWith : ( o1 : any , o2 : any ) => boolean ;
289
296
297
+ /** Whether the selection list is disabled. */
298
+ @Input ( )
299
+ get disabled ( ) : boolean { return this . _disabled ; }
300
+ set disabled ( value : boolean ) {
301
+ this . _disabled = coerceBooleanProperty ( value ) ;
302
+
303
+ // The `MatSelectionList` and `MatListOption` are using the `OnPush` change detection
304
+ // strategy. Therefore the options will not check for any changes if the `MatSelectionList`
305
+ // changed its state. Since we know that a change to `disabled` property of the list affects
306
+ // the state of the options, we manually mark each option for check.
307
+ if ( this . options ) {
308
+ this . options . forEach ( option => option . _markForCheck ( ) ) ;
309
+ }
310
+ }
311
+ private _disabled : boolean = false ;
312
+
290
313
/** The currently selected options. */
291
314
selectedOptions : SelectionModel < MatListOption > = new SelectionModel < MatListOption > ( true ) ;
292
315
@@ -296,6 +319,7 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
296
319
/** Used for storing the values that were assigned before the options were initialized. */
297
320
private _tempValues : string [ ] | null ;
298
321
322
+ /** Subscription to sync value changes in the SelectionModel back to the SelectionList. */
299
323
private _modelChanges = Subscription . EMPTY ;
300
324
301
325
/** View to model callback that should be called if the list or its options lost focus. */
0 commit comments