99import { FocusKeyManager } from '@angular/cdk/a11y' ;
1010import { Directionality } from '@angular/cdk/bidi' ;
1111import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
12- import { HOME , END } from '@angular/cdk/keycodes' ;
12+ import { END , HOME } from '@angular/cdk/keycodes' ;
1313import {
1414 AfterContentInit ,
1515 ChangeDetectionStrategy ,
@@ -26,7 +26,7 @@ import {
2626 ViewEncapsulation
2727} from '@angular/core' ;
2828import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
29- import { MDCChipSetAdapter , MDCChipSetFoundation } from '@material/chips' ;
29+ import { MDCChipSetFoundation } from '@material/chips' ;
3030import { merge , Observable , Subscription } from 'rxjs' ;
3131import { startWith , takeUntil } from 'rxjs/operators' ;
3232import { MatChip , MatChipEvent } from './chip' ;
@@ -96,22 +96,6 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
9696 /** Subscription to focus changes in the chips. */
9797 private _chipFocusSubscription : Subscription | null ;
9898
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-
11599 /** The FocusKeyManager which handles focus. */
116100 _keyManager : FocusKeyManager < MatChip > ;
117101
@@ -223,8 +207,11 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
223207
224208 constructor ( protected _elementRef : ElementRef ,
225209 _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+ } ;
228215 // Reinitialize the foundation with our overridden adapter
229216 this . _chipSetFoundation = new MDCChipSetFoundation ( this . _chipSetAdapter ) ;
230217 this . _updateMdcSelectionClasses ( ) ;
@@ -319,8 +306,8 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
319306 }
320307
321308 /** 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 ] ;
324311 if ( chip && chip . selected != selected ) {
325312 chip . toggleSelected ( true ) ;
326313 }
@@ -468,7 +455,7 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
468455
469456 /** Initializes the key manager to manage focus. */
470457 private _initKeyManager ( ) {
471- this . _keyManager = new FocusKeyManager < MatChipOption > ( this . _chips )
458+ this . _keyManager = new FocusKeyManager < MatChip > ( this . _chips )
472459 . withWrap ( )
473460 . withVerticalOrientation ( )
474461 . withHorizontalOrientation ( this . _dir ? this . _dir . value : 'ltr' ) ;
@@ -543,7 +530,7 @@ export class MatChipListbox extends MatChipSet implements AfterContentInit, Cont
543530 this . _chipSelectionSubscription = this . chipSelectionChanges . subscribe (
544531 ( chipSelectionChange : MatChipSelectionChange ) => {
545532 this . _chipSetFoundation . handleChipSelection (
546- chipSelectionChange . source . id , chipSelectionChange . selected ) ;
533+ chipSelectionChange . source . id , chipSelectionChange . selected , false ) ;
547534 if ( chipSelectionChange . isUserInput ) {
548535 this . _propagateChanges ( ) ;
549536 }
0 commit comments