@@ -73,7 +73,7 @@ function _isInputEmpty(element: HTMLElement): boolean {
73
73
export class MdChipList implements AfterContentInit , OnDestroy {
74
74
75
75
/** When a chip is destroyed, we track the index so we can focus the appropriate next chip. */
76
- protected _destroyedIndex : number = null ;
76
+ protected _lastDestroyedIndex : number = null ;
77
77
78
78
/** Track which chips we're listening to for focus/destruction. */
79
79
protected _chipSet : WeakMap < MdChip , boolean > = new WeakMap ( ) ;
@@ -121,14 +121,14 @@ export class MdChipList implements AfterContentInit, OnDestroy {
121
121
122
122
// If we have 0 chips, attempt to focus an input (if available)
123
123
if ( chips . length == 0 ) {
124
- this . focusInput ( ) ;
124
+ this . _focusInput ( ) ;
125
125
}
126
126
127
127
// Check to see if we need to update our tab index
128
128
this . _checkTabIndex ( ) ;
129
129
130
130
// Check to see if we have a destroyed chip and need to refocus
131
- this . _checkDestroyedFocus ( ) ;
131
+ this . _updateFocusForDestroyedChips ( ) ;
132
132
} ) ;
133
133
}
134
134
@@ -138,6 +138,10 @@ export class MdChipList implements AfterContentInit, OnDestroy {
138
138
}
139
139
}
140
140
141
+ /**
142
+ * Whether or not this chip is selectable. When a chip is not selectable,
143
+ * it's selected state is always ignored.
144
+ */
141
145
@Input ( )
142
146
get selectable ( ) : boolean { return this . _selectable ; }
143
147
set selectable ( value : boolean ) {
@@ -150,20 +154,20 @@ export class MdChipList implements AfterContentInit, OnDestroy {
150
154
}
151
155
152
156
/**
153
- * Programmatically focus the chip list. This in turn focuses the first non-disabled chip in this
154
- * chip list, or the input if available and there are 0 chips.
157
+ * Focuses the the first non-disabled chip in this chip list, or the associated input when there
158
+ * are no eligible chips.
155
159
*/
156
- // TODO: ARIA says this should focus the first `selected` chip if any are selected.
157
160
focus ( event ?: Event ) {
161
+ // TODO: ARIA says this should focus the first `selected` chip if any are selected.
158
162
if ( this . chips . length > 0 ) {
159
163
this . _keyManager . setFirstItemActive ( ) ;
160
164
} else {
161
- this . focusInput ( ) ;
165
+ this . _focusInput ( ) ;
162
166
}
163
167
}
164
168
165
169
/** Attempt to focus an input if we have one. */
166
- focusInput ( ) {
170
+ _focusInput ( ) {
167
171
if ( this . _inputElement ) {
168
172
this . _inputElement . focus ( ) ;
169
173
}
@@ -262,7 +266,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
262
266
} else if ( chipIndex - 1 >= 0 ) {
263
267
this . _keyManager . setActiveItem ( chipIndex - 1 ) ;
264
268
}
265
- this . _destroyedIndex = chipIndex ;
269
+ this . _lastDestroyedIndex = chipIndex ;
266
270
}
267
271
268
272
this . _chipSet . delete ( chip ) ;
@@ -276,17 +280,14 @@ export class MdChipList implements AfterContentInit, OnDestroy {
276
280
* Checks to see if a focus chip was recently destroyed so that we can refocus the next closest
277
281
* one.
278
282
*/
279
- protected _checkDestroyedFocus ( ) {
283
+ protected _updateFocusForDestroyedChips ( ) {
280
284
let chipsArray = this . chips ;
281
285
let focusChip : MdChip ;
282
286
283
- if ( this . _destroyedIndex != null && chipsArray . length > 0 ) {
287
+ if ( this . _lastDestroyedIndex != null && chipsArray . length > 0 ) {
284
288
// Check whether the destroyed chip was the last item
285
- if ( this . _destroyedIndex >= chipsArray . length ) {
286
- this . _keyManager . setActiveItem ( chipsArray . length - 1 ) ;
287
- } else if ( this . _destroyedIndex >= 0 ) {
288
- this . _keyManager . setActiveItem ( this . _destroyedIndex ) ;
289
- }
289
+ const newFocusIndex = Math . min ( this . _lastDestroyedIndex , chipsArray . length - 1 ) ;
290
+ this . _keyManager . setActiveItem ( newFocusIndex ) ;
290
291
291
292
// Focus the chip
292
293
if ( focusChip ) {
@@ -295,7 +296,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
295
296
}
296
297
297
298
// Reset our destroyed index
298
- this . _destroyedIndex = null ;
299
+ this . _lastDestroyedIndex = null ;
299
300
}
300
301
301
302
/**
0 commit comments