8
8
9
9
import {
10
10
AfterContentInit ,
11
+ booleanAttribute ,
11
12
ChangeDetectorRef ,
12
13
ContentChildren ,
13
14
Directive ,
@@ -33,7 +34,7 @@ import {
33
34
SPACE ,
34
35
UP_ARROW ,
35
36
} from '@angular/cdk/keycodes' ;
36
- import { BooleanInput , coerceArray , coerceBooleanProperty } from '@angular/cdk/coercion' ;
37
+ import { coerceArray } from '@angular/cdk/coercion' ;
37
38
import { SelectionModel } from '@angular/cdk/collections' ;
38
39
import { defer , fromEvent , merge , Observable , Subject } from 'rxjs' ;
39
40
import { filter , map , startWith , switchMap , takeUntil } from 'rxjs/operators' ;
@@ -115,12 +116,12 @@ export class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightab
115
116
@Input ( 'cdkOptionTypeaheadLabel' ) typeaheadLabel : string ;
116
117
117
118
/** Whether this option is disabled. */
118
- @Input ( 'cdkOptionDisabled' )
119
+ @Input ( { alias : 'cdkOptionDisabled' , transform : booleanAttribute } )
119
120
get disabled ( ) : boolean {
120
121
return this . listbox . disabled || this . _disabled ;
121
122
}
122
- set disabled ( value : BooleanInput ) {
123
- this . _disabled = coerceBooleanProperty ( value ) ;
123
+ set disabled ( value : boolean ) {
124
+ this . _disabled = value ;
124
125
}
125
126
private _disabled : boolean = false ;
126
127
@@ -281,37 +282,25 @@ export class CdkListbox<T = unknown> implements AfterContentInit, OnDestroy, Con
281
282
* Whether the listbox allows multiple options to be selected. If the value switches from `true`
282
283
* to `false`, and more than one option is selected, all options are deselected.
283
284
*/
284
- @Input ( 'cdkListboxMultiple' )
285
+ @Input ( { alias : 'cdkListboxMultiple' , transform : booleanAttribute } )
285
286
get multiple ( ) : boolean {
286
287
return this . selectionModel . multiple ;
287
288
}
288
- set multiple ( value : BooleanInput ) {
289
- this . selectionModel . multiple = coerceBooleanProperty ( value ) ;
289
+ set multiple ( value : boolean ) {
290
+ this . selectionModel . multiple = value ;
290
291
291
292
if ( this . options ) {
292
293
this . _updateInternalValue ( ) ;
293
294
}
294
295
}
295
296
296
297
/** Whether the listbox is disabled. */
297
- @Input ( 'cdkListboxDisabled' )
298
- get disabled ( ) : boolean {
299
- return this . _disabled ;
300
- }
301
- set disabled ( value : BooleanInput ) {
302
- this . _disabled = coerceBooleanProperty ( value ) ;
303
- }
304
- private _disabled : boolean = false ;
298
+ @Input ( { alias : 'cdkListboxDisabled' , transform : booleanAttribute } )
299
+ disabled : boolean = false ;
305
300
306
301
/** Whether the listbox will use active descendant or will move focus onto the options. */
307
- @Input ( 'cdkListboxUseActiveDescendant' )
308
- get useActiveDescendant ( ) : boolean {
309
- return this . _useActiveDescendant ;
310
- }
311
- set useActiveDescendant ( shouldUseActiveDescendant : BooleanInput ) {
312
- this . _useActiveDescendant = coerceBooleanProperty ( shouldUseActiveDescendant ) ;
313
- }
314
- private _useActiveDescendant : boolean = false ;
302
+ @Input ( { alias : 'cdkListboxUseActiveDescendant' , transform : booleanAttribute } )
303
+ useActiveDescendant : boolean = false ;
315
304
316
305
/** The orientation of the listbox. Only affects keyboard interaction, not visual layout. */
317
306
@Input ( 'cdkListboxOrientation' )
@@ -341,23 +330,23 @@ export class CdkListbox<T = unknown> implements AfterContentInit, OnDestroy, Con
341
330
* Whether the keyboard navigation should wrap when the user presses arrow down on the last item
342
331
* or arrow up on the first item.
343
332
*/
344
- @Input ( 'cdkListboxNavigationWrapDisabled' )
333
+ @Input ( { alias : 'cdkListboxNavigationWrapDisabled' , transform : booleanAttribute } )
345
334
get navigationWrapDisabled ( ) {
346
335
return this . _navigationWrapDisabled ;
347
336
}
348
- set navigationWrapDisabled ( wrap : BooleanInput ) {
349
- this . _navigationWrapDisabled = coerceBooleanProperty ( wrap ) ;
337
+ set navigationWrapDisabled ( wrap : boolean ) {
338
+ this . _navigationWrapDisabled = wrap ;
350
339
this . listKeyManager ?. withWrap ( ! this . _navigationWrapDisabled ) ;
351
340
}
352
341
private _navigationWrapDisabled = false ;
353
342
354
343
/** Whether keyboard navigation should skip over disabled items. */
355
- @Input ( 'cdkListboxNavigatesDisabledOptions' )
344
+ @Input ( { alias : 'cdkListboxNavigatesDisabledOptions' , transform : booleanAttribute } )
356
345
get navigateDisabledOptions ( ) {
357
346
return this . _navigateDisabledOptions ;
358
347
}
359
- set navigateDisabledOptions ( skip : BooleanInput ) {
360
- this . _navigateDisabledOptions = coerceBooleanProperty ( skip ) ;
348
+ set navigateDisabledOptions ( skip : boolean ) {
349
+ this . _navigateDisabledOptions = skip ;
361
350
this . listKeyManager ?. skipPredicate (
362
351
this . _navigateDisabledOptions ? this . _skipNonePredicate : this . _skipDisabledPredicate ,
363
352
) ;
@@ -683,7 +672,7 @@ export class CdkListbox<T = unknown> implements AfterContentInit, OnDestroy, Con
683
672
684
673
/** Called when the user presses keydown on the listbox. */
685
674
protected _handleKeydown ( event : KeyboardEvent ) {
686
- if ( this . _disabled ) {
675
+ if ( this . disabled ) {
687
676
return ;
688
677
}
689
678
@@ -809,7 +798,7 @@ export class CdkListbox<T = unknown> implements AfterContentInit, OnDestroy, Con
809
798
810
799
/** Get the id of the active option if active descendant is being used. */
811
800
protected _getAriaActiveDescendant ( ) : string | null | undefined {
812
- return this . _useActiveDescendant ? this . listKeyManager ?. activeItem ?. id : null ;
801
+ return this . useActiveDescendant ? this . listKeyManager ?. activeItem ?. id : null ;
813
802
}
814
803
815
804
/** Get the tabindex for the listbox. */
0 commit comments