-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ui-color-picker): add hex to aria-label #1857
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" /> | ||
|
@@ -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 ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the color is selected, I append the 'selected' text to the hex code so the user gets information about that through the screenreader.