Skip to content

Commit

Permalink
Merge pull request #199 from oddbird/dialog
Browse files Browse the repository at this point in the history
Add support for dialog popovers.
  • Loading branch information
jgerigmeyer authored Apr 25, 2024
2 parents 4b7df19 + 83b7213 commit bcfc8d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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();
});

0 comments on commit bcfc8d8

Please sign in to comment.