Skip to content

Commit ab2e70a

Browse files
Improve compat notes and behavior on popover-hint demo (#329)
* Improve compat notes and behavior on popover-hint demo * Updates for pepelsbey review comments * Implement Vadim suggestion
1 parent c473ca3 commit ab2e70a

File tree

2 files changed

+61
-30
lines changed

2 files changed

+61
-30
lines changed

popover-api/popover-hint/index.css

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66

77
html {
8-
font-family: sans-serif;
8+
font-family: system-ui;
99
height: 100%;
1010
overflow: hidden;
1111
}
@@ -14,20 +14,20 @@ body {
1414
height: inherit;
1515
background: #ccc;
1616
margin: 0;
17-
}
18-
19-
#wrapper {
20-
height: inherit;
2117
display: flex;
2218
justify-content: center;
2319
align-items: center;
2420
}
2521

22+
#wrapper {
23+
width: 60%;
24+
max-width: 500px;
25+
}
26+
2627
/* Button bar styling */
2728

2829
#button-bar {
2930
height: 48px;
30-
width: 30%;
3131
min-width: 300px;
3232
padding: 8px;
3333
border-radius: 6px;
@@ -36,6 +36,8 @@ body {
3636
display: flex;
3737
justify-content: space-around;
3838
gap: 10px;
39+
z-index: 2;
40+
position: relative;
3941
}
4042

4143
/* Button styling */
@@ -126,11 +128,24 @@ body {
126128
margin: 0;
127129
padding: 16px;
128130
box-shadow: 1px 1px 3px #999;
131+
z-index: 1;
132+
}
133+
134+
.help-para p {
135+
margin: 0;
136+
}
137+
138+
.help-para p:first-child {
139+
margin-bottom: 1rem;
129140
}
130141

131142
@media (max-width: 640px) {
132143
.help-para {
133144
width: auto;
134145
right: 16px;
135146
}
147+
148+
#wrapper {
149+
width: 90%;
150+
}
136151
}

popover-api/popover-hint/index.html

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,64 @@
1515
popovertargetaction="toggle"
1616
id="menu-1">
1717
Menu A
18+
<div id="tooltip-1" class="tooltip" popover="hint">Tooltip A</div>
1819
</button>
1920

2021
<button
2122
popovertarget="submenu-2"
2223
popovertargetaction="toggle"
2324
id="menu-2">
2425
Menu B
26+
<div id="tooltip-2" class="tooltip" popover="hint">Tooltip B</div>
2527
</button>
2628

2729
<button
2830
popovertarget="submenu-3"
2931
popovertargetaction="toggle"
3032
id="menu-3">
3133
Menu C
34+
<div id="tooltip-3" class="tooltip" popover="hint">Tooltip C</div>
3235
</button>
36+
37+
<div id="submenu-1" popover="auto">
38+
<button>Option A</button><br /><button>Option B</button>
39+
</div>
40+
<div id="submenu-2" popover="auto">
41+
<button>Option A</button><br /><button>Option B</button>
42+
</div>
43+
<div id="submenu-3" popover="auto">
44+
<button>Option A</button><br /><button>Option B</button>
45+
</div>
3346
</section>
3447
</div>
3548

36-
<p class="help-para">
37-
Press the buttons to show the auto popovers. Hover or focus the buttons to
38-
show the hint popovers. When an auto popover is shown, you can show the
39-
hint popovers without hiding it. See
40-
<a
41-
href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API/Using#using_hint_popover_state"
42-
>Using "hint" popover state</a
43-
>
44-
for more information. Note that in non-supporting browsers, the position
45-
of the popovers is broken.
46-
</p>
47-
48-
<div id="submenu-1" popover="auto">
49-
<button>Option A</button><br /><button>Option B</button>
50-
</div>
51-
<div id="submenu-2" popover="auto">
52-
<button>Option A</button><br /><button>Option B</button>
49+
<div class="help-para">
50+
<p>
51+
Press the buttons to show the auto popovers. Hover or focus the buttons
52+
to show the hint popovers. When an auto popover is shown, you can show
53+
the hint popovers without hiding it. See
54+
<a
55+
href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API/Using#using_hint_popover_state"
56+
>Using "hint" popover state</a
57+
>
58+
for more information.
59+
</p>
60+
<p>
61+
Note that this demo uses both hint popovers and CSS anchor positioning.
62+
Browsers that don't support the former will experience different tooltip
63+
behavior. Browsers that don't support the latter will not see the menus
64+
and tooltips appear in the correct position relative to each button on
65+
the button bar. Check browser support for
66+
<a
67+
href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/popover#browser_compatibility"
68+
>hint popovers</a
69+
>
70+
and
71+
<a
72+
href="https://developer.mozilla.org/en-US/docs/Web/CSS/position-anchor#browser_compatibility"
73+
>anchor-positioning</a
74+
>.
75+
</p>
5376
</div>
54-
<div id="submenu-3" popover="auto">
55-
<button>Option A</button><br /><button>Option B</button>
56-
</div>
57-
58-
<div id="tooltip-1" class="tooltip" popover="hint">Tooltip A</div>
59-
<div id="tooltip-2" class="tooltip" popover="hint">Tooltip B</div>
60-
<div id="tooltip-3" class="tooltip" popover="hint">Tooltip C</div>
6177
</body>
6278
</html>

0 commit comments

Comments
 (0)