Skip to main content

rc-search-bar

Search field wrapper for a native <input type="search"> with icon chrome, clear button, and debounced events.

Package
@rcarls/rc-search-bar
Element
<rc-search-bar>
Native dependency
Requires a direct child native search input
State model
Controlled or uncontrolled search value
Main events
rc-search-bar-inputrc-search-bar-clear

Installation

npm install @rcarls/rc-search-bar
import '@rcarls/rc-search-bar/define';

Live demo

Theming

The default demo mode shows the component without a package theme. Use the shared preview controls on this page to compare inherited, light, and dark color schemes or to apply the optional Material theme only inside the demo frames.

API

Properties

PropertyMarkupTypeDefaultDescription
debouncedebouncenumber200Debounce window in ms for `rc-search-bar-input`; `0` dispatches synchronously.
clearLabelclear-labelstring'Clear search'Accessible label for the clear button.
allowNativeClearallow-native-clearbooleanfalseWhen set, leaves the browser's native WebKit cancel button visible.
showClearOnFocusshow-clear-on-focusbooleanfalseWhen set, the clear button is visible whenever the input is focused. Matching the Apple HIG "cancel" pattern. Consider setting `clear-label="Cancel"` in this mode.
disableddisabledbooleanNot specifiedDisables the component and mirrors the state to the slotted input.
placeholderplaceholderstring | undefinedNot specifiedPlaceholder mirrored onto the native input. Consumer `placeholder` attribute is always honored.
valueJS property onlystringNot specifiedThe current search value. Reads from the native input when present. Host writes are silent (no events) and win over slotted author values.
defaultValuedefault-valuestring | undefinedNot specifiedInitial uncontrolled value hint. Applied once, and only when neither an author `value`, a host `value` write, nor user input owns the value.

Methods

MethodDescription
clear()Programmatically clears the value and fires rc-search-bar-clear + rc-search-bar-input.

Events

EventDetail typeDescription
rc-search-bar-inputCustomEventDebounced after typing, immediate on clear; `detail: { value }`
rc-search-bar-clearCustomEventWhen the clear button is activated

Slots

NameDescription
(default)The required native `<input type="search">`
leadingDecorative leading icon; mark it `aria-hidden="true"`
trailingOptional trailing content after the clear button
clear-iconOptional glyph replacing the default clear glyph

CSS Custom Properties

PropertyDefaultDescription
--rc-search-bar-border1px solid ButtonBorderWrapper border; set to `none` in M3 theme (uses elevation instead)
--rc-search-bar-shadownoneWrapper box-shadow for elevation; M3 theme sets Level 1 at rest
--rc-search-bar-bgFieldWrapper background
--rc-search-bar-colorFieldTextWrapper text color
--rc-search-bar-icon-colorGrayTextLeading icon color
--rc-search-bar-clear-colorGrayTextClear button glyph color
--rc-search-bar-radiusvar(--rc-control-radius,0.125em)Wrapper border radius
--rc-search-bar-heightvar(--rc-control-block-size,2.5rem)Wrapper block size
--rc-search-bar-padding-inlinevar(--rc-control-padding-inline,0.75rem)Wrapper horizontal padding
--rc-search-bar-gapvar(--rc-control-gap,0.25em)Gap between icon, input, and clear button
--rc-search-bar-input-font-sizeNot specifiedInput font size (inherits when unset)
--rc-search-bar-input-font-familyNot specifiedInput font family (inherits when unset)
--rc-search-bar-input-colorNot specifiedInput text color (inherits when unset)

CSS Parts

PartDescription
rootThe wrapper element
leadingWrapper around the leading icon slot
trailingWrapper around the trailing slot
clearThe clear button