Debian Codegraph @

docs/user_guide/search.rst

raw
1
2 Search bar / search button
3 ==========================
4
5 On narrow viewports, users can access search by clicking the magnifying glass
6 icon (:fas:`search`) in the :ref:`layout-header`. On wide viewports, the
7 magnifying glass icon, search input field, and keyboard shortcut for focusing
8 the search input field are all shown. The keyboard shortcut is:
9
10 * :kbd:`Ctrl` + :kbd:`K` (Linux, Windows)
11 * :kbd:`⌘` + :kbd:`K` (macOS)
12
13 You can also configure some aspects of the search button and search field, described below.
14
15 Configure the search field position
16 -----------------------------------
17
18 The position of the search *button* is controlled by ``search-button`` and by
19 default is included in ``html_theme_options["navbar_persistent"]``; you may move
20 it elsewhere as befits your site's layout, or remove it. You can also add an
21 always-visible search field to some/all pages in your site by adding
22 ``search-field.html`` to one of the configuration variables (e.g.,
23 ``html_sidebars``, ``html_theme_options["footer_start"]``, etc.).
24
25 For example, if you'd like the search field to be in your sidebar, add it to
26 the sidebar templates like so:
27
28 .. code:: python
29
30 html_sidebars = {
31 "**": ["search-field.html", "sidebar-nav-bs.html", "sidebar-ethical-ads.html"]
32 }
33
34 If instead, you'd like to put the search field in the top navbar, use the
35 following configuration:
36
37 .. code:: python
38
39 html_theme_options = {
40 "navbar_end": ["navbar-icon-links.html", "search-field.html"]
41 }
42
43 .. warning::
44
45 If a page includes *both* the search button and an always-visible search
46 field, the keyboard shortcuts will focus on the always-visible field and the
47 hidden search field overlay will not display. *This may not be what you want:*
48 on small screens (i.e. mobile devices) the sidebars may be hidden in a drawer,
49 and if the persistent search field is there, it may receive focus without
50 actually being made visible. It is **strongly recommended** that you use
51 *either* the search button and the hidden/overlaid field that comes with it,
52 *or* use a persistent search field in a place that makes sense for your layout.
53
54
55 Configure the search bar text
56 -----------------------------
57
58 To modify the text that is in the search bar before people click on it, add the
59 following configuration to your ``conf.py`` file:
60
61 .. code:: python
62
63 html_theme_options = {
64 "search_bar_text": "Your text here..."
65 }
66
67 Configure the inline search results (search-as-you-type) feature
68 ----------------------------------------------------------------
69
70 Set the ``search_as_you_type`` HTML theme option to ``True``.
71
72 .. code:: python
73
74 html_theme_options = {
75 "search_as_you_type": True
76 }
77
78 Disable the built-in search
79 ---------------------------
80
81 If your site uses a third-party search backend (e.g. the `Read the Docs
82 server-side search addon <https://docs.readthedocs.com/platform/stable/addons.html>`_),
83 you may want to disable the built-in pydata search entirely. Set the
84 ``disable_search`` HTML theme option to ``True``:
85
86 .. code:: python
87
88 html_theme_options = {
89 "disable_search": True
90 }
91
92 This does two things automatically:
93
94 * The ``#pst-search-dialog`` overlay is omitted from the page, so the
95 built-in search dialog never appears and keyboard shortcuts (:kbd:`Ctrl` +
96 :kbd:`K` / :kbd:`⌘` + :kbd:`K`) do not open it.
97 * ``navbar_persistent`` is set to an empty list, so the default search button
98 is no longer rendered in the navbar.
99
100 .. note::
101
102 ``disable_search`` only controls ``search-button-field`` (the full navbar
103 button showing the search label and keyboard shortcut) via
104 ``navbar_persistent``. It does not remove ``search-button`` (the icon-only
105 variant) or ``search-field.html`` if you have placed either of those
106 explicitly elsewhere in your layout. Remove them manually if needed.
107
108 If you set ``navbar_persistent`` explicitly in your ``html_theme_options``,
109 that value takes precedence and ``disable_search`` will not modify it.