svelte-select (demo)
A select/autocomplete component for Svelte apps. With support for grouping, filtering, async and more.
Installation
yarn add svelte-select
Usage
<Select {items}></Select>
<script>
import Select from 'svelte-select';
export default {
components: { Select },
data() {
return {
items: [
{value: 'chocolate', label: 'Chocolate'},
{value: 'pizza', label: 'Pizza'},
{value: 'cake', label: 'Cake'},
{value: 'chips', label: 'Chips'},
{value: 'ice-cream', label: 'Ice Cream'},
]
};
}
};
</script>
API
items
- array of itemsfilterText
- text to filter list labels byplaceholder
- placeholder textoptionIdentifier
- Override default identifier ('value')listOpen
- open/close listcontainerStyles
- add/override container stylesselectedValue
- Selected value(s)groupBy
- Function to group list itemsisClearable
- Defaults true set to false to disable clear allisDisabled
- Disable selectisMulti
- Enable multi selectisSearchable
- Defaults true set to false to disable search/filteringgroupFilter
- Override default groupFilter functiongetOptionLabel
- Override default getOptionLabel functionItem
- Override default item componentSelection
- Override default selection componentMultiSelection
- Override default multi selection componentgetOptions
- Methods that returns a Promise that updates itemsnoOptionsMessage
- Message to display when there are no items
Development
yarn global add serve@8
yarn
yarn dev
yarn test:browser
Configuring webpack
If you're using webpack with svelte-loader, make sure that you add "svelte"
to resolve.mainFields
in your webpack config. This ensures that webpack imports the uncompiled component (src/index.html
) rather than the compiled version (index.mjs
) — this is more efficient.
If you're using Rollup with rollup-plugin-svelte, this will happen automatically.
License
LIL