Skip to content

Commit

Permalink
Remove the popover defaultopen attribute
Browse files Browse the repository at this point in the history
Per the [1] resolution, we have decided to remove this feature
for now, while we work on ways to make it more generic and
applicable to other elements such as `<details>` and `<dialog>`.

[1] openui/open-ui#631 (comment)

Bug: 1307772
Change-Id: I7bc385fcbe1fadfcdf83d2d65c2e46abc07cb8a4
  • Loading branch information
mfreed7 authored and chromium-wpt-export-bot committed Nov 12, 2022
1 parent a6e9e43 commit 2e4bf18
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 88 deletions.
5 changes: 5 additions & 0 deletions html/semantics/popovers/popover-anchor-display.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<link rel=author href="mailto:masonf@chromium.org">
<link rel=help href="https://open-ui.org/components/popup.research.explainer">
<link rel=match href="popover-anchor-display-ref.tentative.html">
<script src="resources/popover-utils.js"></script>

<p>There should be a green box attached to the right side of each orange box.</p>

Expand All @@ -24,6 +25,10 @@
<div id=popover3 popover=manual defaultopen></div>
</div>

<script>
showDefaultopenPopoversOnLoad();
</script>

<style>
.ex {
margin: 25px;
Expand Down
24 changes: 0 additions & 24 deletions html/semantics/popovers/popover-defaultopen-2.tentative.html

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions html/semantics/popovers/popover-defaultopen-display.tentative.html

This file was deleted.

44 changes: 0 additions & 44 deletions html/semantics/popovers/popover-defaultopen.tentative.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</style>

<script>
showDefaultopenPopoversOnLoad();
const isDialog = (ex) => ex instanceof HTMLDialogElement;
const isFullscreen = (ex) => ex.classList.contains('fullscreen');
function ensureIsOpenPopover(ex,message) {
Expand Down
31 changes: 31 additions & 0 deletions html/semantics/popovers/resources/popover-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,34 @@ async function blessTopLayer(visibleElement) {
await wait_click;
button.remove();
}
// This is a "polyfill" of sorts for the `defaultopen` attribute.
// It can be called before window.load is complete, and it will
// show defaultopen popovers according to the rules previously part
// of the popover API: any popover=manual popover can be shown this
// way, and only the first popover=auto popover.
function showDefaultopenPopoversOnLoad() {
function show() {
const popovers = Array.from(document.querySelectorAll('[popover][defaultopen]'));
popovers.forEach((p) => {
// The showPopover calls below aren't guarded by a check on the popover
// open/closed status. If they throw exceptions, this function was
// probably called at a bad time.
switch (p.popover) {
case 'auto':
if (!document.querySelector('[popover]:open')) {
p.showPopover();
}
break;
case 'manual':
p.showPopover();
default:
assert_notreached(`Unknown popover type ${p.popover}`);
}
});
}
if (document.readyState === 'complete') {
show();
} else {
window.addEventListener('load',show,{once:true});
}
}

0 comments on commit 2e4bf18

Please sign in to comment.