diff --git a/src/components/tooltip/tooltip-body.ts b/src/components/tooltip/tooltip-body.ts index a30d68a71..a949bd153 100644 --- a/src/components/tooltip/tooltip-body.ts +++ b/src/components/tooltip/tooltip-body.ts @@ -1,7 +1,7 @@ /** * @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. @@ -9,6 +9,7 @@ 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, @@ -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. */