X Enterprises
nuxt-x-affiliate

Search Bar

Inline search input with keyboard navigation, autocomplete suggestions, and arrow-key selection. Emits search query events.

Search Bar

The XAFSearchBar component renders an inline search input with keyboard navigation, autocomplete suggestions, and an emitted xaf:search:submit window event for analytics. Pairs with <XAFSearchResults> on the results page.

Components

<XAFSearchBar />

<XAFSearchBar
  v-model="query"
  :suggestions="autocompleteResults"
  placeholder="Search reviews..."
/>

Props

PropTypeDefaultDescription
modelValuestringrequiredTwo-way bound query string
suggestionsSearchSuggestion[]Autocomplete suggestions, shown as the user types
placeholderstring'Search...'Input placeholder
submitOnEnterbooleantrueSubmit on Enter (emits xaf:search:submit)
navigateOnEnterstringIf set, navigate to {base}?q={query} on Enter
minCharsnumber2Min query length before showing suggestions
compactbooleanfalseCompact pill style for headers

Events

EventPayloadDescription
update:modelValuestringEmitted on input. Use with v-model.
submitstringEmitted on Enter. The window-level xaf:search:submit is also dispatched.

Suggestion shape

interface SearchSuggestion {
  label: string       // Display text
  href: string        // Where to navigate on click / Enter
  category?: string   // Optional category badge
}

Tips

  • For search-engine-friendly URLs, set navigateOnEnter to /search. The component will navigate to /search?q=foo on Enter, where <XAFSearchResults> reads the query from useRoute().query.q.
  • Listen to the global xaf:search:submit event for analytics:
    window.addEventListener('xaf:search:submit', (e) => {
      const q = (e as CustomEvent<{ query: string }>).detail.query
      // Push to GA4, etc.
    })
    
  • Keep suggestions to ≤ 8 items — the keyboard navigation expects a small list.

AI Context

component: XAFSearchBar
package: "@xenterprises/nuxt-x-affiliate"
use-when: Inline search input with autocomplete — typically in XAFSiteHeader
Copyright © 2026