mirror of
https://github.com/bitwarden/clients.git
synced 2025-12-05 19:17:06 -06:00
* add back the aria-label when using the a11y title directive * add comment about why aria-label is being added back * fix storybook a11y tests * pass undefined to util function
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { Directive, effect, ElementRef, inject } from "@angular/core";
|
|
|
|
import { TooltipDirective } from "../tooltip/tooltip.directive";
|
|
|
|
import { setA11yTitleAndAriaLabel } from "./set-a11y-title-and-aria-label";
|
|
|
|
/**
|
|
* @deprecated This function is deprecated in favor of `bitTooltip`.
|
|
* Please use `bitTooltip` instead.
|
|
*
|
|
* Directive that provides accessible tooltips by internally using TooltipDirective.
|
|
* This maintains the appA11yTitle API while leveraging the enhanced tooltip functionality.
|
|
*/
|
|
@Directive({
|
|
selector: "[appA11yTitle]",
|
|
hostDirectives: [
|
|
{
|
|
directive: TooltipDirective,
|
|
inputs: ["bitTooltip: appA11yTitle", "tooltipPosition"],
|
|
},
|
|
],
|
|
})
|
|
export class A11yTitleDirective {
|
|
private readonly elementRef = inject(ElementRef<HTMLElement>);
|
|
private readonly tooltipDirective = inject(TooltipDirective);
|
|
|
|
constructor() {
|
|
const originalAriaLabel = this.elementRef.nativeElement.getAttribute("aria-label");
|
|
|
|
// setting aria-label as a workaround for testing purposes. Should be removed once tests are updated to check element content.
|
|
effect(() => {
|
|
setA11yTitleAndAriaLabel({
|
|
element: this.elementRef.nativeElement,
|
|
title: undefined,
|
|
label: originalAriaLabel ?? this.tooltipDirective.tooltipContent(),
|
|
});
|
|
});
|
|
}
|
|
}
|