-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathexample09.ts
More file actions
55 lines (46 loc) · 1.68 KB
/
example09.ts
File metadata and controls
55 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { type LocaleKey, type MultipleSelectInstance, multipleSelect } from 'multiple-select-vanilla';
// 1. load every locale individually, it could be import in 2 ways (named import OR import on window object)
import { Spanish } from 'multiple-select-vanilla/dist/locales/es-ES.js'; // named import
// import 'multiple-select-vanilla/dist/locales/es-ES'; // locale on window object
// 2. or load all locales at once
import { locales } from 'multiple-select-vanilla/dist/locales/all-locales.js';
export default class Example {
ms0?: MultipleSelectInstance;
ms1?: MultipleSelectInstance;
ms2?: MultipleSelectInstance;
mount() {
const elm = document.querySelector('#locale') as HTMLSelectElement;
elm.addEventListener('change', ((event: KeyboardEvent & { target: HTMLSelectElement }) => {
this.updateLocale(event.target.value as LocaleKey);
}) as EventListener);
this.ms0 = multipleSelect(elm, {
maxHeight: 400,
}) as MultipleSelectInstance;
this.ms1 = multipleSelect('#dynamic-select', {
filter: true,
showOkButton: true,
dataTest: 'select1',
locales,
}) as MultipleSelectInstance;
this.ms2 = multipleSelect('#fixed-import', {
filter: true,
showOkButton: true,
dataTest: 'select2',
// when using named import
locale: Spanish,
}) as MultipleSelectInstance;
}
unmount() {
// destroy ms instance(s) to avoid DOM leaks
this.ms0?.destroy();
this.ms1?.destroy();
this.ms2?.destroy();
this.ms0 = undefined;
this.ms1 = undefined;
this.ms2 = undefined;
}
updateLocale(locale: LocaleKey) {
this.ms1?.destroy();
this.ms1?.refreshOptions({ locale });
}
}