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 committed Jan 21, 2025
1 parent e624121 commit 653f90c
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 32 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 @@ -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
13 changes: 12 additions & 1 deletion libs/core/popover/popover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ViewEncapsulation
} from '@angular/core';

import { DOWN_ARROW } from '@angular/cdk/keycodes';
import { DOWN_ARROW, ESCAPE } from '@angular/cdk/keycodes';
import { CdkOverlayOrigin, ConnectedPosition } from '@angular/cdk/overlay';

import { NgTemplateOutlet } from '@angular/common';
Expand Down Expand Up @@ -172,6 +172,17 @@ export class PopoverComponent
super();
}

/** Handler escape keydown */
@HostListener('keydown', ['$event'])
escapeKeydownHandler(event: KeyboardEvent): void {
if (KeyUtil.isKeyCode(event, ESCAPE) && 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

0 comments on commit 653f90c

Please sign in to comment.