@@ -47,13 +47,13 @@ const themeIcons = [
4747 </div >
4848 <div class =" flex" >
4949 <!-- Search bar for desktop - instant display with Astro icons -->
50- <div id =" search-bar" class =" hidden lg:flex transition-all items-center h-11 mr-2 rounded-lg
50+ <div id =" search-bar" class =" hidden lg:flex transition-colors items-center h-11 mr-2 rounded-lg
5151 bg-black/[0.04] hover:bg-black/[0.06] focus-within:bg-black/[0.06]
5252 dark:bg-white/5 dark:hover:bg-white/10 dark:focus-within:bg-white/10
5353 " >
5454 <Icon name =" material-symbols:search" class =" absolute text-[1.25rem] pointer-events-none ml-3 transition my-auto text-black/30 dark:text-white/30" />
5555 <input id =" search-input-desktop" placeholder ={ i18n (I18nKey .search )}
56- class =" transition-all pl-10 text-sm bg-transparent outline-0
56+ class =" transition-all pl-10 text-sm bg-transparent outline-none border-0 ring-0 focus:ring- 0
5757 h-full w-40 text-black/50 dark:text-white/50"
5858 />
5959 </div >
@@ -79,6 +79,7 @@ const themeIcons = [
7979 </div >
8080 ))}
8181 </button >
82+ { /* @ts-ignore */ }
8283 <LightDarkSwitch client:idle ></LightDarkSwitch >
8384 </div >
8485 <button aria-label =" Menu" name =" Nav Menu" class =" btn-plain scale-animation rounded-lg w-11 h-11 active:scale-90 md:!hidden" id =" nav-menu-switch" >
@@ -102,53 +103,7 @@ function loadButtonScript() {
102103 }
103104 };
104105
105- if (settingBtn.dataset.hoverBound !== "1") {
106- settingBtn.dataset.hoverBound = "1";
107-
108- let closeTimer = 0;
109-
110- const getPanel = () => document.getElementById("display-setting");
111- const open = () => {
112- const panel = getPanel();
113- if (panel) panel.classList.remove("float-panel-closed");
114- };
115- const close = () => {
116- const panel = getPanel();
117- if (panel) panel.classList.add("float-panel-closed");
118- };
119- const cancelClose = () => {
120- window.clearTimeout(closeTimer);
121- };
122- const scheduleClose = () => {
123- window.clearTimeout(closeTimer);
124- closeTimer = window.setTimeout(close, 120);
125- };
126-
127- const bindPanelHover = (panel) => {
128- if (panel.dataset.hoverBound === "1") return;
129- panel.dataset.hoverBound = "1";
130- panel.addEventListener("mouseenter", cancelClose);
131- panel.addEventListener("mouseleave", (e) => {
132- const to = e.relatedTarget;
133- if (to instanceof Node && settingBtn.contains(to)) return;
134- scheduleClose();
135- });
136- };
137-
138- settingBtn.addEventListener("mouseenter", () => {
139- cancelClose();
140- open();
141- const panel = getPanel();
142- if (panel) bindPanelHover(panel);
143- });
144-
145- settingBtn.addEventListener("mouseleave", (e) => {
146- const panel = getPanel();
147- const to = e.relatedTarget;
148- if (panel && to instanceof Node && panel.contains(to)) return;
149- scheduleClose();
150- });
151- }
106+
152107 }
153108
154109 let menuBtn = document.getElementById("nav-menu-switch");
@@ -167,19 +122,30 @@ loadButtonScript();
167122function setupSearchBar() {
168123 const bar = document.getElementById("search-bar");
169124 const input = document.getElementById("search-input-desktop");
170- if (!bar || !input) return;
125+ if (!bar || !input || !(input instanceof HTMLInputElement)) return;
126+
171127 const expand = () => input.classList.add("w-60");
172128 const collapse = () => input.classList.remove("w-60");
129+
173130 bar.addEventListener("mouseenter", () => {
174131 expand();
175132 input.focus();
176133 });
177134 bar.addEventListener("mouseleave", () => {
178- input.blur();
179- collapse();
135+ if (document.activeElement === input && input.value.trim() === "") {
136+ input.blur();
137+ } else if (document.activeElement !== input) {
138+ collapse();
139+ }
140+ });
141+ input.addEventListener("focus", () => {
142+ expand();
143+ });
144+ input.addEventListener("blur", () => {
145+ if (!bar.matches(':hover')) {
146+ collapse();
147+ }
180148 });
181- input.addEventListener("focus", expand);
182- // keep expanded while typing; collapse only on mouseleave
183149}
184150
185151setupSearchBar();
0 commit comments