9
9
import { FocusKeyManager } from '@angular/cdk/a11y' ;
10
10
import { Directionality } from '@angular/cdk/bidi' ;
11
11
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
12
- import { HOME , END } from '@angular/cdk/keycodes' ;
12
+ import { END , HOME } from '@angular/cdk/keycodes' ;
13
13
import {
14
14
AfterContentInit ,
15
15
ChangeDetectionStrategy ,
@@ -26,7 +26,7 @@ import {
26
26
ViewEncapsulation
27
27
} from '@angular/core' ;
28
28
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
29
- import { MDCChipSetAdapter , MDCChipSetFoundation } from '@material/chips' ;
29
+ import { MDCChipSetFoundation } from '@material/chips' ;
30
30
import { merge , Observable , Subscription } from 'rxjs' ;
31
31
import { startWith , takeUntil } from 'rxjs/operators' ;
32
32
import { MatChip , MatChipEvent } from './chip' ;
@@ -96,22 +96,6 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
96
96
/** Subscription to focus changes in the chips. */
97
97
private _chipFocusSubscription : Subscription | null ;
98
98
99
- /**
100
- * Implementation of the MDC chip-set adapter interface.
101
- * These methods are called by the chip set foundation.
102
- *
103
- * Overrides the base MatChipSet adapter to provide a setSelected method.
104
- */
105
- protected _chipSetAdapter : MDCChipSetAdapter = {
106
- hasClass : ( className : string ) => this . _hasMdcClass ( className ) ,
107
- // No-op. We keep track of chips via ContentChildren, which will be updated when a chip is
108
- // removed.
109
- removeChip : ( ) => { } ,
110
- setSelected : ( chipId : string , selected : boolean ) => {
111
- this . _setSelected ( chipId , selected ) ;
112
- }
113
- } ;
114
-
115
99
/** The FocusKeyManager which handles focus. */
116
100
_keyManager : FocusKeyManager < MatChip > ;
117
101
@@ -223,8 +207,11 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
223
207
224
208
constructor ( protected _elementRef : ElementRef ,
225
209
_changeDetectorRef : ChangeDetectorRef ,
226
- @Optional ( ) private _dir : Directionality ) {
227
- super ( _elementRef , _changeDetectorRef ) ;
210
+ @Optional ( ) _dir : Directionality ) {
211
+ super ( _elementRef , _changeDetectorRef , _dir ) ;
212
+ this . _chipSetAdapter . selectChipAtIndex = ( index : number , selected : boolean ) => {
213
+ this . _setSelected ( index , selected ) ;
214
+ } ;
228
215
// Reinitialize the foundation with our overridden adapter
229
216
this . _chipSetFoundation = new MDCChipSetFoundation ( this . _chipSetAdapter ) ;
230
217
this . _updateMdcSelectionClasses ( ) ;
@@ -319,8 +306,8 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
319
306
}
320
307
321
308
/** Selects or deselects a chip by id. */
322
- _setSelected ( chipId : string , selected : boolean ) {
323
- const chip = this . _chips . find ( c => c . id === chipId ) ;
309
+ _setSelected ( index : number , selected : boolean ) {
310
+ const chip = this . _chips . toArray ( ) [ index ] ;
324
311
if ( chip && chip . selected != selected ) {
325
312
chip . toggleSelected ( true ) ;
326
313
}
@@ -468,7 +455,7 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
468
455
469
456
/** Initializes the key manager to manage focus. */
470
457
private _initKeyManager ( ) {
471
- this . _keyManager = new FocusKeyManager < MatChipOption > ( this . _chips )
458
+ this . _keyManager = new FocusKeyManager < MatChip > ( this . _chips )
472
459
. withWrap ( )
473
460
. withVerticalOrientation ( )
474
461
. withHorizontalOrientation ( this . _dir ? this . _dir . value : 'ltr' ) ;
@@ -543,7 +530,7 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
543
530
this . _chipSelectionSubscription = this . chipSelectionChanges . subscribe (
544
531
( chipSelectionChange : MatChipSelectionChange ) => {
545
532
this . _chipSetFoundation . handleChipSelection (
546
- chipSelectionChange . source . id , chipSelectionChange . selected ) ;
533
+ chipSelectionChange . source . id , chipSelectionChange . selected , false ) ;
547
534
if ( chipSelectionChange . isUserInput ) {
548
535
this . _propagateChanges ( ) ;
549
536
}
0 commit comments