Skip to content

fix: add aria-describedby attribute to read out tooltip on focus #3134

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/tooltip/definition-tooptip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { PopoverContainer } from "carbon-components-angular/popover";
class="cds--definition-term"
[attr.aria-controls]="id"
[attr.aria-expanded]="isOpen"
[attr.aria-describedby]="isOpen ? id : null"
(blur)="onBlur($event)"
(click)="onClick($event)"
type="button">
Expand All @@ -37,9 +38,9 @@ import { PopoverContainer } from "carbon-components-angular/popover";
*ngIf="description"
class="cds--popover"
[id]="id"
[attr.aria-hidden]="isOpen"
[attr.aria-hidden]="!isOpen"
role="tooltip">
<span class="cds--popover-content cds--definition-tooltip">
<span class="cds--popover-content cds--definition-tooltip" aria-live="polite">
<ng-container *ngIf="!isTemplate(description)">{{description}}</ng-container>
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description" [ngTemplateOutletContext]="{ $implicit: templateContext }"></ng-template>
<span *ngIf="autoAlign" class="cds--popover-caret cds--popover--auto-align"></span>
Expand All @@ -62,6 +63,8 @@ export class TooltipDefinition extends PopoverContainer {
*/
@Input() templateContext: any;

@Input() openOnHover = false;

constructor(
protected elementRef: ElementRef,
protected ngZone: NgZone,
Expand Down Expand Up @@ -94,6 +97,18 @@ export class TooltipDefinition extends PopoverContainer {
this.handleChange(false, event);
}

@HostListener("mouseenter", ["$event"])
mouseenter(event) {
if (this.openOnHover) {
this.handleChange(true, event);
}
}

@HostListener("focusin", ["$event"])
onFocus(event) {
this.handleChange(true, event);
}

public isTemplate(value) {
return value instanceof TemplateRef;
}
Expand Down
2 changes: 2 additions & 0 deletions src/tooltip/definition-tooptip.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const Template = (args) => ({
<p>Custom domains direct requests for your apps in this Cloud Foundry organization to a
<cds-tooltip-definition
[isOpen]="isOpen"
[openOnHover]="openOnHover"
[caret]="caret"
[align]="align"
(onOpen)="onOpen($event)"
Expand Down Expand Up @@ -101,6 +102,7 @@ const AutoAlignTemplate = (args) => ({
<p>Custom domains direct requests for your apps in this Cloud Foundry organization to a
<cds-tooltip-definition
[isOpen]="isOpen"
[openOnHover]="openOnHover"
[caret]="caret"
[align]="align"
[autoAlign]="true"
Expand Down
Loading