Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-web-components/Badge 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-web-components/Badge. - Dark Mode.normal.chromium.png 443 Changed
vr-tests-web-components/MenuList 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-web-components/MenuList. - RTL.2nd selected.chromium.png 17 Changed
vr-tests-web-components/MenuList. - RTL.normal.chromium_1.png 39083 Changed
vr-tests-web-components/TextInput 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-web-components/TextInput. - Dark Mode.normal.chromium_1.png 288 Changed

"type": "prerelease",
"comment": "remove tooltip id from target’s aria-describedby attribute when the tooltip is removed from DOM",
"packageName": "@fluentui/web-components",
"email": "machi@microsoft.com",
"dependentChangeType": "patch"
}
23 changes: 23 additions & 0 deletions packages/web-components/src/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ test.describe('Tooltip', () => {
await expect(button).toHaveAttribute('aria-describedby', id);
});

test('should remove the tooltip id from `aria-describedby` attribute when tooltip is removed', async ({
fastPage,
}) => {
const { element, page } = fastPage;
const button = page.locator('button');

await fastPage.setTemplate(/* html */ `
<div style="position: absolute; inset: 200px">
<button id="target">Target</button>
<${tagName} anchor="target">This is a tooltip</${tagName}>
<${tagName} anchor="target">This is another tooltip</${tagName}>
</div>
`);

const id2 = await element.nth(1).evaluate((node: Tooltip) => node.id);

await element.nth(0).evaluate(node => {
node.remove();
});

await expect(button).toHaveAttribute('aria-describedby', id2);
});

test('should not be visible by default', async ({ fastPage }) => {
const { element } = fastPage;

Expand Down
16 changes: 15 additions & 1 deletion packages/web-components/src/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,25 @@ export class Tooltip extends FASTElement {
}

public disconnectedCallback(): void {
super.disconnectedCallback();
this.anchorElement?.removeEventListener('focus', this.focusAnchorHandler);
this.anchorElement?.removeEventListener('blur', this.blurAnchorHandler);
this.anchorElement?.removeEventListener('mouseenter', this.mouseenterAnchorHandler);
this.anchorElement?.removeEventListener('mouseleave', this.mouseleaveAnchorHandler);

if (this.anchorElement) {
const describedBy = this.anchorElement.getAttribute('aria-describedby') ?? '';
const ids = describedBy
.trim()
.split(/\s+/)
.filter(id => id !== this.id);
if (ids.length) {
this.anchorElement.setAttribute('aria-describedby', ids.join(' '));
} else {
this.anchorElement.removeAttribute('aria-describedby');
}
}

super.disconnectedCallback();
}

/**
Expand Down
Loading