Skip to main content

Search bar

Search with conditions as editable tokens: the query builder and the search box in one.

Guidance​

The search bar is the query builder. Free text and conditions live in one field: each condition is a neutral token in plain words ("Type is Table", "Provider is Snowflake or BigQuery"), and clicking a part of a token edits it (the field, the operator, or the value with a picker that fits the field: a list of known values, a text box, or a from and to pair for ranges). Several values of one field read as "is X or Y". There is no separate builder and no mode to switch.

Add a condition by typing @ (editor-style completion walks field, operator, value), in the query builder, or from outside, such as a facet sidebar setting value. "Build query" opens mm-query-builder in place of the bar, for groups that match all, any or none; Apply writes the result back. "Show as text" swaps the tokens for the raw query in place; a query the tokens cannot show (groups, OR between fields) shows as text with Build query beside it, never as a dead end.

Keyboard: Left at the start of the text moves into the tokens, Left and Right move between their parts, Enter or Space opens a part's editor, Escape closes it and returns focus, Backspace on an empty text box selects the last token and a second Backspace removes it, Delete removes the focused token. Changes are announced politely. Enter in the text box fires mm-search.

Properties​

PropertyAttributeTypeDefaultDescription
valuevaluestring''The query, in Marmot search syntax.
fieldsSearchBarField[][]Fields people can filter on, with everyday labels and known values.
labellabelstring''Accessible name of the search.
placeholderplaceholderstring''
rawrawbooleanfalseShows the raw query instead of tokens.
buildingbuildingbooleanfalseShows the query builder in place of the bar.
loadFields((prefix: string) => Promise<string[]>) | undefinedSuggests metadata fields in the query builder, such as from /assets/suggestions/metadata/fields.
loadValues((field: string, prefix: string) => Promise<string[]>) | undefinedSuggests values in the query builder, such as from /assets/suggestions/metadata/values.
draftCountdraft-countnumber | undefinedLive number of results for the builder's draft, set by the page after mm-draft.

Events​

EventDetailDescription
mm-inputCustomEvent<{ value: string }>The query changed.
mm-searchCustomEvent<{ query: string }>Enter was pressed in the text box.
mm-draftCustomEvent<{ value: string }>The query builder's draft changed, so the page can set draft-count.

CSS parts​

PartDescription
fieldThe bordered bar.
tokenEach condition token.
actionsThe row with Show as text and Build query.
editorThe popup that edits a token part.

Examples​

Every state of mm-search-bar in Storybook, with keyboard and screen reader tests.