Skip to content

Commit 7855a23

Browse files
authored
8443 fix esc closing modal when closing tooltip (#8600)
2 parents 02e3265 + a2a8b11 commit 7855a23

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

packages/components/src/components/drawer/shadow.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
2-
import type { AlignPropType, DrawerAPI, DrawerStates, HasCloserPropType, KoliBriModalEventCallbacks, LabelPropType, OpenPropType } from '../../schema';
3-
import { setState, validateAlign, validateHasCloser, validateLabel, validateOpen } from '../../schema';
42
import type { JSX } from '@stencil/core';
53
import { Component, Element, h, Host, Method, Prop, State, Watch } from '@stencil/core';
6-
import { dispatchDomEvent, KolEvent } from '../../utils/events';
74
import clsx from 'clsx';
85
import { KolCardWcTag } from '../../core/component-names';
6+
import type { AlignPropType, DrawerAPI, DrawerStates, HasCloserPropType, KoliBriModalEventCallbacks, LabelPropType, OpenPropType } from '../../schema';
7+
import { setState, validateAlign, validateHasCloser, validateLabel, validateOpen } from '../../schema';
8+
import { dispatchDomEvent, KolEvent } from '../../utils/events';
9+
import { handleCancelOverlay } from '../../utils/tooltip-open-tracking';
910

1011
/**
1112
* @slot - The Content of drawer.
@@ -87,7 +88,7 @@ export class KolDrawer implements DrawerAPI {
8788
public render(): JSX.Element {
8889
return (
8990
<Host class="kol-drawer">
90-
<dialog aria-label={this.state._label} class="kol-drawer__dialog" ref={this.getRef}>
91+
<dialog aria-label={this.state._label} class="kol-drawer__dialog" onCancel={handleCancelOverlay} ref={this.getRef}>
9192
{this.renderDialogContent()}
9293
</dialog>
9394
</Host>

packages/components/src/components/modal/shadow.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { setState, validateLabel, validateWidth } from '../../schema';
77
import type { ModalVariantPropType } from '../../schema/props/variant/modal';
88
import { validateModalVariant } from '../../schema/props/variant/modal';
99
import { dispatchDomEvent, KolEvent } from '../../utils/events';
10+
import { handleCancelOverlay } from '../../utils/tooltip-open-tracking';
1011

1112
/**
1213
* https://en.wikipedia.org/wiki/Modal_window
@@ -68,6 +69,7 @@ export class KolModal implements ModalAPI {
6869
'kol-modal__blank': this.state._variant === 'blank',
6970
'kol-modal__card': this.state._variant === 'card',
7071
})}
72+
onCancel={handleCancelOverlay}
7173
onClose={this.handleNativeCloseEvent.bind(this)}
7274
ref={(el) => {
7375
this.refDialog = el;

packages/components/src/components/tooltip/component.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Component, Element, h, Host, Prop, State, Watch } from '@stencil/core';
88
import { alignFloatingElements } from '../../utils/align-floating-elements';
99
import { hideOverlay, showOverlay } from '../../utils/overlay';
1010
import { KolSpanFc } from '../../functional-components';
11+
import { tooltipClosed, tooltipOpened } from '../../utils/tooltip-open-tracking';
1112

1213
// Timing Guidelines for Exposing Hidden Content: https://www.nngroup.com/articles/timing-exposing-content/
1314
const TOOLTIP_DELAY = 300;
@@ -42,6 +43,7 @@ export class KolTooltipWc implements TooltipAPI {
4243
private showTooltip = (): void => {
4344
if (this.previousSibling && this.tooltipElement /* SSR instanceof HTMLElement */) {
4445
showOverlay(this.tooltipElement);
46+
tooltipOpened();
4547
this.tooltipElement.style.setProperty('display', 'block');
4648
getDocument().addEventListener('keyup', this.hideTooltipByEscape);
4749

@@ -79,6 +81,7 @@ export class KolTooltipWc implements TooltipAPI {
7981
clearTimeout(this.showTooltipTimeout); // Cancel scheduled tooltips
8082
if (this.tooltipElement /* SSR instanceof HTMLElement */) {
8183
hideOverlay(this.tooltipElement);
84+
tooltipClosed();
8285
this.tooltipElement.style.setProperty('display', 'none');
8386
this.tooltipElement.style.setProperty('visibility', 'hidden');
8487
if (this.cleanupAutoPositioning) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let openTooltips = 0;
2+
3+
export const tooltipOpened = () => {
4+
openTooltips++;
5+
};
6+
7+
export const tooltipClosed = () => {
8+
openTooltips = Math.max(0, openTooltips - 1);
9+
};
10+
11+
export const handleCancelOverlay = (event: Event): void => {
12+
if (openTooltips > 0) {
13+
event.preventDefault();
14+
}
15+
};

0 commit comments

Comments
 (0)