Skip to content

Commit dc28666

Browse files
committed
fix: hide tooltip on escape
1 parent 2a288d6 commit dc28666

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/core/chart-core.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { useRef } from "react";
4+
import { useEffect, useRef } from "react";
55
import clsx from "clsx";
66
import type Highcharts from "highcharts";
77
import HighchartsReact from "highcharts-react-official";
88

99
import { getIsRtl, useMergeRefs, useUniqueId } from "@cloudscape-design/component-toolkit/internal";
1010
import { isDevelopment } from "@cloudscape-design/component-toolkit/internal";
11+
import { KeyCode } from "@cloudscape-design/component-toolkit/internal";
1112
import Spinner from "@cloudscape-design/components/spinner";
1213

1314
import { getDataAttributes } from "../internal/base-component/get-data-attributes";
@@ -103,6 +104,24 @@ export function InternalCoreChart({
103104
legendBottomMaxHeight: legendOptions?.bottomMaxHeight,
104105
};
105106

107+
// AWSUI-61678
108+
// Add global Escape key listener to dismiss hover tooltips for WCAG Content on Hover/Focus compliance
109+
useEffect(() => {
110+
const handleKeyDown = (event: KeyboardEvent) => {
111+
if (event.keyCode === KeyCode.escape && context.tooltipEnabled) {
112+
const tooltipState = api.tooltipStore.get();
113+
if (tooltipState.visible && !tooltipState.pinned) {
114+
api.hideTooltip();
115+
}
116+
}
117+
};
118+
119+
document.addEventListener("keydown", handleKeyDown);
120+
return () => {
121+
document.removeEventListener("keydown", handleKeyDown);
122+
};
123+
}, [api, context.tooltipEnabled]);
124+
106125
// Render fallback using the same root and container props as for the chart to ensure consistent
107126
// size, test classes, and data-attributes assignment.
108127
if (!highcharts) {

0 commit comments

Comments
 (0)