A lightweight, zero-dependency component that supports theming and incorporating new entries. Built with SvelteJS and a11y in mind ❤️
Check out the live demo at simply-svelte-autocomplete.surge.sh
npm install simply-svelte-autocomplete
import AutoComplete from 'simply-svelte-autocomplete'
let options = ['Jorge Luis Borges', 'Voltaire', 'Oscar Wilde', 'Julio Cortazar', 'T.S. Eliot']
const handleSubmit = () => { ... }
<Autocomplete {options} onSubmit={handleSubmit} />
Prop | Type | Default | Description |
---|---|---|---|
options | Array | [] | List of autocomplete results to display |
searchModifiers | Array | [] | Used to restrict searches to a specific category |
className | String | '' | Container class |
onSubmit | Function | () => {} | Called upon clicking an autocomplete result or hitting the Enter key |
themeColor | String | '#333' | Color of chevron icon and highlight background |
highlightTextColor | String | '#FFF' | Highlight text color |
keepValueOnSubmit | Boolean | false | Whether to keep the value instead of clearing it when clicking on a result or hitting the Enter key |
Note: options
and searchModifiers
only accept strings. This is simply svelte, with a side of simple.
Prop | Type | Default | Description |
---|---|---|---|
selectedValue | String | '' | The current raw value written in the input |
Though the component includes ARIA information, tabbed result navigation needs to be implemented for the component to be truly accessible.
To run this app locally, clone this repository and run npm run dev
This component is tested with Jest. To run tests, run npm test
Contributions are always welcome! Open a pull request or file an issue.