Class: DocsUI::SearchBox

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
app/components/docs_ui/search_box.rb

Overview

The topbar docs-search affordance: a plain GET form to config.search_path (the JS-off path — Enter lands on the server-rendered results page) that the ONE docs-nav controller enhances into a keyboard-shortcut palette. The shortcuts come from config.search_shortcuts (default "/" and "mod+k"): this component renders one hint per shortcut AND emits the parsed list as JSON on the scope, so the badges and the key bindings share one source and can't drift. The results dropdown is server-rendered here EMPTY and hidden; docs-nav fills it from search.json?q= as the reader types and toggles it. The form still submits normally if JS dies mid-typing, so search never depends on JavaScript.

Rendered by DocsUI::Shell only when DocsKit.configuration.search_enabled?.

The dropdown/menu/hidden classes are render-time LITERALS (never interpolated), so Tailwind's scan of this file keeps them; the CSS also time (like the Drawer classes).

Instance Method Summary collapse

Instance Method Details

#view_templateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/docs_ui/search_box.rb', line 21

def view_template
  # data-docs-nav-target="searchScope" roots the palette so the shortcut keys
  # can focus the input, and the results dropdown is a sibling.
  # data-docs-nav-shortcuts-value carries the parsed shortcut list as JSON so
  # docs-nav binds each configured key without hardcoding any.
  # min-w-0 (not flex-none) so the box SHRINKS on a narrow topbar instead of
  # pushing the theme switcher off-screen — on a 390px phone the brand +
  # search + switcher otherwise overflow. The input carries daisyUI's default
  # min-width, so it too needs min-w-0 + a modest responsive max-width.
  div(
    class: "dropdown min-w-0",
    data: { docs_nav_target: "searchScope", docs_nav_shortcuts_value: shortcuts_json }
  ) do
    form(
      action: config.search_path, method: "get", role: "search",
      class: "flex min-w-0 items-center", data: { action: "submit->docs-nav#submitSearch" }
    ) do
      label(class: "input input-sm flex min-w-0 max-w-[40vw] items-center gap-2 sm:max-w-none") do
        render DocsUI::Icon.new("search", class: "size-4 opacity-60")
        search_input
        shortcut_hint
      end
    end
    results_dropdown
  end
end