Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions projects/igniteui-angular/combo/src/combo/combo.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,40 @@ describe('igxCombo', () => {
expect(document.activeElement).toEqual(combo.comboInput.nativeElement);
expect(combo.selection.length).toEqual(0);
}));
it('should stop Escape keydown event propagation when the dropdown is open', fakeAsync(() => {
const escapeEvent = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true });
spyOn(escapeEvent, 'stopPropagation');

combo.comboInput.nativeElement.focus();
fixture.detectChanges();

combo.toggle();
fixture.detectChanges();
expect(combo.collapsed).toBeFalsy();

combo.onEscape(escapeEvent);
tick();
fixture.detectChanges();

expect(escapeEvent.stopPropagation).toHaveBeenCalled();
}));
it('should stop Escape key propagation when the combo is collapsed and has a selection', fakeAsync(() => {
combo.comboInput.nativeElement.focus();
fixture.detectChanges();

combo.select([combo.data[0][combo.valueKey]]);
expect(combo.selection.length).toEqual(1);
fixture.detectChanges();

const keyEvent = new KeyboardEvent('keydown', { key: 'Escape' });
const stopPropSpy = spyOn(keyEvent, 'stopPropagation');

combo.onEscape(keyEvent);
tick();
fixture.detectChanges();

expect(stopPropSpy).toHaveBeenCalledTimes(1);
}));
it('should close the combo and preserve the focus when Escape key is pressed', fakeAsync(() => {
combo.comboInput.nativeElement.focus();
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class IgxComboComponent extends IgxComboBaseDirective implements AfterVie

@HostListener('keydown.Escape', ['$event'])
public onEscape(event: Event) {
event.stopPropagation();
if (this.collapsed) {
this.deselectAllItems(true, event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,38 @@ describe('IgxSimpleCombo', () => {
expect(combo.selection).not.toBeDefined();
}));

it('should stop Escape keydown event propagation when the dropdown is open', fakeAsync(() => {
const escapeEvent = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true });
spyOn(escapeEvent, 'stopPropagation');

combo.open();
fixture.detectChanges();
expect(combo.collapsed).toBeFalsy();

combo.handleKeyDown(escapeEvent);
tick();
fixture.detectChanges();

expect(escapeEvent.stopPropagation).toHaveBeenCalled();
}));

it('should stop Escape key propagation when the combo is collapsed and has a selection', fakeAsync(() => {
combo.comboInput.nativeElement.focus();
fixture.detectChanges();

combo.select(combo.data[2][combo.valueKey]);
fixture.detectChanges();
expect(combo.selection).toBeDefined();

const keyEvent = new KeyboardEvent('keydown', { key: 'Escape' });
const stopPropSpy = spyOn(keyEvent, 'stopPropagation');

combo.handleKeyDown(keyEvent);
fixture.detectChanges();

expect(stopPropSpy).toHaveBeenCalledTimes(1);
}));

it('should clear the selection on tab/blur if the search text does not match any value', () => {
// allowCustomValues does not matter
combo.select(combo.data[2][combo.valueKey]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
}
}
if (event.key === this.platformUtil.KEYMAP.ESCAPE) {
event.stopPropagation();
if (this.collapsed) {
const oldSelection = this.selection;
this.clearSelection(true);
Expand Down
Loading