Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
feat(tooltip): support Esc dismissal
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Jan 21, 2022
1 parent f069c3d commit f70e1f0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/tooltip/tooltip-body.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/**
* @license
*
* Copyright IBM Corp. 2019, 2020
* Copyright IBM Corp. 2019, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import settings from 'carbon-components/es/globals/js/settings';
import { html, property, customElement } from 'lit-element';
import HostListener from '../../globals/decorators/host-listener';
import BXFloatingMenu, {
FLOATING_MENU_ALIGNMENT,
FLOATING_MENU_DIRECTION,
Expand Down Expand Up @@ -41,6 +42,17 @@ class BXTooltipBody extends BXFloatingMenu {
@property({ type: Boolean, reflect: true })
open = false;

/**
* Handles `keydown` event on this element.
*/
@HostListener('keydown')
// @ts-ignore: The decorator refers to this method but TS thinks this method is not referred to
private _handleKeydown = async event => {
if (event.key === 'Escape') {
this.open = false;
}
};

/**
* The position of this tooltip body.
*/
Expand Down

0 comments on commit f70e1f0

Please sign in to comment.