Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leastbad/5a2bc361367e57f91f67f3eb549271ad to your computer and use it in GitHub Desktop.
Save leastbad/5a2bc361367e57f91f67f3eb549271ad to your computer and use it in GitHub Desktop.
Slim-select stimulus controller
import { Controller } from "stimulus"
import SlimSelect from "slim-select"
import "slim-select/dist/slimselect.min.css"
import "../style/slimselect-customized.css"
export default class extends Controller {
connect() {
const limit = this.data.get("limit")
const placeholder = this.data.get("placeholder")
const searchText = this.data.get("no-results")
const closeOnSelect = this.single
const allowDeselect = !this.element.required
this.select = new SlimSelect({
select: this.element,
closeOnSelect,
allowDeselect,
limit,
placeholder,
searchText
})
}
get single() {
return !this.element.multiple
}
get multi() {
return this.element.multiple
}
disconnect() {
if (this.select) {
this.select.destroy()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment