Skip to content

Commit b467128

Browse files
committed
feat(web-app): add clear search button to sidebar search
1 parent a86424c commit b467128

3 files changed

Lines changed: 79 additions & 5 deletions

File tree

web-app/css/styles.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,6 +3869,40 @@ textarea:focus-visible,
38693869
box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
38703870
}
38713871

3872+
.clear-search-btn {
3873+
position: absolute;
3874+
top: 50%;
3875+
right: 0.85rem;
3876+
transform: translateY(-50%);
3877+
width: 1.4rem;
3878+
height: 1.4rem;
3879+
border: none;
3880+
border-radius: 50%;
3881+
background: transparent;
3882+
color: var(--text-muted);
3883+
cursor: pointer;
3884+
display: flex;
3885+
align-items: center;
3886+
justify-content: center;
3887+
padding: 0;
3888+
transition: background-color 0.2s ease, color 0.2s ease;
3889+
z-index: 5;
3890+
}
3891+
3892+
.clear-search-btn:hover {
3893+
background: rgba(255, 255, 255, 0.08);
3894+
color: var(--text-color);
3895+
}
3896+
3897+
.clear-search-btn:focus-visible {
3898+
outline: 2px solid var(--accent-color);
3899+
outline-offset: 2px;
3900+
}
3901+
3902+
.search-box input {
3903+
padding-right: 3rem;
3904+
}
3905+
38723906
/* Search dropdown items — keyboard highlight */
38733907
.dropdown-item:focus-visible,
38743908
.dropdown-item.selected {
@@ -3946,6 +3980,7 @@ button:focus-visible,
39463980

39473981

39483982
.search-box {
3983+
position: relative;
39493984
max-width: none;
39503985
width: 100%;
39513986
}

web-app/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
<i class="fas fa-search" aria-hidden="true"></i>
6363
<input aria-label="Search projects" id="searchInput" placeholder="Search projects or tags..." type="text"
6464
role="combobox" aria-autocomplete="list" aria-controls="resultsList" aria-expanded="false" />
65+
<button
66+
id="clearSearchBtn"
67+
class="clear-search-btn"
68+
type="button"
69+
aria-label="Clear search"
70+
hidden>
71+
<i class="fas fa-times"></i>
72+
</button>
6573
<div class="search-dropdown" id="searchDropdown" aria-live="polite">
6674
<div class="dropdown-content" id="searchDropdownContent">
6775
<div class="search-loader" id="searchLoader" style="display: none">

web-app/js/main.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ document.addEventListener("DOMContentLoaded", function () {
286286
var html = document.documentElement;
287287
var backToTopButton = document.getElementById("backToTop");
288288
var searchInput = document.querySelector(".sidebar-dock #searchInput");
289+
const clearSearchBtn = document.getElementById("clearSearchBtn");
289290
var navSearchInput = document.getElementById("navSearchInput");
290291
var searchDropdown = document.getElementById("searchDropdown");
291292
var searchLoader = document.getElementById("searchLoader");
@@ -1264,6 +1265,10 @@ if (searchInputs.length) {
12641265
var rawValue = e.target.value;
12651266
var query = rawValue.trim();
12661267
currentSearchQuery = query;
1268+
1269+
if (clearSearchBtn) {
1270+
clearSearchBtn.hidden = query === "";
1271+
}
12671272

12681273
// Show loader
12691274
if (searchLoader) {
@@ -1301,11 +1306,16 @@ if (searchInputs.length) {
13011306
// Keyboard navigation
13021307
input.addEventListener("keydown", function (e) {
13031308
if (e.key === "Escape") {
1304-
input.value = "";
1305-
currentSearchQuery = "";
1306-
performSearch(false);
1307-
closeDropdown();
1308-
input.blur();
1309+
input.value = "";
1310+
currentSearchQuery = "";
1311+
1312+
if (clearSearchBtn) {
1313+
clearSearchBtn.hidden = true;
1314+
}
1315+
1316+
performSearch(false);
1317+
closeDropdown();
1318+
input.blur();
13091319
}
13101320

13111321
if (e.key === "Enter") {
@@ -1345,6 +1355,27 @@ if (searchInputs.length) {
13451355
}
13461356
});
13471357
});
1358+
1359+
if (clearSearchBtn) {
1360+
clearSearchBtn.addEventListener("click", function () {
1361+
1362+
searchInputs.forEach(function (input) {
1363+
input.value = "";
1364+
});
1365+
1366+
currentSearchQuery = "";
1367+
1368+
performSearch(false);
1369+
1370+
closeDropdown();
1371+
1372+
clearSearchBtn.hidden = true;
1373+
1374+
if (searchInput) {
1375+
searchInput.focus();
1376+
}
1377+
});
1378+
}
13481379
}
13491380

13501381
// Close dropdown when clicking outside

0 commit comments

Comments
 (0)