Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Improve compat notes and behavior on popover-hint demo
  • Loading branch information
chrisdavidmills committed Aug 28, 2025
commit f48d78036c8e3a1d533e5b13d941ac48e5f8bead
28 changes: 22 additions & 6 deletions popover-api/popover-hint/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

html {
font-family: sans-serif;
font-family: system-ui;
height: 100%;
overflow: hidden;
}
Expand All @@ -14,20 +14,21 @@ body {
height: inherit;
background: #ccc;
margin: 0;
}

#wrapper {
height: inherit;
display: flex;
justify-content: center;
align-items: center;
}

#wrapper {
position: relative;
width: 60%;
max-width: 500px;
}

/* Button bar styling */

#button-bar {
height: 48px;
width: 30%;
min-width: 300px;
padding: 8px;
border-radius: 6px;
Expand All @@ -36,6 +37,7 @@ body {
display: flex;
justify-content: space-around;
gap: 10px;
z-index: 1;
}

/* Button styling */
Expand All @@ -61,6 +63,7 @@ body {
[popover="auto"] {
inset: unset;
position: absolute;
bottom: 0;
bottom: calc(anchor(top) + 20px);
justify-self: anchor-center;
margin: 0;
Expand Down Expand Up @@ -126,11 +129,24 @@ body {
margin: 0;
padding: 16px;
box-shadow: 1px 1px 3px #999;
z-index: -1;
Copy link
Member

Choose a reason for hiding this comment

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

This line makes the paragraph unreachable to the cursor, as it’s hidden behind the body: no text selection, no link clicking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, crap, that was foolish! In my next commit I have adjusted the z-index values to fix this issue.

}

.help-para p {
margin: 0;
}

.help-para p:first-child {
margin-bottom: 1rem;
}

@media (max-width: 640px) {
.help-para {
width: auto;
right: 16px;
}

#wrapper {
width: 90%;
}
}
64 changes: 40 additions & 24 deletions popover-api/popover-hint/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,48 @@
Menu C
</button>
</section>
</div>

<p class="help-para">
Press the buttons to show the auto popovers. Hover or focus the buttons to
show the hint popovers. When an auto popover is shown, you can show the
hint popovers without hiding it. See
<a
href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API/Using#using_hint_popover_state"
>Using "hint" popover state</a
>
for more information. Note that in non-supporting browsers, the position
of the popovers is broken.
</p>
<div id="submenu-1" popover="auto">
<button>Option A</button><br /><button>Option B</button>
</div>
<div id="submenu-2" popover="auto">
<button>Option A</button><br /><button>Option B</button>
</div>
<div id="submenu-3" popover="auto">
<button>Option A</button><br /><button>Option B</button>
</div>

<div id="submenu-1" popover="auto">
<button>Option A</button><br /><button>Option B</button>
</div>
<div id="submenu-2" popover="auto">
<button>Option A</button><br /><button>Option B</button>
</div>
<div id="submenu-3" popover="auto">
<button>Option A</button><br /><button>Option B</button>
<div id="tooltip-1" class="tooltip" popover="hint">Tooltip A</div>
<div id="tooltip-2" class="tooltip" popover="hint">Tooltip B</div>
<div id="tooltip-3" class="tooltip" popover="hint">Tooltip C</div>
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest putting tooltips right next to the buttons they’re triggered by. First of all, this is something you would most likely do in a real-world component to contain everything. Second, it might help to position them next to the buttons as a fallback for browsers that don’t support the hint value yet:

<button
  popovertarget="submenu-1"
  popovertargetaction="toggle"
  id="menu-1">
  Menu A
</button>

<div id="tooltip-1" class="tooltip" popover="hint">
  Tooltip A
</div>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done that, experimented with moving the HTML around a bit more besides, and made a few CSS adjustments, but I still can't make it work particularly well in browsers that don't support anchor positioning. Do you have any suggestions?

</div>

<div id="tooltip-1" class="tooltip" popover="hint">Tooltip A</div>
<div id="tooltip-2" class="tooltip" popover="hint">Tooltip B</div>
<div id="tooltip-3" class="tooltip" popover="hint">Tooltip C</div>
<div class="help-para">
<p>
Press the buttons to show the auto popovers. Hover or focus the buttons
to show the hint popovers. When an auto popover is shown, you can show
the hint popovers without hiding it. See
<a
href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API/Using#using_hint_popover_state"
>Using "hint" popover state</a
>
for more information.
</p>
<p>
Note that this demo uses both hint popovers and CSS anchor positioning.
Browsers that don't support the former will experience different tooltip
behavior. Browsers that don't support the latter will not see the menus
and tooltips appear in the correct position relative to each button on
the button bar. Check browser support for
<a
href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/popover#browser_compatibility"
>hint popovers</a
>
and
<a
href="https://developer.mozilla.org/en-US/docs/Web/CSS/position-anchor#browser_compatibility"
>anchor-positioning</a
>.
</p>
</div>
</body>
</html>