Search
A search field with an optional dropdown of suggestions that you supply.
<arc-search>Overview
Search is a text field for search and filtering. It has a magnifying glass icon at the start, a clear button that shows once there's text, and a spinner that takes the clear button's place while loading is set. A label renders above the field. Without one, the placeholder becomes the accessible name.
Typing fires arc-input on every keystroke. Enter fires arc-change to submit. The clear button empties the field, fires arc-clear and puts focus back in the field.
Add <arc-suggestion> children for a dropdown of suggestions. Each one's value is what you get back, and its text is the label. The dropdown opens on focus or typing, ArrowUp and ArrowDown move through it, Enter picks the highlighted one, and Escape or a click outside closes it. Picking one fills the field with its label and fires arc-select with { value: { label, value } }, then arc-change. Search doesn't filter the list as you type. To narrow it, replace the children from your arc-input handler.
The field is a searchbox. With suggestions it becomes a combobox with aria-expanded, wired to a listbox of options.
Guidelines
Do
- Give it a `label`. Hide it with `::part(label)` if the design has no room for it
- Use `placeholder` to say what can be searched, for example "Search components..."
- Set `loading` while results are being fetched
- Debounce your `arc-input` handler for live search, and use `arc-change` for an explicit submit
Don't
- Don't use it for ordinary text fields. Use Input or Textarea
- Don't show hundreds of suggestions. Keep the list to 8 to 10
- Don't set `loading` when nothing is being fetched
Features
- The dropdown renders in the top layer, so a parent with `overflow: hidden` doesn't clip it
- `open` reflects whether the dropdown is showing, and you can set it yourself
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-search label="Search" placeholder="Search docs...">
<arc-suggestion value="getting-started">Getting Started</arc-suggestion>
<arc-suggestion value="components">Components</arc-suggestion>
</arc-search>import { Search, Suggestion } from '@arclux/arc-ui-react';
export default function Example() {
return (
<Search label="Search" placeholder="Search docs...">
<Suggestion value="getting-started">Getting Started</Suggestion>
<Suggestion value="components">Components</Suggestion>
</Search>
);
}<script setup>
import { Search, Suggestion } from '@arclux/arc-ui-vue';
</script>
<template>
<Search label="Search" placeholder="Search docs...">
<Suggestion value="getting-started">Getting Started</Suggestion>
<Suggestion value="components">Components</Suggestion>
</Search>
</template><script>
import { Search, Suggestion } from '@arclux/arc-ui-svelte';
</script>
<Search label="Search" placeholder="Search docs...">
<Suggestion value="getting-started">Getting Started</Suggestion>
<Suggestion value="components">Components</Suggestion>
</Search>import { Component } from '@angular/core';
import { Search, Suggestion } from '@arclux/arc-ui-angular';
@Component({
imports: [Search, Suggestion],
template: `
<arc-search label="Search" placeholder="Search docs...">
<arc-suggestion value="getting-started">Getting Started</arc-suggestion>
<arc-suggestion value="components">Components</arc-suggestion>
</arc-search>
`,
})
export class MyComponent {}import { Search, Suggestion } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<Search label="Search" placeholder="Search docs...">
<Suggestion value="getting-started">Getting Started</Suggestion>
<Suggestion value="components">Components</Suggestion>
</Search>
);
}import { Search, Suggestion } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<Search label="Search" placeholder="Search docs...">
<Suggestion value="getting-started">Getting Started</Suggestion>
<Suggestion value="components">Components</Suggestion>
</Search>
);
}API
valuestring''- Current text content of the search input.
placeholderstring'Search...'- Hint text displayed when the input is empty.
labelstring''- Accessible label for the search field. Rendered visually above the input when provided.
disabledbooleanfalse- Disables the input, reducing opacity and blocking interaction.
loadingbooleanfalse- Shows a spinning indicator in place of the clear button to signal in-progress loading.
openbooleanfalse- Whether the suggestion dropdown is visible. Reflected so it can be opened programmatically or styled from CSS.
Events
arc-inputdetail:{ value: string }- Fired on each keystroke in the search field
arc-clear- Fired when the clear button is clicked
arc-changedetail:{ value: string }- Fired when the value is committed: Enter in the field, or a suggestion selected by click or keyboard
arc-select- Fired when a suggestion is selected (before the accompanying arc-change)
Suggestion
<arc-suggestion>One suggestion in a Search dropdown. `value` is what the events report, and the text is the label.
labelvaluestring''- Suggestion value
See also
- ComboboxA text input that filters a list of options as you type, for picking one value from a long list.
- Command PaletteCommand list that opens as a dialog, with fuzzy, ranked search and shortcut hints.
- InputText field with a built-in label, placeholder and validation states. Set `multiline` for a textarea.