Skip to content

Commit

Permalink
fix(primefaces#16630): ensure aria-describedby is dynamically set and…
Browse files Browse the repository at this point in the history
… removed for tooltip

This fix improves accessibility by maintaining proper ARIA relationships for tooltips.

- Added `setAriaDescribedBy` to dynamically set `aria-describedby` attribute on the target element when the tooltip is created.
- Added `removeAriaDescribedBy` to remove the `aria-describedby` attribute when the tooltip is removed.
  • Loading branch information
Martin Schmitz committed Nov 29, 2024
1 parent c2556eb commit 33cff6f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/app/components/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ export class Tooltip implements AfterViewInit, OnDestroy {
});
}
}

setAriaDescribedBy() {
const tooltipId = this.getOption('id');
if (tooltipId && this.active) {
this.renderer.setAttribute(this.el.nativeElement, 'aria-describedby', tooltipId);
}
}

removeAriaDescribedBy() {
this.renderer.removeAttribute(this.el.nativeElement, 'aria-describedby');
}


ngOnChanges(simpleChange: SimpleChanges) {
if (simpleChange.tooltipPosition) {
Expand Down Expand Up @@ -423,6 +435,8 @@ export class Tooltip implements AfterViewInit, OnDestroy {
this.container.style.pointerEvents = 'unset';
this.bindContainerMouseleaveListener();
}

this.setAriaDescribedBy();
}

bindContainerMouseleaveListener() {
Expand Down Expand Up @@ -705,6 +719,7 @@ export class Tooltip implements AfterViewInit, OnDestroy {
this.unbindScrollListener();
this.unbindContainerMouseleaveListener();
this.clearTimeouts();
this.removeAriaDescribedBy();
this.container = null;
this.scrollHandler = null;
}
Expand Down

0 comments on commit 33cff6f

Please sign in to comment.