4.4.1 • Published 9 months ago

svelecte v4.4.1

Weekly downloads
33
License
MIT
Repository
github
Last release
9 months ago

Svelecte NPM version

svelecte

Flexible autocomplete/select component written in Svelte. Initially inspired by Selectize.js. Also usable as custom element. Usable in forms, behaves very similar to standard <select> element.

See the latest changes on the Releases page.

📃 Features

  • searchable
  • multiselect with limit of max selected items
  • allow simple array or complex objects as items
  • custom item renderer (formatter)
  • allow creating new items (and possibly edit them)
  • remote data fetch
  • virtual list support
  • i18n and basic ARIA support
  • SSR support
  • client-validation support (tested with sveltekit-superforms)
  • lazy dropdown rendering
  • usable as custom element
  • customizable styling
  • dnd intergration with svelte-dnd-action

🔧 Installation

npm install svelecte --save

Minimalistic example

<script>
import Svelecte from 'svelecte';

const list = [{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2'}, ...];
let myValue = null;
</script>

<Svelecte options={list} bind:value={myValue}></Svelecte>

Properties

PropertyTypeDefaultDescription
namestring'svelecte'Create internal <select> element. Without name defined, no <select> is created
inputIdstringnullAllow targeting input using a html ID. Otherwise it is based on name property
requiredboolfalseMake sense only when name is defined and you work with it as standard <select> element
disabledboolfalseDisable component
optionsarray[]Option list, see Options for more info
optionResolverfunctionundefinedCustom option resolver. Enabling "query mode". Check the example on Options page
valuestring,objectnullBound value property. For multiple is always array
valueAsObjectboolfalseSwitch whether Svelecte should expects from and return to bind:value objects or primitive value (usually string, number)
parentValuestringundefinedValue which this component depends on. When parentValue is null, component is disabled. There is an example on Remote Datasource page.
valueFieldstringnullProperty to be used as value (if not specified, will be resolved automatically)
labelFieldstringnullProperty shown in dropdown (if not specified, will be resolved automatically)
groupLabelFieldstringlabelProperty to be used as optgroup label
groupItemsFieldstringoptionsProperty holding optgroup option list
disabledFieldstring$disabledProperty to check, whether given options should be disabled and unselectable
placeholderstringSelectInput placeholder
searchablebooltrueAllow search among items by typing
clearableboolfalseDisplay ✖ icon to clear whole selection
renderermixednullDropdown and selection renderer function. More on Rendering page
disableHighlightboolfalseDisable highlighting of input value in results. Can be useful with a renderer function that includes additional text or does its own highlighting
highlightFirstItembooltrueAutomatically highlight the first item in the list when the dropdown opens
selectOnTabbool,stringnullBased on value provided, it allows selecting currently active item by Tab AND (if value is 'select-navigate') also focus next input.
resetOnBlurbooltrueControl if input value should be cleared on blur
resetOnSelectbooltrueControl if input value should be cleared on item selection. Note: applicable only with multiple
closeAfterSelectbool'auto'closes dropdown after selection. Setting this to true is useful for multiple select only. For single select dropdown is always closed no matter the value this property has
strictModebooltrueWhen true, passed value is checked whether exists on provided options array. If not, invalidValue event is dispatched
multipleboolfalseallow multiselection. Will be set automatically to true, if name property ends with [], like tags[]
maxnumber0Maximum allowed items selected, applicable only for multiselect
collapseSelectionstringnullWhether selection should be collapsed and when, check Rendering for more info.
keepSelectionInListbool'auto'Whether keep selected items in dropdown. auto for multiple removes selected items from dropdown
creatableboolfalseAllow creating new item(s)
creatablePrefixstring*Prefix marking new item
allowEditingboolfalseWhen pressing Backspace switch to edit mode instead of removing newly created item. NOTE intended to be used with creatable property
keepCreatedbooltrueSwitch whether to add newly created option to option list or not
delimiterstring,split inserted text when pasting to create multiple items
createFilterfunctionnullFunction, that transform input string to custom value. It can serve as a filter, if value is valid or not. If you want to dismiss entered value, function should return '' (empty string). By default all input string is trimmed and all multiple spaces are removed.
createHandlerfunctionnullCustom (may be) async function transforming input string to option object. Default returns object with valueField and labelField properties, where labelField's value is input string prefixed with creatablePrefix property.
fetchstringnullSets fetch URL. Visit Remote datasource form more details
fetchPropsobjectnullSet options for new fetch Request
fetchCallbackfunctionnulloptional fetch callback
fetchResetOnBlurbooltruereset previous search results on empty input, related to resetOnBlur
fetchDebounceTimenumber300how many miliseconds is request debounced before fetch is executed
minQuerynumber1Minimal amount of characters required to perform remote request. Usable with fetch property
lazyDropdownbooltruerender dropdown after first focus, not by default
virtualListboolfalseWhether use virtual list for dropdown items (useful for large datasets)
vlHeightnumbernullHeight of virtual list dropdown (if not specified, computed automatically)
vlItemSizenumbernullHeight of one row (if not specified, computed automatically)
searchPropsobjectnullCustomize sifter.js settings. See Searching page for more details
classstringsvelecte-controldefault css class
i18nobjectnullI18n object overriding default settings
dndzonefunctionnoopPass dndzone from svelte-dnd-action, see Examples page
validatorActionarraynullBind validator action for inner <select> element. Designed to be used with svelte-use-form, see Validation page. For this to work, name property MUST be defined
anchor_elementboolnullinternal: when passing also existing select (for custom element)

Available slots

For more info refer to Rendering page.

<slot name="icon" />
<slot name="collapsedSelection" let:selectedOptions let:i18n />
<slot name="selection" let:selectedOptions let:bindItem />
<slot name="clear-icon" let:selectedOptions let:inputValue />
<slot name="dropdown-toggle" let:isOpen />
<slot name="list-header" />
<slot name="option" let:item />
<slot name="create-row" let:isCreating let:inputValue let:i18n  />

Emitted events:

Eventargumentsdescription
fetchoptionsnewly fetched remote options
fetchErrorerrordispatche on fetch error of any kind
changeselectionselected objects. If anchor property is defined, change event is called also on it
createoptionoptionnewly created option object
createFailobjectthrown if createHandler fails
focus<input>focus event
blur<input>blur event
invalidValueinvalidValuetriggered when passed value is out of provided options items. Internal (and bound, if any) value is set to null or [] if multiple
enterKeyunderlying keyDown eventtriggered when natively it would cause form submit (dropdown is closed). This gives you ability to prevent it by calling event.detail.preventDefault()

Public API:

Nametypeargumentsdescription
focusfunction-focus input
refetchWithfunctionnew value
<!-- clearByParentboolinternal for CE -->

There are global config and addRenderer function available. Refer to Global config and Rendering page respectively.

I18n, a11y, CSS variables

Visit documentation for more details.

Thanks to

And if you want to thank me, you can through my sponsor page.

License

MIT License

4.4.1

9 months ago

5.0.0-next.16

9 months ago

4.4.0

9 months ago

5.0.0-next.15

9 months ago

4.3.1

9 months ago

4.3.0

9 months ago

5.0.0-next.14

10 months ago

5.0.0-next.9

1 year ago

5.0.0-next.7

1 year ago

5.0.0-next.8

1 year ago

4.2.3

12 months ago

4.2.2

1 year ago

4.2.5

11 months ago

4.2.4

11 months ago

5.0.0-next.13

11 months ago

5.0.0-next.12

12 months ago

5.0.0-next.11

1 year ago

5.0.0-next.10

1 year ago

5.0.0-next.5

1 year ago

5.0.0-next.6

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

5.0.0-next.3

1 year ago

5.0.0-next.4

1 year ago

5.0.0-next.2

1 year ago

5.0.0-beta.1

1 year ago

4.1.0

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

3.17.3

1 year ago

3.17.0

2 years ago

3.17.2

2 years ago

4.0.0-alpha.13

2 years ago

3.17.1

2 years ago

4.0.0-alpha.12

2 years ago

4.0.0-alpha.11

2 years ago

3.16.3

2 years ago

3.16.2

2 years ago

3.16.4

2 years ago

4.0.0-alpha.9

2 years ago

4.0.0-alpha.7

2 years ago

4.0.0-alpha.8

2 years ago

4.0.0-alpha.5

2 years ago

4.0.0-alpha.6

2 years ago

4.0.0-alpha.3

2 years ago

4.0.0-alpha.4

2 years ago

4.0.0-alpha.1

2 years ago

3.13.3

2 years ago

4.0.0-alpha.2

2 years ago

4.0.0-alpha.10

2 years ago

3.14.0

2 years ago

3.15.0

2 years ago

3.15.2

2 years ago

3.15.1

2 years ago

3.15.4

2 years ago

3.15.3

2 years ago

3.15.5

2 years ago

3.16.1

2 years ago

3.16.0

2 years ago

3.13.2

3 years ago

3.13.1

3 years ago

3.12.0

3 years ago

3.13.0

3 years ago

3.11.0

3 years ago

3.11.1

3 years ago

3.9.9

3 years ago

3.9.8

3 years ago

3.9.3

3 years ago

3.9.7

3 years ago

3.9.6

3 years ago

3.9.5

3 years ago

3.9.4

3 years ago

3.10.1

3 years ago

3.10.0

3 years ago

3.10.2

3 years ago

3.9.2

3 years ago

3.9.1

3 years ago

3.9.0

3 years ago

3.8.0

3 years ago

3.8.1

3 years ago

3.7.5

3 years ago

3.7.7

3 years ago

3.7.6

3 years ago

3.7.4

3 years ago

3.7.3

3 years ago

3.7.2

3 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.5.7

3 years ago

3.5.6

3 years ago

3.5.5

3 years ago

3.5.4

3 years ago

3.5.8

3 years ago

3.4.3

4 years ago

3.6.0

3 years ago

3.4.2

4 years ago

3.4.1

4 years ago

3.4.5

4 years ago

3.5.3

3 years ago

3.5.2

4 years ago

3.5.1

4 years ago

3.5.0

4 years ago

3.3.6

4 years ago

3.4.0

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.3.5

4 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.1.0

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.3.2

4 years ago

1.2.3

4 years ago

1.3.1

4 years ago

1.2.2

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago

0.5.10

4 years ago

0.5.9

4 years ago

0.5.8

4 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.0

5 years ago

0.5.1

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.3.0

5 years ago

0.3.1

5 years ago

0.1.0

5 years ago