BNA

BNA UI
24

SearchBar

A customizable search input with debouncing, loading states, and suggestions.

Installation

pnpm dlx bna-ui add searchbar

Usage

import { SearchBar, SearchBarWithSuggestions } from '@/components/ui/searchbar';
<SearchBar
  placeholder='Search for anything...'
  onSearch={(query) => console.log('Searching for:', query)}
  loading={false}
/>

Examples

Default

With Loading State

Custom Icons

With Suggestions

Custom Styling

Without Clear Button

API Reference

The main search input component with debouncing and customization options.

PropTypeDefaultDescription
loadingbooleanfalseShows loading indicator when true.
onSearch(query: string) => void-Callback fired when search is triggered (debounced).
onClear() => void-Callback fired when clear button is pressed.
showClearButtonbooleantrueWhether to show the clear button when text is present.
leftIconReactNodeSearch iconCustom left icon component.
rightIconReactNode-Custom right icon component.
containerStyleViewStyle | ViewStyle[]-Additional styles for the container.
inputStyleTextStyle | TextStyle[]-Additional styles for the text input.
debounceMsnumber300Debounce delay in milliseconds for search callbacks.
placeholderstring'Search...'Placeholder text for the input.
valuestring-Controlled value of the input.
onChangeText(text: string) => void-Callback fired when text changes.

All other TextInputProps are also supported.

SearchBarWithSuggestions

An enhanced search bar with dropdown suggestions functionality.

PropTypeDefaultDescription
suggestionsstring[][]Array of suggestion strings to display.
onSuggestionPress(suggestion: string) => void-Callback fired when a suggestion is selected.
maxSuggestionsnumber5Maximum number of suggestions to display.
showSuggestionsbooleantrueWhether to show the suggestions dropdown.

All SearchBar props are also supported.

Features

  • Debounced Search: Configurable debounce delay to prevent excessive API calls
  • Loading States: Built-in loading indicator support
  • Clear Functionality: Optional clear button with customizable behavior
  • Custom Icons: Support for custom left and right icons
  • Suggestions Dropdown: Enhanced variant with autocomplete suggestions
  • Flexible Styling: Comprehensive styling options for container and input
  • Controlled/Uncontrolled: Supports both controlled and uncontrolled usage patterns
  • Accessibility: Built with accessibility best practices

Accessibility

The SearchBar component follows accessibility guidelines:

  • Proper focus management and keyboard navigation
  • Screen reader compatible with appropriate labels
  • Clear button is properly labeled for assistive technologies
  • Suggestions dropdown supports keyboard navigation
  • High contrast support for better visibility