소스 검색

Fix search autofocus

Zed 6 년 전
부모
커밋
06945f433b
2개의 변경된 파일7개의 추가작업 그리고 7개의 파일을 삭제
  1. 5 3
      src/views/renderutils.nim
  2. 2 4
      src/views/search.nim

+ 5 - 3
src/views/renderutils.nim

@@ -61,14 +61,16 @@ proc genCheckbox*(pref, label: string; state: bool): VNode =
     else: input(name=pref, `type`="checkbox")
     span(class="checkbox")
 
-proc genInput*(pref, label, state, placeholder: string; class=""; autofocus=false): VNode =
+proc genInput*(pref, label, state, placeholder: string; class=""): VNode =
   let s = xmltree.escape(state)
   let p = xmltree.escape(placeholder)
-  let a = if autofocus: "autofocus" else: ""
   buildHtml(tdiv(class=("pref-group pref-input " & class))):
     if label.len > 0:
       label(`for`=pref): text label
-    input(name=pref, `type`="text", placeholder=p, value=s): text a
+    if s.len == 0:
+      input(name=pref, `type`="text", placeholder=p, value=s, autofocus="")
+    else:
+      input(name=pref, `type`="text", placeholder=p, value=s)
 
 proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
   buildHtml(tdiv(class="pref-group pref-input")):

+ 2 - 4
src/views/search.nim

@@ -58,8 +58,7 @@ proc renderSearchPanel*(query: Query): VNode =
   let action = if user.len > 0: &"/{user}/search" else: "/search"
   buildHtml(form(`method`="get", action=action, class="search-field")):
     hiddenField("f", "tweets")
-    genInput("q", "", query.text, "Enter search...",
-             class="pref-inline", autofocus=true)
+    genInput("q", "", query.text, "Enter search...", class="pref-inline")
     button(`type`="submit"): icon "search"
     if isPanelOpen(query):
       input(id="search-panel-toggle", `type`="checkbox", checked="")
@@ -110,8 +109,7 @@ proc renderUserSearch*(results: Result[Profile]; prefs: Prefs): VNode =
     tdiv(class="timeline-header"):
       form(`method`="get", action="/search", class="search-field"):
         hiddenField("f", "users")
-        genInput("q", "", results.query.text, "Enter username...",
-                 class="pref-inline", autofocus=true)
+        genInput("q", "", results.query.text, "Enter username...", class="pref-inline")
         button(`type`="submit"): icon "search"
 
     renderSearchTabs(results.query)