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
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4021706
Reviewed-by: Nate Fischer <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: Mason Freed <[email protected]>
Reviewed-by: Joey Arhar <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1071760}
  • Loading branch information
mfreed7 authored and chromium-wpt-export-bot committed Nov 15, 2022
1 parent d251ba1 commit 3c338f5
Show file tree
Hide file tree
Showing 7 changed files with 40 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:[email protected]">
<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
34 changes: 34 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,37 @@ 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. However, a check is made for open
// <dialog open> elements.
if (p instanceof HTMLDialogElement && p.hasAttribute('open'))
return;
switch (p.popover) {
case 'auto':
if (!document.querySelector('[popover]:open'))
p.showPopover();
return;
case 'manual':
p.showPopover();
return;
default:
assert_unreached(`Unknown popover type ${p.popover}`);
}
});
}
if (document.readyState === 'complete') {
show();
} else {
window.addEventListener('load',show,{once:true});
}
}

0 comments on commit 3c338f5

Please sign in to comment.