@@ -22,21 +22,10 @@ import {
2222
2323import { MdChip } from './chip' ;
2424import { FocusKeyManager } from '../core/a11y/focus-key-manager' ;
25- import { BACKSPACE , DELETE , SPACE , DOWN_ARROW , LEFT_ARROW , RIGHT_ARROW , UP_ARROW } from '../core/keyboard/keycodes' ;
25+ import { BACKSPACE , DELETE , LEFT_ARROW , RIGHT_ARROW , UP_ARROW } from '../core/keyboard/keycodes' ;
2626import { coerceBooleanProperty , Directionality } from '@angular/cdk' ;
2727import { Subscription } from 'rxjs/Subscription' ;
2828
29- /** Utility to check if an input element has no value. */
30- function _isInputEmpty ( element : HTMLElement ) : boolean {
31- if ( element && element . nodeName . toLowerCase ( ) == 'input' ) {
32- let input = element as HTMLInputElement ;
33-
34- return ! input . value ;
35- }
36-
37- return false ;
38- }
39-
4029/**
4130 * A material design chips component (named ChipList for it's similarity to the List component).
4231 *
@@ -116,7 +105,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
116105 this . _subscribeChips ( chips ) ;
117106
118107 // If we have 0 chips, attempt to focus an input (if available)
119- if ( chips . length == 0 ) {
108+ if ( chips . length === 0 ) {
120109 this . _focusInput ( ) ;
121110 }
122111
@@ -139,7 +128,10 @@ export class MdChipList implements AfterContentInit, OnDestroy {
139128 * it's selected state is always ignored.
140129 */
141130 @Input ( )
142- get selectable ( ) : boolean { return this . _selectable ; }
131+ get selectable ( ) : boolean {
132+ return this . _selectable ;
133+ }
134+
143135 set selectable ( value : boolean ) {
144136 this . _selectable = coerceBooleanProperty ( value ) ;
145137 }
@@ -175,26 +167,19 @@ export class MdChipList implements AfterContentInit, OnDestroy {
175167 _keydown ( event : KeyboardEvent ) {
176168 let code = event . keyCode ;
177169 let target = event . target as HTMLElement ;
178- let isInputEmpty = _isInputEmpty ( target ) ;
170+ let isInputEmpty = this . _isInputEmpty ( target ) ;
179171 let isRtl = this . _dir && this . _dir . value == 'rtl' ;
180172
181- let isPrevKey = ( code == ( isRtl ? RIGHT_ARROW : LEFT_ARROW ) ) ;
182- let isNextKey = ( code == ( isRtl ? LEFT_ARROW : RIGHT_ARROW ) ) ;
183- let isBackKey = ( code == BACKSPACE || code == DELETE || code == UP_ARROW || isPrevKey ) ;
184- let isForwardKey = ( code == DOWN_ARROW || isNextKey ) ;
173+ let isPrevKey = ( code === ( isRtl ? RIGHT_ARROW : LEFT_ARROW ) ) ;
174+ let isNextKey = ( code === ( isRtl ? LEFT_ARROW : RIGHT_ARROW ) ) ;
175+ let isBackKey = ( code === BACKSPACE || code == DELETE || code == UP_ARROW || isPrevKey ) ;
185176 // If they are on an empty input and hit backspace/delete/left arrow, focus the last chip
186177 if ( isInputEmpty && isBackKey ) {
187178 this . _keyManager . setLastItemActive ( ) ;
188179 event . preventDefault ( ) ;
189180 return ;
190181 }
191182
192- let focusedIndex = this . _keyManager . activeItemIndex ;
193-
194- if ( typeof focusedIndex === 'number' && this . _isValidIndex ( focusedIndex ) ) {
195- let focusedChip : MdChip = this . chips . toArray ( ) [ focusedIndex ] ;
196- }
197-
198183 // If they are on a chip, check for space/left/right, otherwise pass to our key manager (like
199184 // up/down keys)
200185 if ( target && target . classList . contains ( 'mat-chip' ) ) {
@@ -225,7 +210,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
225210 */
226211 protected _updateTabIndex ( ) : void {
227212 // If we have 0 chips, we should not allow keyboard focus
228- this . _tabIndex = ( this . chips . length == 0 ? - 1 : 0 ) ;
213+ this . _tabIndex = ( this . chips . length === 0 ? - 1 : 0 ) ;
229214 }
230215
231216 /**
@@ -263,7 +248,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
263248 this . _keyManager . setActiveItem ( chipIndex - 1 ) ;
264249 }
265250 }
266- if ( this . _keyManager . activeItemIndex == chipIndex ) {
251+ if ( this . _keyManager . activeItemIndex === chipIndex ) {
267252 this . _lastDestroyedIndex = chipIndex ;
268253 }
269254
@@ -308,4 +293,14 @@ export class MdChipList implements AfterContentInit, OnDestroy {
308293 private _isValidIndex ( index : number ) : boolean {
309294 return index >= 0 && index < this . chips . length ;
310295 }
296+
297+ private _isInputEmpty ( element : HTMLElement ) : boolean {
298+ if ( element && element . nodeName . toLowerCase ( ) === 'input' ) {
299+ let input = element as HTMLInputElement ;
300+
301+ return ! input . value ;
302+ }
303+
304+ return false ;
305+ }
311306}
0 commit comments