Skip to content
Closed
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
9 changes: 6 additions & 3 deletions packages/injected/src/domUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ function computeElementStyleVisibilityVisible(element: Element, style?: CSSStyle
return false;
} else {
// Manual workaround for WebKit that does not have checkVisibility.
const detailsOrSummary = element.closest('details,summary');
if (detailsOrSummary !== element && detailsOrSummary?.nodeName === 'DETAILS' && !(detailsOrSummary as HTMLDetailsElement).open)
return false;
// Check all ancestors: an open details inside a closed one is still hidden.
for (let child: Element | undefined = element; child; child = parentElementOrShadowHost(child)) {
const parent = parentElementOrShadowHost(child);
if (parent?.nodeName === 'DETAILS' && !(parent as HTMLDetailsElement).open && child.nodeName !== 'SUMMARY')
return false;
}
}
if (style.visibility !== 'visible')
return false;
Expand Down
15 changes: 15 additions & 0 deletions tests/page/locator-is-visible.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ it('isVisible and isHidden should work with details', async ({ page }) => {
await expect(page.locator('ul')).toBeHidden();
});

it('isVisible and isHidden should work with nested details', async ({ page }) => {
await page.setContent(`<details>
<summary>outer</summary>
<details open>
<summary>inner</summary>
<button>hidden button</button>
</details>
</details>`);

await expect(page.locator('summary', { hasText: 'outer' })).toBeVisible();
await expect(page.locator('summary', { hasText: 'inner' })).toBeHidden();
await expect(page.locator('button')).toBeHidden();
await expect(page.getByRole('button')).toHaveCount(0);
});

it('isVisible inside a button', async ({ page }) => {
await page.setContent(`<button><span></span>a button</button>`);
const span = page.locator('span');
Expand Down