|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -import { useRef } from "react"; |
| 4 | +import { useEffect, useRef } from "react"; |
5 | 5 | import clsx from "clsx"; |
6 | 6 | import type Highcharts from "highcharts"; |
7 | 7 | import HighchartsReact from "highcharts-react-official"; |
8 | 8 |
|
9 | 9 | import { getIsRtl, useMergeRefs, useUniqueId } from "@cloudscape-design/component-toolkit/internal"; |
10 | 10 | import { isDevelopment } from "@cloudscape-design/component-toolkit/internal"; |
| 11 | +import { KeyCode } from "@cloudscape-design/component-toolkit/internal"; |
11 | 12 | import Spinner from "@cloudscape-design/components/spinner"; |
12 | 13 |
|
13 | 14 | import { getDataAttributes } from "../internal/base-component/get-data-attributes"; |
@@ -103,6 +104,24 @@ export function InternalCoreChart({ |
103 | 104 | legendBottomMaxHeight: legendOptions?.bottomMaxHeight, |
104 | 105 | }; |
105 | 106 |
|
| 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 | + |
106 | 125 | // Render fallback using the same root and container props as for the chart to ensure consistent |
107 | 126 | // size, test classes, and data-attributes assignment. |
108 | 127 | if (!highcharts) { |
|
0 commit comments