File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ describe('MatChipList', () => {
269
269
270
270
// Press the LEFT arrow
271
271
chipListInstance . _keydown ( LEFT_EVENT ) ;
272
+ chipListInstance . _blur ( ) ; // Simulate focus leaving the list and going to the chip.
272
273
fixture . detectChanges ( ) ;
273
274
274
275
// It focuses the next-to-last item
@@ -290,6 +291,7 @@ describe('MatChipList', () => {
290
291
291
292
// Press the RIGHT arrow
292
293
chipListInstance . _keydown ( RIGHT_EVENT ) ;
294
+ chipListInstance . _blur ( ) ; // Simulate focus leaving the list and going to the chip.
293
295
fixture . detectChanges ( ) ;
294
296
295
297
// It focuses the next-to-last item
@@ -362,6 +364,7 @@ describe('MatChipList', () => {
362
364
363
365
// Press the RIGHT arrow
364
366
chipListInstance . _keydown ( RIGHT_EVENT ) ;
367
+ chipListInstance . _blur ( ) ; // Simulate focus leaving the list and going to the chip.
365
368
fixture . detectChanges ( ) ;
366
369
367
370
// It focuses the next-to-last item
@@ -383,6 +386,7 @@ describe('MatChipList', () => {
383
386
384
387
// Press the LEFT arrow
385
388
chipListInstance . _keydown ( LEFT_EVENT ) ;
389
+ chipListInstance . _blur ( ) ; // Simulate focus leaving the list and going to the chip.
386
390
fixture . detectChanges ( ) ;
387
391
388
392
// It focuses the next-to-last item
Original file line number Diff line number Diff line change @@ -242,7 +242,7 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
242
242
243
243
/** Whether any chips or the matChipInput inside of this chip-list has focus. */
244
244
get focused ( ) : boolean {
245
- return ( this . _chipInput && this . _chipInput . focused ) || this . chips . some ( chip => chip . _hasFocus ) ;
245
+ return ( this . _chipInput && this . _chipInput . focused ) || this . _hasFocusedChip ( ) ;
246
246
}
247
247
248
248
/**
@@ -636,7 +636,10 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
636
636
637
637
/** When blurred, mark the field as touched when focus moved outside the chip list. */
638
638
_blur ( ) {
639
- this . _keyManager . setActiveItem ( - 1 ) ;
639
+ if ( ! this . _hasFocusedChip ( ) ) {
640
+ this . _keyManager . setActiveItem ( - 1 ) ;
641
+ }
642
+
640
643
if ( ! this . disabled ) {
641
644
if ( this . _chipInput ) {
642
645
// If there's a chip input, we should check whether the focus moved to chip input.
@@ -758,4 +761,9 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
758
761
759
762
return false ;
760
763
}
764
+
765
+ /** Checks whether any of the chips is focused. */
766
+ private _hasFocusedChip ( ) {
767
+ return this . chips . some ( chip => chip . _hasFocus ) ;
768
+ }
761
769
}
You can’t perform that action at this time.
0 commit comments