Skip to main content

Query input

Search box with highlighting for Marmot's query syntax.

Guidance​

The Discover search box. People type free text mixed with Marmot's search syntax (type:table, provider:snowflake, @metadata.owner = "Analytics Engineering", AND, OR, NOT), and the structured parts are highlighted as they type: field keys in slate, values in ink, operators and boolean keywords in ink-2. The field is a real <input> with transparent text under an aria-hidden highlighted copy, so caret, selection, IME and screen readers behave natively. Every token is set in the text face so the copy lines up with the caret to the pixel.

Pass createQuerySuggest({ fields }) as suggest for editor-style completion: @ lists the fields, then operators, values and AND, OR or NOT follow as the query is typed.

Optional suggestions follow the WAI-ARIA combobox pattern with a listbox popup (https://www.w3.org/WAI/ARIA/apg/patterns/combobox/): ArrowDown opens and moves, ArrowUp moves, Enter or Tab accepts the active suggestion, Escape closes. Enter with no active suggestion fires mm-search and submits the owning form unless the event is cancelled. The shortcut key ("/" by default) focuses the field from anywhere on the page.

Properties​

PropertyAttributeTypeDefaultDescription
valuevaluestring''The query.
placeholderplaceholderstring''
loadingloadingbooleanfalseShows a spinner while results load.
shortcutshortcutstring'/'Key that focuses the field from anywhere on the page, shown as a keycap. Empty to turn off.
suggestQuerySuggestFn | undefinedReturns suggestions for the query at the cursor. Calls are debounced and stale answers ignored.
suggestDelaysuggest-delaynumber120Debounce in milliseconds before suggest is called while typing.
tokensQueryToken[]Tokens of the current value.
labellabelstring''Field label. Rendered above the control unless hide-label, and always the accessible name.
helphelpstring''Help text under the control.
errorerrorstring''Error text: a sentence saying what to fix. Shows the crimson border, an icon and sets aria-invalid.
hideLabelhide-labelbooleanfalseHides the label visually; it stays the accessible name.
optionaloptionalbooleanfalseMarks the field as optional, in words.
namenamestring''Name submitted with the form.
disableddisabledbooleanfalseDisables the control and excludes it from submission.
requiredrequiredbooleanfalseRequires a value before the form submits.
formHTMLFormElement | null
validityValidityState
validationMessagestring
willValidateboolean
isDisabledbooleanTrue when disabled directly or by a disabled ancestor fieldset.

Methods​

MethodDescription
formResetCallback()Restore the initial value when the owning form resets.

Events​

EventDetailDescription
mm-inputCustomEvent<{ value: string; tokens: QueryToken[] }>Fired on every edit.
mm-changeCustomEvent<{ value: string }>Fired when the query is committed with Enter or on blur after an edit.
mm-searchCustomEvent<{ query: string; tokens: QueryToken[] }>Fired on Enter with no active suggestion. Cancel it to stop form submission.
changeEventNative change, re-dispatched from the host on commit.
inputInputEvent

CSS parts​

PartDescription
fieldThe bordered box.
iconThe leading search icon.
inputThe native input.
listboxThe suggestions popup.
optionEach suggestion.

Examples​

Every state of mm-query-input in Storybook, with keyboard and screen reader tests.