Files
manyfold/app/javascript/controllers/searchable_select_controller.ts
T

25 lines
548 B
TypeScript

import { Controller } from '@hotwired/stimulus'
import TomSelect from 'tom-select'
import type { TomInput } from 'tom-select/dist/cjs/types'
// Connects to data-controller="searchable-select"
export default class extends Controller {
tomSelect: TomSelect | null
connect (): void {
this.tomSelect = new TomSelect((this.element as TomInput), { // eslint-disable-line no-new
selectOnTab: true
})
}
disconnect (): void {
this.tomSelect?.destroy()
}
reconnect (): void {
this.disconnect()
this.connect()
}
}