Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dialog popovers. #199

Merged
merged 1 commit into from
Apr 25, 2024
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
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h1>Popover Attribute Polyfill</h1>
Menu with shadowed popover
<div id="menu-host"></div>
</div>
<dialog popover>I'm a dialog!</dialog>
<dialog id="dialog" popover>This is a dialog</dialog>
<div id="host"></div>

<script type="module">
Expand Down Expand Up @@ -137,6 +137,7 @@ <h1>Popover Attribute Polyfill</h1>
<button popovertarget="menu-with-shadowed-popover">
Toggle menu with shadowed nested popover
</button>
<button popovertarget="dialog">Click to toggle dialog</button>

<script type="module">
const shadowInInvoker = document.getElementById('shadowInInvoker');
Expand Down
12 changes: 8 additions & 4 deletions src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ ${useLayer ? '@layer popover-polyfill {' : ''}
margin: auto;
}

:where([popover]:not(.\\:popover-open)) {
display: none;
}

:where(dialog[popover].\\:popover-open) {
display: block;
}

:where(dialog[popover][open]) {
display: revert;
}
Expand Down Expand Up @@ -105,10 +113,6 @@ ${useLayer ? '@layer popover-polyfill {' : ''}
bottom: 0;
}
}

:where([popover]:not(.\\:popover-open)) {
display: none;
}
${useLayer ? '}' : ''}
`;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ test('popover as "invalid"', async ({ page }) => {
const popover = (await page.locator('#popover6')).nth(0);
await expect(popover).toBeFunctionalPopover();
});

test('dialog popover', async ({ page }) => {
const popover = (await page.locator('#dialog')).nth(0);
await expect(popover).toBeFunctionalPopover();
});