Skip to content

Commit be28604

Browse files
committed
fix: Add role="tooltip" to non-modal chart popovers
1 parent ed20611 commit be28604

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/internal/components/chart-popover/__tests__/chart-popover.test.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@ import { act, render } from '@testing-library/react';
66

77
import ChartPopover from '../../../../../lib/components/internal/components/chart-popover';
88

9+
describe('accessibility', () => {
10+
test('has role="tooltip" on the root element if dismissButton is false', () => {
11+
const { container } = render(
12+
<ChartPopover
13+
trackRef={{ current: null }}
14+
container={null}
15+
onDismiss={() => {}}
16+
dismissButton={false}
17+
data-testid="chart-popover"
18+
>
19+
content
20+
</ChartPopover>
21+
);
22+
23+
const popoverRoot = container.querySelector('[data-testid="chart-popover"]');
24+
expect(popoverRoot).toBeInTheDocument();
25+
expect(popoverRoot).toHaveAttribute('role', 'tooltip');
26+
});
27+
28+
test('does not have role="tooltip" on the root element if dismissButton is true', () => {
29+
const { container } = render(
30+
<ChartPopover
31+
trackRef={{ current: null }}
32+
container={null}
33+
onDismiss={() => {}}
34+
dismissButton={true}
35+
data-testid="chart-popover"
36+
>
37+
content
38+
</ChartPopover>
39+
);
40+
41+
const popoverRoot = container.querySelector('[data-testid="chart-popover"]');
42+
expect(popoverRoot).toBeInTheDocument();
43+
expect(popoverRoot).not.toHaveAttribute('role', 'tooltip');
44+
});
45+
});
46+
947
describe('click outside', () => {
1048
function TestComponent({ onDismiss }: { onDismiss: () => void }) {
1149
return (

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function ChartPopover(
119119
return (
120120
<div
121121
{...baseProps}
122+
role={!dismissButton ? 'tooltip' : undefined}
122123
className={clsx(popoverStyles.root, styles.root, baseProps.className)}
123124
ref={popoverRef}
124125
onMouseEnter={onMouseEnter}

0 commit comments

Comments
 (0)