Replacing native select, multiselect
- ~44 KB
- no dependencies
- select, multiselect
- Optgroup
- Search
- Mobile native select (setting)
npm install simp-select --save
Or you can load it via a script tag as follows:
<script src="https://unpkg.com/simp-select@1.2.3/dist/simpleSelect.js" ></script>
<script src="https://unpkg.com/simp-select@1.2.3/dist/polyfill.js" ></script> - for IE 11
Or get last version
<script src="https://unpkg.com/simp-select"></script>
import SimpSelect from 'simp-select';
Types
import { ISimpleSelectProps, ISimpleSelectLocale } from 'simp-select/dist/types/simpleSelect.types';
var SimpSelect = require('simp-select');
the variable SimpSelect attached to window or this depending on what environment you are using
| Property | Value |
|---|---|
| selector(required) | string(css selector), HTMLSelectElement, HTMLSelectElement(Array, HTMLSelectElement) |
| OPTIONS: | |
| countShowSelected:number* | default: 3 Show count selected options. If more then this count, showed template: Selected: 4Or - |
| isSearch:boolean* | default: false Show input for filter itemsOr - |
| isSearchInDropdown:boolean* | default: false Show search input inside dropdownOr - |
| isConfirmInMulti:boolean* | default: false Show buttonsOK and Cancel. Only Multiselect Or |
| isConfirmInMultiOkClickOutside:boolean | default: false Click outside like click by buttonOK. Only if isConfirmInMulti=true |
| nativeOnDevice:string[] | default: 'Android', 'BlackBerry', 'iPhone', 'iPad', 'iPod', 'Opera Mini', 'IEMobile', 'Silk' The system default select list is rendered on the matched device(Check useragent ). |
| debounceTime:number* | default: 0 The change event will not be triggered immediately, but after a specified amount of time.Or |
| floatWidth:number* | default: 767 Minimum screen width of device below which the dropdown is rendered like popup.Or |
| sepChars:string | default: , Separator for selected element. Show |
| selectAll:boolean* | default: false Show button -Select all Or |
| selectAllAfterClose:boolean | default: true Close dropdown after click forselect all |
| resetAll:boolean* | default: false Show button -Reset all Or |
| resetAllAfterClose:boolean | default: true Close dropdown after click forReset all |
| isCloneClass:boolean | default: true Clone class from native select to wrapper created select |
| isRemoveTop:boolean* | default: false Do not create top element (Title, arrow, search ) (default: false)Or |
| isUp:boolean* | default: false Dropdown rendering the direction in which to open the dropdown (default: false)Or |
| isAlwaysOpen:boolean* | default: false Dropdown always open (default: false)Or |
| isAlwaysOpenShowDisabledTabindex:boolean* | default: false Set tabindex (tabindex="0") for disabled element (In Always open list) |
| isOnlyPlaceholder:boolean* | default: false Show only placeholder. Don't show selected options (default: false)Or |
| isLabelMode:boolean* | default: false Always displays the placeholder text as a persistent top-level label, even after a value is selected. See NoteOr |
| detectNative:function | default: none Returntrue if need rendering native select |
| changeBodyLi:function | default: none Custom |
| locale:{key: string} | default: simpleSelectLocale ** Object of locales. ** |
| historyMaxSize: number | default: 0 Maximum number of saved changes. |
| isScrollToCheckedFirst: boolean | default: true Scroll to the first element. This works only on the first opening. |
| isScrollToCheckedAlways: boolean | default: false Scroll to the first element. This works on each opening. |
| isDebounceStatusBar: boolean | default: false Status bar if multiselect has debounce.Or |
| isDebounceStatusBarBottom: boolean | default: false Location of the bar status in the dropdown (default in the Top element) |
| isNeedFormatTitle: boolean | default: false If you need to clear the line for the title |
| formatTitle: function | default: none Custom Line Clearing Function for Title |
| isSetAttributeSizeMultiple: boolean | default: '' Add classes for wrapper SimpSelect.Or |
| attributeSizeMultiple: number | default: true (If the attribute is not set for Select) Set attribute "size" for seletct multiple |
| addClasses: string | default: 1 Value for attribute "size" for seletct multiple |
| Options only DOM elements | |
| data-simple-placeholder="text": Select | Replace default placeholder (locale.title) |
| data-simple-item-html-before=" before : Select |
Add HTML before content (for item Li) |
| data-simple-item-html-after=" after ": Select |
Add HTML after content (for item Li) |
| data-simple-add-classes="class1 class2": Select | Add classes for wrapper SimpSelect |
| data-simple-html-before="before": option | Add HTML before content (for item Li) |
| data-simple-html-after="after": option | Add HTML after content (for item Li) |
| data-simple-show-checkbox: Select | Show checkbox in item (Li) (for single select) |
| Callbacks | |
| callbackInitialization: (item:SimpleSelectItem) => void | Before initialization |
| callbackInitialized:(item:SimpleSelectItem) => void; | After initialization |
| callbackOpen: (item:SimpleSelectItem) => void; | Open dropdown |
| callbackClose: (item:SimpleSelectItem) => void; | Close dropdown |
| callbackDestroyInit: (item:SimpleSelectItem) => void; | Before destroy SimpSelect |
| callbackDestroy: (item:SimpleSelectItem) => void; | After destroy SimpSelect |
| callbackChangeSelect :(e: Event, item:SimpleSelectItem) => void; | Change SimpSelect (change options) |
| Methods | |
| reload:select(DomElement).SimpSelect.reload() | Reload SimpSelect. |
| update:select(DomElement).SimpSelect.update() | Update list (ul in dropdown) |
| detach:select(DomElement).SimpSelect.detach() | Detach SimpSelect. |
| getHistory:select(DomElement).SimpSelect.getHistory() | Get history. |
| getHistoryLast:select(DomElement).SimpSelect.getHistoryLast() | Get history - last element. |
| getHistoryFirst:select(DomElement).SimpSelect.getHistoryFirst() | Get history - first element. |
| getInstance:select(DomElement).SimpSelect.getInstance() | Get instance SimpSelect. |
| const simpleSelect = new SimpleSelect('select') | Instance of the SimpleSelect plugin object |
| getSelectById('ID'):simpleSelect.getSelectById('ID') | Get item SimpSelect for ID (data-simple-select-init="ID" - dem element select) |
| getSelectFirst():simpleSelect.getSelectFirst() | Get first item SimpSelect |
| getSelects():simpleSelect.getSelects() | Get list SimpSelect |
| getSelects():simpleSelect.getSelects() | Get list SimpSelect |
*Data attributes in DOM element(select) more important than initialization options.
💡 Note on Floating Label Styling
When
isLabelModeis enabled, the plugin automatically toggles CSS state classes and handles basic placeholder visibility out of the box.You can easily customize the look of the floating label using these state classes:
SimpleSel--fill_with_value— Active when a real value is selected (label floats up).SimpleSel--fill_without_value— Active when the selection is empty (label rests in the center).Example Nesting CSS:
/* Customizing the floating label when it moves to the top */ .SimpleSel--label_mode.SimpleSel--fill_with_value { .SimpleSel__label { color: #007bff; /* Change label color when active */ font-weight: 600; } }
**Object of locales.
const simpleSelectLocale: = {
noSearch: 'No matches for',
searchText: 'Search',
title: 'Select',
selected: 'Selected:',
all: 'all',
ok: 'Ok',
cancel: 'Cancel',
selectAll: 'Select all',
resetAll: 'Reset all',
};
import SimpleSelect from 'simp-select';
new SimpleSelect('select');
View Live Demo Here.
Supported on all modern browsers