Skip to content

Commit 98adf34

Browse files
committed
fix(ui-color-picker): add hex to aria-label
INSTUI-4273
1 parent 4dacbf8 commit 98adf34

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

packages/ui-color-picker/src/ColorPreset/__new-tests__/ColorPreset.test.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ describe('<ColorPreset />', () => {
110110

111111
testColors.forEach((testColor, index) => {
112112
const tooltip = tooltips[index]
113-
const indicator = indicators[index]
114113

115-
expect(tooltip.getAttribute('id')).toBe(
116-
indicator.getAttribute('aria-describedby')
117-
)
118114
expect(tooltip).toHaveTextContent(testColor)
119115
})
120116
})

packages/ui-color-picker/src/ColorPreset/index.tsx

+24-4
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
266266
cursor={this.props.disabled ? 'not-allowed' : 'auto'}
267267
as="button"
268268
{...(selectOnClick ? { onClick: () => this.props.onSelect(color) } : {})}
269-
{...(this.isSelectedColor(color) ? { 'aria-label': 'selected' } : {})}
269+
{...{
270+
'aria-label': `${color}${
271+
this.isSelectedColor(color) ? ' selected' : ''
272+
}`
273+
}}
270274
>
271275
<div>
272276
<ColorIndicator color={color} shape="rectangle" role="presentation" />
@@ -282,9 +286,25 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
282286
</View>
283287
)
284288

285-
renderIndicatorTooltip = (child: React.ReactElement, color: string) => (
286-
<Tooltip renderTip={<div>{color}</div>}>{child}</Tooltip>
287-
)
289+
renderIndicatorTooltip = (child: React.ReactElement, color: string) => {
290+
return (
291+
<Tooltip
292+
renderTip={<div>{color}</div>}
293+
elementRef={(element) => {
294+
if (
295+
element &&
296+
element.firstElementChild instanceof HTMLButtonElement
297+
) {
298+
// The tooltip and the button's aria-label has the same text content. This is redundant for screenreaders.
299+
// Aria-describedby is removed to bypass reading the tooltip twice
300+
element.firstElementChild.removeAttribute('aria-describedby')
301+
}
302+
}}
303+
>
304+
{child}
305+
</Tooltip>
306+
)
307+
}
288308

289309
renderSettingsMenu = (color: string, index: number) => (
290310
<Drilldown

0 commit comments

Comments
 (0)