Skip to content

martinjo/svelte-typeahead

 
 

Repository files navigation

svelte-typeahead

NPM Build

Accessible, fuzzy search typeahead component.

This component uses the lightweight fuzzy library for typeahead and follows WAI-ARIA guidelines.

Try it in the Svelte REPL.

Install

yarn add -D svelte-typeahead

Usage

<script>
  import Typeahead from "svelte-typeahead";

  const data = [
    { state: "California" },
    { state: "North Carolina" },
    { state: "South Carolina" },
  ];
</script>

<Typeahead {data} extract={item => item.state} />

Custom results

By default, this component uses the fuzzy library to higlight matching characters with the mark element.

Use a slot to render custom results.

<Typeahead {data} extract={item => item.state} let:result>
  <div>{@html result.string}</div>
</Typeahead>

API

Prop name Value
value string (default: "")
data T[] (default: [])
extract (T) => T
autoselect boolean (default: true)
...$$restProps (forwarded to Search component)

Forwarded events

Typeahead

Event name Description
on:select triggered based on the dropdown selection

Search

The following events are forwarded to the underlying Search input element:

  • on:input
  • on:change
  • on:focus
  • on:clear
  • on:blur
  • on:keydown

License

MIT

About

Accessible, fuzzy search typeahead component

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 95.1%
  • Svelte 4.9%