Skip to content

Commit e6e5f58

Browse files
committed
fix legend focus in ff
1 parent bb8f4d1 commit e6e5f58

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/core/components/core-application.tsx

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

4+
import clsx from "clsx";
5+
46
import { useSelector } from "../../internal/utils/async-store";
57
import { ChartAPI } from "../chart-api";
68

9+
import styles from "../styles.css.js";
710
import testClasses from "../test-classes/styles.css.js";
811

912
// An invisible component rendered before chart plot to capture focus for custom keyboard navigation.
@@ -26,7 +29,7 @@ export function ChartApplication({
2629
tabIndex={0}
2730
role="application"
2831
aria-label={ariaLabel}
29-
className={testClasses.application}
32+
className={clsx(testClasses.application, styles.application)}
3033
/>
3134
</div>
3235
) : null;

src/core/styles.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,8 @@ $side-legend-min-inline-size: max(20%, 150px);
112112
max-inline-size: $side-legend-max-inline-size;
113113
min-inline-size: $side-legend-min-inline-size;
114114
}
115+
116+
.application {
117+
// We hide the native focus outline to render a custom one around the chart plot instead.
118+
outline: none;
119+
}

src/internal/components/chart-legend/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ export const ChartLegend = ({
252252
)}
253253

254254
<div
255+
// The list element is not focusable. However, the focus lands on it regardless, when testing in Firefox.
256+
// Setting the tab index to -1 does fix the problem.
257+
tabIndex={-1}
255258
className={clsx(styles.list, {
256259
[styles["list-bottom"]]: position === "bottom",
257260
[styles["list-side"]]: position === "side",

0 commit comments

Comments
 (0)