Skip to content

Commit

Permalink
[EuiComboBox, EuiPopover] Update esc logic (#4336)
Browse files Browse the repository at this point in the history
* prevent esc from propagating when list is open

* prevent esc propagation from focus trap

* CL
  • Loading branch information
thompsongl authored Dec 7, 2020
1 parent 5aece6a commit ad97583
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fixed `EuiToolTip` closing during initial positioning period ([#4327](https://github.com/elastic/eui/pull/4327))
- Added `!default` to SASS variables of `EuiCollapsibleNav` ([#4335](https://github.com/elastic/eui/pull/4335))
- Fixed `EuiDataGrid` column property `displayAsText`. Column headers prefer `displayAsText` over `id`; `display` still takes precedence. If provided, the filter in the sort-popover will search against `displayAsText` instead of `id`. ([#4351](https://github.com/elastic/eui/pull/4351))
- Fixed propagation of `esc` key presses closing parent popovers ([#4336](https://github.com/elastic/eui/pull/4336))


**Theme: Amsterdam**
Expand Down
7 changes: 5 additions & 2 deletions src/components/combo_box/combo_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,11 @@ export class EuiComboBox<T> extends Component<
break;

case keys.ESCAPE:
event.stopPropagation();
this.closeList();
if (this.state.isListOpen) {
event.preventDefault();
event.stopPropagation();
this.closeList();
}
break;

case keys.ENTER:
Expand Down
12 changes: 10 additions & 2 deletions src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,17 @@ export class EuiPopover extends Component<Props, State> {
}
};

onEscapeKey = (event: Event) => {
if (this.props.isOpen) {
event.preventDefault();
event.stopPropagation();
this.closePopover();
}
};

onKeyDown = (event: KeyboardEvent) => {
if (event.key === cascadingMenuKeys.ESCAPE) {
this.closePopover();
this.onEscapeKey((event as unknown) as Event);
}
};

Expand Down Expand Up @@ -724,7 +732,7 @@ export class EuiPopover extends Component<Props, State> {
initialFocus={initialFocus}
onDeactivation={onTrapDeactivation}
onClickOutside={this.onClickOutside}
onEscapeKey={this.closePopover}
onEscapeKey={this.onEscapeKey}
disabled={
!ownFocus || !this.state.isOpenStable || this.state.isClosing
}>
Expand Down

0 comments on commit ad97583

Please sign in to comment.