Forked from rickychilcott/slim_select_controller.js
Created
February 9, 2021 02:21
-
-
Save leastbad/5a2bc361367e57f91f67f3eb549271ad to your computer and use it in GitHub Desktop.
Slim-select stimulus controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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