All Projects → metonym → svelte-typeahead

metonym / svelte-typeahead

Licence: MIT license
Accessible, fuzzy search typeahead component

Programming Languages

Svelte
593 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to svelte-typeahead

Autocomplete
Accessible autocomplete component for vanilla JavaScript and Vue.
Stars: ✭ 277 (+96.45%)
Mutual labels:  accessibility, typeahead
Vue Autosuggest
🔍 Vue autosuggest component.
Stars: ✭ 492 (+248.94%)
Mutual labels:  accessibility, typeahead
Vue Simple Suggest
Feature-rich autocomplete component for Vue.js
Stars: ✭ 324 (+129.79%)
Mutual labels:  accessibility, wai-aria
sublime-wai-aria
WAI-ARIA Roles, States and Properties auto-completion for Sublime Text
Stars: ✭ 21 (-85.11%)
Mutual labels:  accessibility, wai-aria
Visible
🦉 Accessibility testing framework at the next level
Stars: ✭ 164 (+16.31%)
Mutual labels:  accessibility, wai-aria
accessibility-testing-tools
A collection of useful tools for accessibility testing and debugging in the browser, online and desktop
Stars: ✭ 18 (-87.23%)
Mutual labels:  accessibility, wai-aria
React Spectrum
A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
Stars: ✭ 5,876 (+4067.38%)
Mutual labels:  accessibility, wai-aria
Vue Morphling
Vue filters and directives collection.
Stars: ✭ 179 (+26.95%)
Mutual labels:  filter, highlight
Awesome A11y
A curate list about A11Y ♿️
Stars: ✭ 1,210 (+758.16%)
Mutual labels:  accessibility, wai-aria
Chakra Ui Vue
⚡️ Build scalable and accessible Vue.js applications with ease.
Stars: ✭ 993 (+604.26%)
Mutual labels:  accessibility, wai-aria
stucco
An experimental adaptive UI toolkit.
Stars: ✭ 31 (-78.01%)
Mutual labels:  accessibility, wai-aria
React Menu
React component for building accessible menu, dropdown, submenu, context menu and more.
Stars: ✭ 237 (+68.09%)
Mutual labels:  accessibility, wai-aria
Fuzzysort
Fast SublimeText-like fuzzy search for JavaScript.
Stars: ✭ 2,569 (+1721.99%)
Mutual labels:  filter, fuzzy
Js Offcanvas
A lightweight, flexible jQuery off-canvas navigation plugin which lets you create fully accessible sidebar or top/bottom sliding (or push) panels with keyboard interactions and ARIA attributes.
Stars: ✭ 272 (+92.91%)
Mutual labels:  accessibility, wai-aria
Aerojump.nvim
Aerojump is a fuzzy-match searcher/jumper for Neovim with the goal of quick keyboard navigation
Stars: ✭ 184 (+30.5%)
Mutual labels:  filter, fuzzy
Accessible Autocomplete
An autocomplete component, built to be accessible.
Stars: ✭ 474 (+236.17%)
Mutual labels:  accessibility, typeahead
xray
Hexrays decompiler plugin that colorizes and filters the decompiler's output based on regular expressions
Stars: ✭ 97 (-31.21%)
Mutual labels:  filter, highlight
Reakit
Toolkit for building accessible rich web apps with React
Stars: ✭ 5,265 (+3634.04%)
Mutual labels:  accessibility, wai-aria
Bootstrap Vue
BootstrapVue provides one of the most comprehensive implementations of Bootstrap v4 for Vue.js. With extensive and automated WAI-ARIA accessibility markup.
Stars: ✭ 13,603 (+9547.52%)
Mutual labels:  accessibility, wai-aria
ari
Accessible unstyled vue components
Stars: ✭ 22 (-84.4%)
Mutual labels:  accessibility, wai-aria

svelte-typeahead

NPM

Accessible, fuzzy search typeahead component.

