Skip to content
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

IconButton: Put tooltip text as aria-label #36760

Merged
merged 3 commits into from
Jul 22, 2021

Conversation

tskarhed
Copy link
Contributor

What this PR does / why we need it:
A lot of IconButtons don't have an aria-label property, but has a tooltip. This is inaccessible and Axe complains about it. Until we can make Tooltips a very accessible solution that possibly covers this use case, I'd suggest doing this.

@tskarhed tskarhed added the type/accessibility Accessibility problem / enhancement label Jul 14, 2021
@tskarhed tskarhed requested review from a team and mckn and removed request for a team July 14, 2021 14:43
@tskarhed tskarhed requested a review from oscarkilhed July 14, 2021 14:43
@tskarhed tskarhed mentioned this pull request Jul 14, 2021
28 tasks
@@ -36,7 +36,7 @@ export const IconButton = React.forwardRef<HTMLButtonElement, Props>(
const styles = getStyles(theme, size, variant);

const button = (
<button ref={ref} {...restProps} className={cx(styles.button, className)}>
<button ref={ref} aria-label={tooltip} {...restProps} className={cx(styles.button, className)}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is the best solution, most icon buttons don't have tooltip, so they still won't be accessible, I think a better way would be to add aria-label prop to the component, so the consumers could provide the labels according to their use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about taking the tooltip if there is no aria-label? That way we cover a lot of cases that already exist. You can always override it through restProps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that tooltip doesn't always correctly represent the button, content. For example when it's some help text, also sometimes tooltips are an html content (not in this case but might happen in the future). Could be an edge case though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it fits the use case for an icon button. Icon buttons are minimalist and should fit a very specific action. Maybe we can add guidelines about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the BEST approach, but using https://benjaminjohnson.me/blog/accessible-icon-buttons as a reference, probably adding a required label prop, adding its content next to the icon, and "hiding" the text to non-screenreader users via css might be a good approach. wdyt?

big plus imho: an accessible description of the "action" will be required

Copy link
Contributor

@gabor gabor Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be interesting to go through a couple well known websites and see how they deal with icon-only buttons, it seems to me the web is full of them :-)
i did a quick check on gmail/google-sheets, and they went with aria-label, the github formatting tools right above the text i am writing right now do the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Clarity-89 true, then i see no problem in having it optional. maybe we can log a warning in the console before 9.0 if the props isn't used? not sure if we can add a linter rule for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabor that's interesting, somehow i always thought using aria-label wasn't the proper way to solve this specific use case, but reading more about the subject it seems it actually is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Elfo404 yeah an optional property with a warning sounds good imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the big issue here is that our tooltips are not WCAG compliant, otherwise they would've served this purpose.

@tskarhed tskarhed added this to the 8.1.0 milestone Jul 15, 2021
@zserge zserge modified the milestones: 8.1.0-beta1, 8.1.0 Jul 22, 2021
Copy link
Contributor

@ashharrison90 ashharrison90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my 2c - although you can already specify an aria-label via restProps, think it makes sense to have a specific optional prop as it's more likely to remind a consumer to actually set it.

in terms of using tooltip, i think that would be fine as a backup. e.g. aria-label={ariaLabel ?? tooltip}. i agree with previous comments that it's not the best, but it's definitely better than nothing.

Copy link
Contributor

@ashharrison90 ashharrison90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 🙌

@tskarhed tskarhed merged commit 8af83b8 into grafana:main Jul 22, 2021
@tskarhed tskarhed deleted the iconbutton-label branch July 22, 2021 12:15
@wbrowne wbrowne added the old backport v8.1.x Mark PR for automatic backport to v8.1.x label Jul 23, 2021
grafanabot pushed a commit that referenced this pull request Jul 23, 2021
* Make tooltip prop aria-label

* Add ariaLabel prop

(cherry picked from commit 8af83b8)
tskarhed added a commit that referenced this pull request Jul 23, 2021
* Make tooltip prop aria-label

* Add ariaLabel prop

(cherry picked from commit 8af83b8)

Co-authored-by: Tobias Skarhed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend old backport v8.1.x Mark PR for automatic backport to v8.1.x type/accessibility Accessibility problem / enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants