Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 166859c

Browse files
Refine accessibility for WidgetTooltip
1 parent 49d7533 commit 166859c

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.4.0] - 2023-03-24
9+
10+
## Changed
11+
12+
- refined accessibility for `WidgetTooltip`
13+
814
## [3.3.1] - 2023-03-10
915

1016
## Changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import { render, screen } from '@testing-library/react'
3+
4+
import { TooltipProvider, WidgetTooltip } from '../../src'
5+
6+
describe('WidgetTooltip', () => {
7+
it('does not violate accessibility', async () => {
8+
render(
9+
<TooltipProvider>
10+
<WidgetTooltip helpText='My help text' triggerAriaLabel='Get help' />
11+
</TooltipProvider>
12+
)
13+
14+
screen.getByLabelText('Get help')
15+
})
16+
})

src/common/WidgetTooltip.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ import { QuestionMarkCircledIcon } from '@radix-ui/react-icons'
77

88
type Props = {
99
helpText: string | null
10+
triggerAriaLabel: string
1011
}
1112

12-
const WidgetTooltip = ({ helpText }: Props) => {
13+
const WidgetTooltip = ({ helpText, triggerAriaLabel }: Props) => {
1314
if (!helpText) return null
1415
return (
1516
<Tooltip
1617
triggerProps={{
1718
asChild: true,
18-
child: () => <StyledQuestionMarkCircledIcon />
19+
child: () => (
20+
<Trigger aria-label={triggerAriaLabel}>
21+
<StyledQuestionMarkCircledIcon
22+
focusable={false}
23+
aria-hidden={true}
24+
/>
25+
</Trigger>
26+
)
1927
}}
2028
contentProps={{
2129
child: () => (
@@ -29,6 +37,10 @@ const WidgetTooltip = ({ helpText }: Props) => {
2937
)
3038
}
3139

40+
const Trigger = styled.button`
41+
all: unset;
42+
`
43+
3244
const ContentWrapper = styled.div`
3345
max-width: 18.75em;
3446
`

src/widgets/LicenceWidget.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ const LicenceWidget = ({
128128
<Widget id={name}>
129129
<WidgetHeader>
130130
<WidgetTitle>{label}</WidgetTitle>
131-
<WidgetTooltip helpText={help || null} />
131+
<WidgetTooltip
132+
helpText={help || null}
133+
triggerAriaLabel={`Get help about ${label}`}
134+
/>
132135
</WidgetHeader>
133136
{licences.map((licence, index) => {
134137
const { id, label, accepted, revision, contents_url, attachment_url } =

0 commit comments

Comments
 (0)