This component uses the lightweight fuzzy library for client-side, fuzzy search and follows WAI-ARIA guidelines.

Try it in the Svelte REPL.


Installation

# Yarn
yarn add -D svelte-typeahead

# npm
npm i -D svelte-typeahead

# pnpm
pnpm i -D svelte-typeahead

Usage

SvelteKit set-up

To use this component with SvelteKit or vite-powered set-ups, instruct vite to optimize the "fuzzy" dependency.

// svelte.config.js
const config = {
  kit: {
    vite: {
      optimizeDeps: {
        include: ["fuzzy"],
      },
    },
  },
};

Styling

Note: this component is minimally styled by design. You can target the component using the [data-svelte-typeahead] selector.

:global([data-svelte-typeahead]) {
  margin: 1rem;
}

Basic

Pass an array of objects to the data prop. Use the extractor prop to specify the value to search on.

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

  const data = [
    { state: "California" },
    { state: "North Carolina" },
    { state: "North Dakota" },
    { state: "South Carolina" },
    { state: "South Dakota" },
    { state: "Michigan" },
    { state: "Tennessee" },
    { state: "Nevada" },
    { state: "New Hampshire" },
    { state: "New Jersey" },
  ];

  const extract = (item) => item.state;
</script>

<Typeahead {data} {extract} />

Custom-styled results

This component uses the fuzzy library to highlight matching characters with the mark element.

Use the default slot to render custom results.

<Typeahead {data} {extract} let:result let:index>
  <strong>{@html result.string}</strong>
  {index}
</Typeahead>

No results

Use the "no-results" slot to render a message if the search value does not yield results.

<Typeahead value="abcd" {data} {extract} let:value>
  <svelte:fragment slot="no-results">
    No results found for "{value}"
  </svelte:fragment>
</Typeahead>

Limit the number of results

Use the limit prop to specify the maximum number of results to display. The default is Infinity.

<Typeahead limit={2} {data} {extract} />

Disabled items

Disable items using the disable filter. Disabled items are not selectable or navigable by keyboard.

In the following example, items with a state value containing "Carolina" are disabled.

<Typeahead
  {data}
  value="ca"
  extract={(item) => item.state}
  disable={(item) => /Carolina/.test(item.state)}
/>

Focus after select

Set focusAfterSelect to true to re-focus the search input after selecting a result.

<Typeahead focusAfterSelect {data} {extract} />

API

Props

Prop name Value Description
value string (default: "") Input search value
data TItem[] (default: []) Items to search
extract (TItem) => any Target an item key if data is an object array
disable (TItem) => boolean Pass in a function to disable items. They can be displayed in the results but will not be selectable.
filter (TItem) => boolean Pass in a function to filter items. They will be hidden and are not displayed in the results.
autoselect boolean (default: true) Automatically select the first (top) result
inputAfterSelect "update" or "clear" or "keep"(default: "update") Set to "clear" to clear the value after selecting a result. Set to "keep" to keep the search field unchanged after a selection.
results FuzzyResult[] (default: []) Raw fuzzy results from the fuzzy module
focusAfterSelect boolean (default: false) Set to true to re-focus the input after selecting a result.
limit number (default: Infinity) Specify the maximum number of results to display.
...$$restProps (forwarded to svelte-search) All other props are forwarded to the input element.

Dispatched events

  • on:select: dispatched when selecting a result
  • on:clear: dispatched when clearing the input field
<script>
  import Typeahead from "svelte-typeahead";

  let e = [];
</script>

<Typeahead
  {data}
  {extract}
  on:select={({ detail }) => (e = [...e, { event: "select", detail }])}
  on:clear={() => (e = [...e, { event: "clear" }])}
/>

<pre>{JSON.stringify(e, null, 2)}</pre>

Forwarded events

The following events are forwarded to the svelte-search component.

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

TypeScript

Svelte version 3.31 or greater is required to use this component with TypeScript.

TypeScript definitions are located in the types folder.

Changelog

Changelog

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].