Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Renderer2 } from "@angular/core";

class MockTooltipComponent {
descriptionId = "mock-tooltip-id";
isOpen = jest.fn(() => false);
isContentHovered = jest.fn(() => false);
timeoutDelay = jest.fn(() => 100);
hideTimeout?: ReturnType<typeof setTimeout>;
Expand Down Expand Up @@ -227,25 +226,13 @@ describe("TooltipTriggerComponent", () => {
expect(btn.getAttribute("tabindex")).toBe("2");
});

it("should set ARIA attributes on interactive element when closed", () => {
it("should set aria-describedby on interactive element", () => {
hostEl.innerHTML = `<button>Click me</button>`;
const btn = hostEl.querySelector("button")!;
component.ngAfterContentChecked();
fixture.detectChanges();

expect(btn.getAttribute("aria-describedby")).toBe("mock-tooltip-id");
expect(btn.getAttribute("aria-expanded")).toBe("false");
});

it("should set aria-expanded to true when tooltip is open", () => {
tooltip.isOpen = jest.fn(() => true);
hostEl.innerHTML = `<button>Click me</button>`;
const btn = hostEl.querySelector("button")!;
component.ngAfterContentChecked();
fixture.detectChanges();

expect(btn.getAttribute("aria-describedby")).toBe("mock-tooltip-id");
expect(btn.getAttribute("aria-expanded")).toBe("true");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ export class TooltipTriggerComponent implements AfterContentChecked {
const element = this.interactiveElement();
if (!element) return;

const descriptionId = this.tooltip.descriptionId;
const isOpen = this.tooltip.isOpen();

element.setAttribute("aria-describedby", descriptionId);
element.setAttribute("aria-expanded", String(isOpen));
element.setAttribute("aria-describedby", this.tooltip.descriptionId);
});
}

Expand Down