Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): popover escape key to close should not bubble to dialog #12957

Merged
merged 2 commits into from
Feb 3, 2025
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
6 changes: 0 additions & 6 deletions libs/core/combobox/combobox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,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 @@ -525,9 +522,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 @@ -569,7 +569,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 @@ -724,10 +723,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 @@ -735,8 +735,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 @@ -279,7 +279,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 @@ -371,9 +371,6 @@ export class PlatformMultiInputComponent extends BaseMultiInput implements OnIni
this.searchInputElement.nativeElement.focus();
}
}
if (KeyUtil.isKeyCode(event, [ESCAPE])) {
this.showList(false);
}
this.markForCheck();
}

Expand Down
Loading