Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: auto focus search bar when sidebar is shown (close #1269) (#1304)

Jason Chen65850dfd0376
diff --git a/web/src/components/HomeSidebar.tsx b/web/src/components/HomeSidebar.tsx
index ef2c78a62..1b655edb0 100644
--- a/web/src/components/HomeSidebar.tsx
+++ b/web/src/components/HomeSidebar.tsx
@@ -32,6 +32,10 @@ export const toggleHomeSidebar = (show?: boolean) => {
if (show) {
sidebarEl.classList.add("show");
maskEl.classList.add("show");
+
+ // auto focus search bar when sidebar is shown
+ const inputEl = sidebarEl.querySelector("#mobile-search-bar") as HTMLInputElement;
+ inputEl?.focus();
} else {
sidebarEl.classList.remove("show");
maskEl.classList.remove("show");
diff --git a/web/src/components/SearchBar.tsx b/web/src/components/SearchBar.tsx
index 830c41e4c..d8be5e05b 100644
--- a/web/src/components/SearchBar.tsx
+++ b/web/src/components/SearchBar.tsx
@@ -54,6 +54,7 @@ const SearchBar = () => {
<input
className="flex ml-2 w-24 grow text-sm outline-none bg-transparent dark:text-gray-200"
type="text"
+ id="mobile-search-bar"
placeholder="Search memos"
ref={inputRef}
value={queryText}