Slim Select
Advanced select dropdown

Support


See website for the full list of settings, methods and event callbacks

Features
- No Dependencies
- JS: 48kb - 10kb gzip
- CSS: 11kb - 2kb gzip
- Single Select
- Multi Select
- User Addable Options
- Html Options
- Settable Data
- Callback Events
- Label Support
- Placeholders
- Search
- Disable Options
- Light CSS
- Light Color Scheme
- Style and Class Inheritance
- Clean Animations
- Performant
- Typescript
- ARIA Accessibility (WCAG 2.1 Level AA compliant)
Frameworks
Installation
npm install slim-select
or
<script src="https://unpkg.com/slim-select@latest/dist/slimselect.js"></script>
<link rel="stylesheet" href="https://unpkg.com/slim-select@latest/dist/slimselect.css" />
Simple Usage
import SlimSelect from 'slim-select'
import 'slim-select/styles'
import 'slim-select/scss'
new SlimSelect({
select: '#selectElement'
})
<select id="selectElement">
<option value="value1">Value 1</option>
</select>
Data
Data is an array of objects that represent both option and optgroups.
See below for list of data types
new SlimSelect({
select: '#selectElement',
data: [{ text: 'Value 1', value: 'value1' }],
data: [{ label: 'Optgroup Label', options: { text: 'Value 1', value: 'value1' } }]
})
Data Types
var optgroup = {
label: 'label',
selectAll: false,
closable: 'off',
options: []
}
var option = {
text: 'text',
value: 'value',
html: '<b>Html</b>',
selected: false,
display: true,
disabled: false,
mandatory: false,
placeholder: false,
class: '',
style: '',
data: {}
}
Settings
Settings are optional fields that customize how SlimSelect operates. All values shown are defaults.
Full Settings Documentation
new SlimSelect({
select: '#selectElement',
settings: {
disabled: false,
alwaysOpen: false,
showSearch: true,
focusSearch: true,
keepSearch: false,
ariaLabel: 'Combobox',
searchPlaceholder: 'Search',
searchText: 'No Results',
searchingText: 'Searching...',
searchHighlight: false,
closeOnSelect: true,
contentLocation: document.body,
contentPosition: 'absolute',
openPosition: 'auto',
placeholderText: 'Select Value',
allowDeselect: false,
hideSelected: false,
keepOrder: false,
showOptionTooltips: false,
minSelected: 0,
maxSelected: 1000,
timeoutDelay: 200,
maxValuesShown: 20,
maxValuesMessage: '{number} selected',
addableText: 'Press "Enter" to add {value}'
}
})
Events
Events are function callbacks for when certain actions happen
Full Events Documentation
new SlimSelect({
select: '#selectElement',
events: {
search: (searchValue: string, currentData: (Option | Optgroup)[]) => Promise<(Partial<Option> | Partial<Optgroup>)[]> | (Partial<Option> | Partial<Optgroup>)[],
searchFilter: (option: Option, search: string) => boolean,
addable: (value: string) => Promise<Partial<Option> | string> | Partial<Option> | string | Error,
beforeChange: (newVal: Option[], oldVal: Option[]) => boolean | void,
afterChange: (newVal: Option[]) => void,
beforeOpen: () => void,
afterOpen: () => void,
beforeClose: () => void,
afterClose: () => void,
error: (err: Error) => void
}
})
Methods
SlimSelect provides methods to programmatically control the select
Full Methods Documentation
const slim = new SlimSelect({ select: '#selectElement' })
slim.enable()
slim.disable()
slim.getData()
slim.setData(data)
slim.getSelected()
slim.setSelected(['value1', 'value2'])
slim.addOption(option)
slim.open()
slim.close()
slim.search('searchValue')
slim.destroy()
Vue
SlimSelect has official Vue 3 component support with full reactivity.
For more Vue examples and advanced usage, see the Vue documentation.
Installation
npm install slim-select
Usage
<script lang="ts">
import SlimSelect from 'slim-select/vue'
import 'slim-select/styles'
export default {
components: { SlimSelect },
data() {
return {
selected: 'value2',
options: [
{ text: 'Value 1', value: 'value1' },
{ text: 'Value 2', value: 'value2' },
{ text: 'Value 3', value: 'value3' }
]
}
}
}
</script>
<template>
<SlimSelect v-model="selected" :data="options" />
</template>
React
SlimSelect has official React component support with hooks.
For more React examples and advanced usage, see the documentation.
Installation
npm install slim-select
Usage
import { useState } from 'react'
import SlimSelect from 'slim-select/react'
import 'slim-select/styles'
function MyComponent() {
const [selected, setSelected] = useState('value2')
const options = [
{ text: 'Value 1', value: 'value1' },
{ text: 'Value 2', value: 'value2' },
{ text: 'Value 3', value: 'value3' }
]
return <SlimSelect data={options} value={selected} onChange={setSelected} />
}
Advanced Usage with Ref
import { useRef } from 'react'
import SlimSelect, { SlimSelectRef } from 'slim-select/react'
import 'slim-select/styles'
function MyComponent() {
const slimRef = useRef<SlimSelectRef>(null)
const handleClick = () => {
slimRef.current?.slimSelect?.open()
}
return (
<>
<SlimSelect ref={slimRef} data={options} />
<button onClick={handleClick}>Open Dropdown</button>
</>
)
}