Fix search autofocus
This commit is contained in:
		
							parent
							
								
									c25aa507d3
								
							
						
					
					
						commit
						06945f433b
					
				
					 2 changed files with 7 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -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")):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue