Search

A box people search from keeps the queries they ran and draws values as the app does: which boxes keep them, in which bucket, when a query counts as searched, how a value looks, the words an app finishes, groups and the status line, where the panel goes, slash commands, and a box that only jumps.

API QueryBox

A box people search from keeps the queries they ran and offers them back. QueryBox turns the browser's own input history off, so a box given no history offers none.

Search for is:open and then for flaky test, and click into the empty box: both wait there, newest first. Type fl and the one it begins rises above the submit row; type test and the one it only appears in waits below it. Tab loads a past query to keep editing; Enter or a click runs it again.

An empty box#

The submit row stays when the box is empty, and renderSubmitRow gets "". Choosing it submits the empty query, so draw the row as the place an empty query goes: every issue, all mail, or a search page that explains the syntax. Enter with no row picked still submits nothing.

Which boxes keep a history#

Give history to a box a reader comes back to search from: the search in an app's header, the query over a list of issues or mail. Keep it from a query-typed field in a form, such as the filter rule on Forms: that field holds one value the form saves, and a history there would offer other rules' queries as if they were this one's.

Where the queries are kept#

useQueryHistory keeps them in the browser, under a storageKey named after the app, and after the person signed in where several share one browser. Inside the key, each scope is a bucket of its own. Pick the scope from whatever a query's meaning depends on: a label of one project finds nothing in another, so each project gets its own. A box whose queries mean the same everywhere names its one bucket.

When a query counts as searched#

The box records nothing. Call record in onSubmit, where the app runs the search, and nowhere else:

  • A query that names one thing and goes straight to it, an issue's number say, is a jump, not a search. Do not record it. Only Enter in the box with the panel showing and no row highlighted, { from: "input", panelOpen: true }, may jump.
  • The submit row asks for a search of exactly what was typed, and so does Enter after Escape hid the panel (panelOpen: false). Search them as they are, even when they name one thing.
  • A submission the app refuses, a form field that fails its check, is not a search either. Return false from onSubmit, and the box stays as it was: its panel, its highlight and the query.
  • A past query chosen from its row arrives from: "history". It was a search when it was recorded, so search it as it is, without asking again whether it names one thing.
  • Words typed and then a row they found, one of a search's results offered in the panel, chosen by Enter, a click or a middle click: the words were a search, so record them. A middle click on a link row never reaches onSubmit, so record it from the link's own handler.

Record a query that ran, whichever way it came; it moves back to the top.

Waiting on a query#

Sometimes onSubmit cannot tell at once where a query goes: a pasted reference has to be looked up before the app knows whether it names one thing. Set busy until it knows. The box marks its input busy for a screen reader and draws nothing, because the wait is usually shorter than the 500ms under which Loading adds nothing new.

Linking the results#

When the results have an address, give queryHref: each past query becomes a link to them, so a middle click or a modified click opens them in a new tab, as any place does on Navigation. A plain click still goes through onSubmit.

Forgetting a query#

Each past query carries an × that forgets it: on the highlighted row under a mouse, and on every row on a touch screen, where nothing is hovered. Shift+Delete forgets the highlighted one from the keyboard, as in a browser's address bar.

Forgetting asks nothing and offers no Undo. What goes is a query, which can be searched again, and the row goes from under the finger that tapped its ×, so nothing vanishes unseen (Destructive actions).

Drawing values#

Draw a value in the panel as the app draws it everywhere else, so it is known at a glance: a label as its chip, a status as its pill, a person with their avatar. Put what each is drawn from on the provider's options (a label's colour, a person's login) and draw it in renderValue. A mark such as an avatar takes the icon's place and leaves the words where every row's words start; a chip takes the value's text; the hint still follows. Keep the value's name in the row either way: it is what a screen reader reads and what the reader matched by typing.

Type label: or assignee: in the example at the top. The schema already offers @me; the member search restates it with who that is, and the box keeps one @me, where it stood, now with an avatar.

Words the app finishes#

Some words only the app can finish: a project's prefix, which an issue's number follows, means nothing to the schema. Offer them from a RowSource that completes, with an apply that writes the word into the query and puts the caret after it. Its rows then behave as the schema's own completions: Enter, a click or Tab rewrites the query and keeps the reader in the box, and nothing is searched. A row that goes somewhere, a jump to one issue, stays in a source without completes, so choosing it submits.

Groups#

When the panel offers rows of more than one kind, pages by their title and passages in their text say, give each source a label. Its rows sit under it as a group, which a screen reader names by it, and a source with no rows draws no heading. Past queries that follow a heading get one of their own, historyLabel; in an empty box they stand first and need none, and examples of what to type that fill it out to a few rows stand bare beside them, told apart by their icons and their hints.

Saying what the search is doing#

When the app runs a search of its own as the reader types, say what it is doing in status, a line in the panel: Searching… until it answers, Nothing matches “…”. when it found nothing, Search is unavailable right now. when it failed. The line opens the panel on its own and, with rows, comes after them. A screen reader hears it from a region outside the panel, and, given countLabel, how many rows there are once the typing rests. End it with a full stop, as Writing asks of a sentence.

Where the panel goes#

The panel floats under the box, centred on it by default. A box at the start of a bar takes listAlign="start", and one at its end listAlign="end", so the panel grows into the page rather than past the window's edge. In a sheet or a narrow pane, where a floating panel would reach past the edge, panel="inline" sets it in the flow under the box, as wide as the box, with no frame of its own; whatever holds the box scrolls it.

Commands#

Give commands to a box people come back to that can also change something in place: the site's look from its header, the order of a list from the query above it. A value that starts with a slash is then a command line, read by a createCommandRegistry table, the same kind a Markdown editor's slash commands read. Keep commands out of a query field in a form, which holds one value to save.

  • Each command's detail says what it is set to now, and its compile returns null where it would change nothing, with an invalidReason that says so: Theme is already Dracula.
  • Enter, or a click, on a row that leaves a whole command runs it: /dark, or a value after /theme . Any other row is written in, /theme waiting for its value, and Tab only ever writes in. Enter with nothing highlighted runs the line as typed, or says in the panel why it cannot and leaves the box as it was.
  • A word typed without the slash names its commands too: dark offers /dark, dracula offers /theme dracula. They come under commandsLabel after the app's rows, only those that would run, and a line two of them would spell alike (/touch, /sizes touch) once. A click, or an arrow and Enter, runs one; highlightFirst never lands on one, so a word and Enter goes somewhere rather than changing everything.
  • A command that takes no value and would run nothing says why in place of what it is set to, in the list the slash opens: /dark under a theme with no dark palette.
  • Record a command in onCommand, as the line it is given (/theme dracula), whichever way it came: typed, picked, found by a word, or a past one picked again. A command that did not run is not recorded. Past commands are drawn as commands.
  • A command run empties the box and leaves the reader in it. Say what changed in a toast with Undo, as Principles asks of an action that is done at once.
  • Draw a command's values as the app draws them elsewhere (Drawing values): a theme as the theme menu's ThemeSwatch.

A box that only jumps#

A box with nothing to search, one that only takes the reader to what a query names (an issue by its number, a project by its prefix), has nothing for a submit row to do: leave out renderSubmitRow. Its panel then holds only the places and the words it offers, and opens only when there are some, so text that names nothing opens nothing.

Draw each place as a link, as on Navigation, from a source without completes, and a prefix the app finishes from one that completes: Tab with nothing highlighted still finishes the word being typed, and only that.

Where the words typed are a search rather than a reference, a site's search of its pages say, give the box highlightFirst: while a word is typed the first row is highlighted, and Enter goes there. Up stops at the top row; an empty box, and one waiting after a space for the next word, highlights nothing, and neither does a command a word found (Commands).

Enter with no row highlighted still reaches onSubmit, from: "input", since a pasted reference names a place before any row has had time to offer it. Look it up with busy set (Waiting on a query), and return false for text that names nothing. With no search to fall back on, panelOpen changes nothing: a panel with no rows is not shown either.

In the demos