Skip to content

Commit df8cfb1

Browse files
author
r00ster91
committed
feat: new search placeholder
This new search placeholder looks much nicer because it allows HTML inside it which the `placeholder` attribute on `<input>`s doesn't allow. I tested it for all kinds of cases and it seems to work pretty well.
1 parent 6354851 commit df8cfb1

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/docs/index.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@
190190
box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color);
191191
}
192192

193-
.docs .search::placeholder {
194-
font-size: 1rem;
195-
font-family: var(--ui);
196-
color: var(--tx-color);
197-
opacity: 0.5;
193+
#searchPlaceholder {
194+
position: absolute;
195+
pointer-events: none;
196+
top: 5px;
197+
left: 5px;
198198
}
199199

200200
.docs a {
@@ -334,7 +334,7 @@
334334
margin-right: 0.5em;
335335
}
336336

337-
.help-modal kbd {
337+
kbd {
338338
display: inline-block;
339339
padding: 0.3em 0.2em;
340340
font-size: 1.2em;
@@ -614,7 +614,10 @@ <h2><span>Zig Version</span></h2>
614614
<div class="flex-right">
615615
<div class="wrap">
616616
<section class="docs">
617-
<input type="search" class="search" id="search" autocomplete="off" spellcheck="false" placeholder="`s` to search, `?` to see more options">
617+
<div style="position: relative">
618+
<span id="searchPlaceholder"><kbd>S</kbd> to search, <kbd>?</kbd> for more options</span>
619+
<input type="search" class="search" id="search" autocomplete="off" spellcheck="false">
620+
</div>
618621
<p id="status">Loading...</p>
619622
<div id="sectNav" class="hidden"><ul id="listNav"></ul></div>
620623
<div id="fnProto" class="hidden">

lib/docs/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var zigAnalysis;
4949
let domTdZigVer = document.getElementById("tdZigVer");
5050
let domHdrName = document.getElementById("hdrName");
5151
let domHelpModal = document.getElementById("helpModal");
52+
const domSearchPlaceholder = document.getElementById("searchPlaceholder");
5253

5354
let searchTimer = null;
5455

@@ -103,6 +104,13 @@ var zigAnalysis;
103104
// let nodesToCallsMap = indexNodesToCalls();
104105

105106
domSearch.addEventListener("keydown", onSearchKeyDown, false);
107+
domSearch.addEventListener("focus", ev => {
108+
domSearchPlaceholder.classList.add("hidden");
109+
});
110+
domSearch.addEventListener("blur", ev => {
111+
if (domSearch.value.length == 0)
112+
domSearchPlaceholder.classList.remove("hidden");
113+
});
106114
domPrivDeclsBox.addEventListener(
107115
"change",
108116
function () {
@@ -2623,6 +2631,10 @@ var zigAnalysis;
26232631
updateCurNav();
26242632
if (domSearch.value !== curNavSearch) {
26252633
domSearch.value = curNavSearch;
2634+
if (domSearch.value.length == 0)
2635+
domSearchPlaceholder.classList.remove("hidden");
2636+
else
2637+
domSearchPlaceholder.classList.add("hidden");
26262638
}
26272639
render();
26282640
if (imFeelingLucky) {

0 commit comments

Comments
 (0)