You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am displaying a long list of ordered options, allowing users to add their own values via the addable event. After a new item is added I would like to re-order the options in the dropdown.
Current workaround
I am currently storing the original state, and then on every afterChange event comparing the new values with the original values and re-creating the slim select instance.
This not only results in a flash of no content while re-creating slim select, but also a lot of boilerplate.
Add an added event that fires after the DOM has been updated
(nice to have) Add a rebuild method (or observe DOM mutations) that rebuilds the slim select list from the DOM
constselects=document.querySelectorAll('[data-slim-select]');selects.forEach(select=>{constslimSelect=newSlimSelect({select: select,events: {addable: value=>value,/*** NEW 'ADDED' EVENT ***/added: (newValue)=>{// re-order the DOM elementsArray.from(options).sort((a,b)=>a.innerText.localeCompare(b.innerText)).forEach(node=>select.appendChild(node));/*** NEW 'REBUILD' METHOD ***/slimSelect.rebuild();}},settings: {}});});
The text was updated successfully, but these errors were encountered:
Use case
I am displaying a long list of ordered options, allowing users to add their own values via the
addable
event. After a new item is added I would like to re-order the options in the dropdown.Current workaround
I am currently storing the original state, and then on every
afterChange
event comparing the new values with the original values and re-creating the slim select instance.This not only results in a flash of no content while re-creating slim select, but also a lot of boilerplate.
Suggested solution
added
event that fires after the DOM has been updatedrebuild
method (or observe DOM mutations) that rebuilds the slim select list from the DOMThe text was updated successfully, but these errors were encountered: