Skip to content

Commit 0416022

Browse files
committed
Fix blur & focus behavior
1 parent 108b985 commit 0416022

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/lib/chips/chip-list.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export class MdChipList implements MdFormFieldControl<any>, ControlValueAccessor
111111
/** Subscription to focus changes in the chips. */
112112
private _chipFocusSubscription: Subscription|null;
113113

114+
/** Subscription to blur changes in the chips. */
115+
private _chipBlurSubscription: Subscription|null;
116+
114117
/** Subscription to selection changes in chips. */
115118
private _chipSelectionSubscription: Subscription|null;
116119

@@ -284,6 +287,11 @@ export class MdChipList implements MdFormFieldControl<any>, ControlValueAccessor
284287
return merge(...this.chips.map(chip => chip._onFocus));
285288
}
286289

290+
/** Combined stream of all of the child chips' blur change events. */
291+
get chipBlurChanges(): Observable<MdChipEvent> {
292+
return merge(...this.chips.map(chip => chip._onBlur));
293+
}
294+
287295
/** Combined stream of all of the child chips' remove change events. */
288296
get chipRemoveChanges(): Observable<MdChipEvent> {
289297
return merge(...this.chips.map(chip => chip.destroy));
@@ -656,6 +664,11 @@ export class MdChipList implements MdFormFieldControl<any>, ControlValueAccessor
656664
this._chipFocusSubscription = null;
657665
}
658666

667+
if (this._chipBlurSubscription) {
668+
this._chipBlurSubscription.unsubscribe();
669+
this._chipBlurSubscription = null;
670+
}
671+
659672
if (this._chipSelectionSubscription) {
660673
this._chipSelectionSubscription.unsubscribe();
661674
this._chipSelectionSubscription = null;
@@ -694,6 +707,11 @@ export class MdChipList implements MdFormFieldControl<any>, ControlValueAccessor
694707
}
695708
this.stateChanges.next();
696709
});
710+
711+
this._chipBlurSubscription = this.chipBlurChanges.subscribe(_ => {
712+
this._blur();
713+
this.stateChanges.next();
714+
});
697715
}
698716

699717
private _listenToChipsRemoved(): void {

src/lib/chips/chip.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class MdBasicChip { }
6969
'(click)': '_handleClick($event)',
7070
'(keydown)': '_handleKeydown($event)',
7171
'(focus)': '_hasFocus = true',
72-
'(blur)': '_hasFocus = false',
72+
'(blur)': '_blur()',
7373
},
7474

7575
})
@@ -122,6 +122,9 @@ export class MdChip extends _MdChipMixinBase implements FocusableOption, OnDestr
122122
/** Emits when the chip is focused. */
123123
_onFocus = new Subject<MdChipEvent>();
124124

125+
/** Emits when the chip is blured. */
126+
_onBlur = new Subject<MdChipEvent>();
127+
125128
/** Emitted when the chip is selected or deselected. */
126129
@Output() onSelectionChange = new EventEmitter<MdChipSelectionChange>();
127130

@@ -225,6 +228,11 @@ export class MdChip extends _MdChipMixinBase implements FocusableOption, OnDestr
225228
break;
226229
}
227230
}
231+
232+
_blur() {
233+
this._hasFocus = false;
234+
this._onBlur.next({chip: this});
235+
}
228236
}
229237

230238

0 commit comments

Comments
 (0)