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

hidePopover with button click not timeout #10469

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 6 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
38 changes: 15 additions & 23 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -84774,32 +84774,24 @@ dictionary <dfn dictionary>DragEventInit</dfn> : <span>MouseEventInit</span> {
the user. The following demonstrates how one could reveal a popover in an <code>output</code>
element.</p>

<pre><code class="html">&lt;button id=submit>Submit&lt;/button>
&lt;p>&lt;output>&lt;span popover=manual>&lt;/span>&lt;/output>&lt;/p>
<pre><code class="html">&lt;img id="image" src="cat.js" alt="pretty kitten">
&lt;div id="tooltip" popover>
Jxck marked this conversation as resolved.
Show resolved Hide resolved
&lt;p>&lt;/p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code had the popover inside of the <output> element instead of having the popover outside of the <output>, but I'm not sure if that means anything with regards to the semantics of the <output> element.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, but it's out of scope for here.
I'll remove it.

Jxck marked this conversation as resolved.
Show resolved Hide resolved
&lt;button popovertarget="message" popovertargetaction="hide">x&lt;/button>
&lt;/div>

&lt;script>
const sBtn = document.getElementById("submit");
const outSpan = document.querySelector("output [popover=manual]");
let successMessage;
let errorMessage;

/* define logic for determining success of action
and determining the appropriate success or error
messages to use */

sBtn.addEventListener("click", ()=> {
if ( success ) {
outSpan.textContent = successMessage;
}
else {
outSpan.textContent = errorMessage;
}
outSpan.showPopover();
const img = document.querySelector("#image")
const tooltip = document.querySelector("#tooltip")
const p = tooltip.querySelector("p")

setTimeout(function () {
outSpan.hidePopover();
}, 10000);
});
$img.addEventListener("pointerover", () => {
Jxck marked this conversation as resolved.
Show resolved Hide resolved
Jxck marked this conversation as resolved.
Show resolved Hide resolved
$p.textContent = $img.alt
$tooltip.showPopover()
})
$img.addEventListener("pointerleave", () => {
Jxck marked this conversation as resolved.
Show resolved Hide resolved
$tooltip.hidePopover()
})
&lt;/script></code></pre>
</div>

Expand Down