Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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,20 @@ body {
height: inherit;
background: #ccc;
margin: 0;
}

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

#wrapper {
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 +36,8 @@ body {
display: flex;
justify-content: space-around;
gap: 10px;
z-index: 2;
position: relative;
}

/* 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;
}

.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%;
}
}
67 changes: 43 additions & 24 deletions popover-api/popover-hint/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,65 @@
Menu A
</button>

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

<button
popovertarget="submenu-2"
popovertargetaction="toggle"
id="menu-2">
Menu B
</button>

<div id="tooltip-2" class="tooltip" popover="hint">Tooltip B</div>

<button
popovertarget="submenu-3"
popovertargetaction="toggle"
id="menu-3">
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="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.

If you put the tooltips inside buttons, it falls back nicely!

Image
Suggested change
<div id="tooltip-3" class="tooltip" popover="hint">Tooltip C</div>
<button
popovertarget="submenu-1"
popovertargetaction="toggle"
id="menu-1">
Menu A
<div id="tooltip-1" class="tooltip" popover="hint">Tooltip A</div>
</button>
<button
popovertarget="submenu-2"
popovertargetaction="toggle"
id="menu-2">
Menu B
<div id="tooltip-2" class="tooltip" popover="hint">Tooltip B</div>
</button>
<button
popovertarget="submenu-3"
popovertargetaction="toggle"
id="menu-3">
Menu C
<div id="tooltip-3" class="tooltip" popover="hint">Tooltip C</div>
</button>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you put the tooltips inside buttons, it falls back nicely!

Ah yes, the tooltips certainly sit more nicely. The menus are still a bit broken, but it is better than before.


<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="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>
</section>
</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>