Skip to content

fix(tooltip): improve accessibility #4688

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

Closed
wants to merge 7 commits into from

Conversation

andrewseguin
Copy link
Contributor

  • Show on trigger focus
  • Hide on trigger blur
  • Hide on escape when trigger has focus
  • Add aria tooltip role for tooltip
  • Add aria describedby role for trigger

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 19, 2017
@andrewseguin
Copy link
Contributor Author

Looking into the test failures, not sure why the instance isnt being removed right.

@@ -58,7 +58,11 @@ export function throwMdTooltipInvalidPositionError(position: string) {
selector: '[md-tooltip], [mdTooltip], [mat-tooltip], [matTooltip]',
host: {
'(longpress)': 'show()',
'(focus)': 'show()',
'(blur)': 'hide(0)',
'(keydown.esc)': 'hide(0)',
Copy link
Member

Choose a reason for hiding this comment

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

Can't use keydown.xxx syntax because it's not supported in Safari 9 (Angular uses KeyboardEvent.key for this). You'll need to just handle keydown and check the keycode.

You'll also need to check whether the tooltip is actually present, and call stopPropagation if it. This is necessary in cases where you have something like a tooltip inside of a dialog; you only want to dismiss the tooltip without closing the dialog.

'(touchend)': 'hide(' + TOUCHEND_HIDE_DELAY + ')',
'[attr.aria-describedby]': '_getTooltipId()'
Copy link
Member

Choose a reason for hiding this comment

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

This needs to avoid clobbering an existing aria-describedby


/** Returns the trigger's aria-describedby attribute. */
private _getAriaDescribedby(): string {
return this._elementRef.nativeElement.getAttribute('aria-describedby');
Copy link
Member

Choose a reason for hiding this comment

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

This one is technically safe from throwing an error in Universal, because it's after a user interaction, but it might be better if we used an @Input anyway.

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 agree except I think we need would need this anyways since we're checking if the current tooltip matches the aria-describedby and an Input@ won't capture our setter's interaction.

flushMicrotasks
flushMicrotasks,
TestBed,
tick
Copy link
Member

Choose a reason for hiding this comment

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

Needs a trailing comma here and on line 14.

@@ -1,4 +1,6 @@
<div class="mat-tooltip"
role="tooltip"
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this example of an accessible tooltip, it looks like we need to toggle aria-hidden, in addition to the role and aria-describedby.

}

/** Sets the trigger's aria-describedby attribute. */
private _setAriaDescribedBy(ariaDescribedby: string) {
Copy link
Member

Choose a reason for hiding this comment

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

This one could be replaced with an attribute binding.

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 had that at first but we saw that it would clobber any existing aria-describedby attribute that the user may have set. We want to only apply the tooltip's id as aria-describedby if there isn't already one set.

@jelbourn jelbourn changed the title fix(tooltip): add accessibility standards fix(tooltip): improve accessibility May 23, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants