Skip to content

Commit

Permalink
fix(core): popover escape key to close should not bubble to dialog (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikerodonnell89 authored Feb 3, 2025
1 parent 77c1913 commit 474428e
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 31 deletions.
6 changes: 0 additions & 6 deletions libs/core/combobox/combobox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,6 @@ export class ComboboxComponent<T = any>
SHIFT
];

/** Keys, that will close popover's body, when dispatched on search input */
readonly closingKeys: number[] = [ESCAPE];

/** @hidden */
readonly _repositionScrollStrategy: RepositionScrollStrategy;

Expand Down Expand Up @@ -533,9 +530,6 @@ export class ComboboxComponent<T = any>
} else if (KeyUtil.isKeyCode(event, UP_ARROW)) {
this._chooseOtherItem(-1);
event.preventDefault();
} else if (KeyUtil.isKeyCode(event, this.closingKeys)) {
this.isOpenChangeHandle(false);
event.stopPropagation();
} else if (
this.openOnKeyboardEvent &&
!event.ctrlKey &&
Expand Down
5 changes: 0 additions & 5 deletions libs/core/multi-combobox/multi-combobox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ export class MultiComboboxComponent<T = any> extends BaseMultiCombobox<T> implem
_onItemKeyDownHandler(event: KeyboardEvent): void {
if (KeyUtil.isKeyCode(event, ESCAPE)) {
this._focusToSearchField();
this.close();
} else if ((event.ctrlKey || event.metaKey) && event.shiftKey && KeyUtil.isKeyCode(event, A)) {
event.preventDefault();
this._handleSelectAllItems(false);
Expand Down Expand Up @@ -723,10 +722,6 @@ export class MultiComboboxComponent<T = any> extends BaseMultiCombobox<T> implem
this._chooseOtherItem(-1);
} else if (KeyUtil.isKeyCode(event, ENTER)) {
this._toggleSelectionByInputText();
} else if (KeyUtil.isKeyCode(event, ESCAPE)) {
event.stopPropagation();

this._showList(false);
} else if (!KeyUtil.isKeyCode(event, [...this._nonOpeningKeys, CONTROL])) {
this._showList(true);
const acceptedKeys = !KeyUtil.isKeyType(event, 'alphabetical') && !KeyUtil.isKeyType(event, 'numeric');
Expand Down
4 changes: 1 addition & 3 deletions libs/core/multi-input/multi-input.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/member-ordering */
import { DOWN_ARROW, ENTER, ESCAPE, SPACE, TAB, UP_ARROW } from '@angular/cdk/keycodes';
import { DOWN_ARROW, ENTER, SPACE, TAB, UP_ARROW } from '@angular/cdk/keycodes';
import {
AfterViewInit,
ChangeDetectionStrategy,
Expand Down Expand Up @@ -739,8 +739,6 @@ export class MultiInputComponent<ItemType = any, ValueType = any>
}
} else if (KeyUtil.isKeyCode(event, [DOWN_ARROW, UP_ARROW, ENTER])) {
this.openChangeHandle(true);
} else if (KeyUtil.isKeyCode(event, ESCAPE)) {
this.openChangeHandle(false);
} else if (KeyUtil.isKeyCode(event, TAB) && this.open) {
this._close();
} else if (KeyUtil.isKeyType(event, 'alphabetical') || KeyUtil.isKeyType(event, 'numeric')) {
Expand Down
11 changes: 11 additions & 0 deletions libs/core/popover/popover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ export class PopoverComponent
super();
}

/** Handler escape keydown */
@HostListener('keydown.escape', ['$event'])
escapeKeydownHandler(event: KeyboardEvent): void {
if (this.closeOnEscapeKey && this.isOpen) {
// In case if popover belongs to the element inside dialog
event.preventDefault();
event.stopImmediatePropagation();
this.popoverBody.onClose.next();
}
}

/** @hidden */
@HostListener('keydown.space', ['$event'])
@HostListener('keydown.enter', ['$event'])
Expand Down
4 changes: 0 additions & 4 deletions libs/platform/form/combobox/commons/base-combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,6 @@ export abstract class BaseCombobox
event.preventDefault();

this._chooseOtherItem(-1);
} else if (KeyUtil.isKeyCode(event, ESCAPE)) {
event.stopPropagation();

this.isOpenChangeHandle(false);
} else if (!event.ctrlKey && !KeyUtil.isKeyCode(event, this._nonOpeningKeys)) {
if (!KeyUtil.isKeyCode(event, this._numberPadNumberKeys)) {
this.isOpenChangeHandle(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,6 @@ export abstract class BaseMultiCombobox extends CollectionBaseInput implements O
this._chooseOtherItem(-1);
} else if (KeyUtil.isKeyCode(event, ENTER)) {
this.toggleSelectionByInputText();
} else if (KeyUtil.isKeyCode(event, ESCAPE)) {
event.stopPropagation();

this.showList(false);
} else if (!KeyUtil.isKeyCode(event, [...this._nonOpeningKeys, CONTROL])) {
this.showList(true);
const acceptedKeys = !KeyUtil.isKeyType(event, 'alphabetical') && !KeyUtil.isKeyType(event, 'numeric');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ export class MultiComboboxComponent extends BaseMultiCombobox implements OnInit,
onItemKeyDownHandler(event: KeyboardEvent): void {
if (KeyUtil.isKeyCode(event, ESCAPE)) {
this._focusToSearchField();
this.close();
} else if ((event.ctrlKey || event.metaKey) && event.shiftKey && KeyUtil.isKeyCode(event, A)) {
event.preventDefault();
this.handleSelectAllItems(false);
Expand Down
4 changes: 0 additions & 4 deletions libs/platform/form/multi-input/base-multi-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,6 @@ export abstract class BaseMultiInput extends CollectionBaseInput implements Afte
event.preventDefault();

this._chooseOtherItem(-1);
} else if (KeyUtil.isKeyCode(event, ESCAPE)) {
event.stopPropagation();

this.showList(false);
} else if (!event.ctrlKey && !KeyUtil.isKeyCode(event, this._nonOpeningKeys)) {
this.showList(true);
}
Expand Down
5 changes: 1 addition & 4 deletions libs/platform/form/multi-input/multi-input.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/member-ordering */
import { DOWN_ARROW, ESCAPE, UP_ARROW } from '@angular/cdk/keycodes';
import { DOWN_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
import {
AfterViewInit,
ChangeDetectionStrategy,
Expand Down Expand Up @@ -370,9 +370,6 @@ export class PlatformMultiInputComponent extends BaseMultiInput implements OnIni
this.searchInputElement.nativeElement.focus();
}
}
if (KeyUtil.isKeyCode(event, [ESCAPE])) {
this.showList(false);
}
this.markForCheck();
}

Expand Down

0 comments on commit 474428e

Please sign in to comment.