Skip to content

Search Field

SearchField composes a native search input, a conditional clear button and a submit button inside one visual control. Use it inside a native form. The submit button keeps the form’s normal submission behavior.

<script>
import SearchField from "@invisible-ui/svelte/SearchField.svelte";
</script>
<form role="search" onsubmit={search}>
<SearchField
label="Search tables and columns"
hideLabel
name="query"
bind:value={query}
/>
</form>

In Elements:

<form role="search">
<ds-search-field
label="Search tables and columns"
hide-label
name="query"
></ds-search-field>
</form>

The clear button appears only when the field has a value. It reports an empty value once and returns focus to the search input. clearLabel / clear-label and submitLabel / submit-label override the localized accessible names.

The component provides its own clear button because browsers do not expose a consistent native cancel affordance. It suppresses the browser-specific cancel glyph only inside this component, avoiding duplicate controls in Chromium and WebKit while keeping the same behavior in Firefox.

When the results update on every keystroke, there is nothing to submit. Turn the submit button off with submitButton={false} (submit-button="false" in Elements): the search glyph moves to the start of the field as a decorative mark, and the clear button stays.

6 tables

  • accounts
  • archive
  • audit_log
  • invoices
  • orders
  • users
<SearchField label="Filter tables" hideLabel submitButton={false} bind:value={query} />

Announce the result count in a polite live region, so a screen reader user hears the effect of each change.

PropTypeDefaultDescription
label *string—Visible label and accessible name of the search input.
hideLabelbooleanfalseVisually hide the label while preserving the accessible name.
valuestring""Initial or controlled search query.
placeholderstring | undefinedundefinedNative input placeholder. It does not replace the label.
disabledbooleanfalse
requiredbooleanfalse
readOnlybooleanfalse
namestring | undefinedundefinedNative form field name.
autocompleteHTMLInputAttributes["autocomplete"] | undefinedundefinedNative browser autofill hint.
clearLabelstring | undefinedundefinedAccessible name for the conditional clear button.
submitLabelstring | undefinedundefinedAccessible name for the native submit button.
submitButtonbooleantrueRender the submit button; turn it off for a filter that applies as you type.
onValueChange((value: string) => void) | undefinedundefinedCalled once after a user edit or clear action is committed locally.
  • Keep the real label. hideLabel hides it only visually.
  • The clear and submit icons are decorative; their buttons have accessible names.
  • Keyboard order is input, clear when present, then submit when present.
  • Enter in the input follows native form submission.
  • Disabled and read-only search fields do not expose a clear action.