Skip to content

Commit

Permalink
fix(ui-color-picker): add hex to aria-label
Browse files Browse the repository at this point in the history
INSTUI-4273
  • Loading branch information
joyenjoyer committed Feb 10, 2025
1 parent 4dacbf8 commit 98adf34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ describe('<ColorPreset />', () => {

testColors.forEach((testColor, index) => {
const tooltip = tooltips[index]
const indicator = indicators[index]

expect(tooltip.getAttribute('id')).toBe(
indicator.getAttribute('aria-describedby')
)
expect(tooltip).toHaveTextContent(testColor)
})
})
Expand Down
28 changes: 24 additions & 4 deletions packages/ui-color-picker/src/ColorPreset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
cursor={this.props.disabled ? 'not-allowed' : 'auto'}
as="button"
{...(selectOnClick ? { onClick: () => this.props.onSelect(color) } : {})}
{...(this.isSelectedColor(color) ? { 'aria-label': 'selected' } : {})}
{...{
'aria-label': `${color}${
this.isSelectedColor(color) ? ' selected' : ''
}`
}}
>
<div>
<ColorIndicator color={color} shape="rectangle" role="presentation" />
Expand All @@ -282,9 +286,25 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
</View>
)

renderIndicatorTooltip = (child: React.ReactElement, color: string) => (
<Tooltip renderTip={<div>{color}</div>}>{child}</Tooltip>
)
renderIndicatorTooltip = (child: React.ReactElement, color: string) => {
return (
<Tooltip
renderTip={<div>{color}</div>}
elementRef={(element) => {
if (
element &&
element.firstElementChild instanceof HTMLButtonElement
) {
// The tooltip and the button's aria-label has the same text content. This is redundant for screenreaders.
// Aria-describedby is removed to bypass reading the tooltip twice
element.firstElementChild.removeAttribute('aria-describedby')
}
}}
>
{child}
</Tooltip>
)
}

renderSettingsMenu = (color: string, index: number) => (
<Drilldown
Expand Down

0 comments on commit 98adf34

Please sign in to comment.