Skip to content

Commit 52ce245

Browse files
Refactor mention popup to use the popover API and focusable buttons for keyboard nav
1 parent b10cb5b commit 52ce245

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

opaque-range/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ <h3>Input</h3>
4747
<input type="text" id="input-popup" placeholder="Type : to show the emoji picker...">
4848
</div>
4949

50-
<div id="mention-popup" class="popup" hidden>
50+
<div id="mention-popup" class="popup" popover>
5151
<ul>
52-
<li data-emoji="👍">👍 thumbs up</li>
53-
<li data-emoji="❤️">❤️ heart</li>
54-
<li data-emoji="😂">😂 laugh</li>
55-
<li data-emoji="🎉">🎉 celebrate</li>
52+
<li data-emoji="👍"><button>👍 thumbs up</button></li>
53+
<li data-emoji="❤️"><button>❤️ heart</button></li>
54+
<li data-emoji="😂"><button>😂 laugh</button></li>
55+
<li data-emoji="🎉"><button>🎉 celebrate</button></li>
5656
</ul>
5757
</div>
5858
</section>

opaque-range/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ function showMentionPopup(element) {
3131

3232
mentionPopup.style.left = `${rect.left}px`;
3333
mentionPopup.style.top = `${rect.bottom + 4}px`;
34-
mentionPopup.hidden = false;
34+
mentionPopup.showPopover({ source: element });
3535
mentionTriggerField = element;
3636
}
3737

3838
function hideMentionPopup() {
39-
mentionPopup.hidden = true;
39+
mentionPopup.hidePopover();
4040
mentionTriggerField = null;
4141
}
4242

opaque-range/style.css

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ input[type="text"]:focus {
109109
/* Mention popup */
110110
.popup {
111111
position: fixed;
112-
z-index: 1000;
112+
margin: 0;
113113
background: #fff;
114114
border: 1px solid #ccc;
115115
border-radius: 6px;
@@ -120,16 +120,24 @@ input[type="text"]:focus {
120120
.popup ul {
121121
list-style: none;
122122
margin: 0;
123-
padding: 0.25rem 0;
123+
padding: 0;
124124
}
125125

126-
.popup li {
126+
.popup button {
127+
display: block;
128+
width: 100%;
129+
text-align: start;
130+
border-radius: 0;
131+
margin: 0;
132+
background: none;
133+
border: none;
134+
font-family: inherit;
127135
padding: 0.4rem 0.75rem;
128136
cursor: pointer;
129137
font-size: 0.95rem;
130138
}
131139

132-
.popup li:hover {
140+
.popup button:hover {
133141
background: #e8f0fe;
134142
}
135143

0 commit comments

Comments
 (0)