@tsed/react-formio 3.0.0-rc.24 → 3.0.0-rc.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/molecules/forms/select/components/ChoicesSelect.js +62 -65
- package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/HtmlSelect.js +21 -21
- package/dist/molecules/forms/select/components/HtmlSelect.js.map +1 -1
- package/package.json +3 -3
- package/src/molecules/forms/select/components/ChoicesSelect.tsx +12 -16
- package/src/molecules/forms/select/components/HtmlSelect.tsx +6 -6
|
@@ -1,100 +1,97 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { C as
|
|
1
|
+
import { jsx as k } from "react/jsx-runtime";
|
|
2
|
+
import { C as p } from "../../../../chunks/choices.js";
|
|
3
3
|
import { c as O } from "../../../../chunks/clsx.js";
|
|
4
|
-
import { useRef as S, useMemo as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
function B({
|
|
4
|
+
import { useRef as S, useMemo as w, useEffect as E } from "react";
|
|
5
|
+
import { registerComponent as z } from "../../../../registries/components.js";
|
|
6
|
+
import { cleanFormControlProps as M } from "../../form-control/FormControl.js";
|
|
7
|
+
import { callbackOnCreateTemplates as $ } from "./choices.template.js";
|
|
8
|
+
function j({
|
|
10
9
|
name: r,
|
|
11
10
|
disabled: i,
|
|
12
|
-
multiple:
|
|
13
|
-
options:
|
|
14
|
-
placeholder:
|
|
15
|
-
searchEnabled:
|
|
16
|
-
customProperties:
|
|
17
|
-
size:
|
|
18
|
-
value:
|
|
19
|
-
required:
|
|
20
|
-
onChange:
|
|
11
|
+
multiple: s,
|
|
12
|
+
options: d,
|
|
13
|
+
placeholder: n,
|
|
14
|
+
searchEnabled: v = !0,
|
|
15
|
+
customProperties: f = {},
|
|
16
|
+
size: h,
|
|
17
|
+
value: o,
|
|
18
|
+
required: b,
|
|
19
|
+
onChange: u
|
|
21
20
|
}) {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
21
|
+
const C = S(), t = S(), l = w(() => {
|
|
22
|
+
const a = (e) => [].concat(o).includes(e), m = d.map((e) => (e.options && (e = {
|
|
24
23
|
...e,
|
|
25
|
-
choices: e.options.map((
|
|
26
|
-
...
|
|
27
|
-
selected:
|
|
24
|
+
choices: e.options.map((c) => ({
|
|
25
|
+
...c,
|
|
26
|
+
selected: a(c.value)
|
|
28
27
|
}))
|
|
29
28
|
}), {
|
|
30
29
|
...e,
|
|
31
|
-
selected:
|
|
30
|
+
selected: a(e.value)
|
|
32
31
|
}));
|
|
33
|
-
return !
|
|
32
|
+
return !s && n ? [
|
|
34
33
|
{
|
|
35
|
-
disabled:
|
|
36
|
-
label:
|
|
34
|
+
disabled: b,
|
|
35
|
+
label: n,
|
|
37
36
|
value: ""
|
|
38
37
|
},
|
|
39
|
-
...
|
|
40
|
-
] :
|
|
41
|
-
}, [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
t.current && (c && t.current.clearStore(), t.current.setChoices(m, "value", "label", !0));
|
|
46
|
-
}, [m]), p(() => {
|
|
38
|
+
...m
|
|
39
|
+
] : m;
|
|
40
|
+
}, [d, o, b, s, n]);
|
|
41
|
+
return E(() => {
|
|
42
|
+
t.current && (s && t.current.clearStore(), t.current.setChoices(l, "value", "label", !0));
|
|
43
|
+
}, [s, l]), E(() => {
|
|
47
44
|
if (!t.current) {
|
|
48
45
|
const {
|
|
49
46
|
allowHTML: e = !0,
|
|
50
|
-
silent:
|
|
51
|
-
removeItemButton:
|
|
52
|
-
shouldSort:
|
|
47
|
+
silent: c = !0,
|
|
48
|
+
removeItemButton: T = !0,
|
|
49
|
+
shouldSort: I = !1,
|
|
53
50
|
itemSelectText: L = "",
|
|
54
|
-
callbackOnCreateTemplates:
|
|
55
|
-
} =
|
|
56
|
-
t.current = new
|
|
57
|
-
...
|
|
51
|
+
callbackOnCreateTemplates: x
|
|
52
|
+
} = f;
|
|
53
|
+
t.current = new p(C.current, {
|
|
54
|
+
...f,
|
|
58
55
|
allowHTML: e,
|
|
59
|
-
silent:
|
|
60
|
-
searchEnabled:
|
|
61
|
-
removeItemButton:
|
|
62
|
-
choices:
|
|
63
|
-
placeholder:
|
|
56
|
+
silent: c,
|
|
57
|
+
searchEnabled: v,
|
|
58
|
+
removeItemButton: T,
|
|
59
|
+
choices: l,
|
|
60
|
+
placeholder: n,
|
|
64
61
|
placeholderValue: "",
|
|
65
62
|
itemSelectText: L,
|
|
66
|
-
shouldSort:
|
|
67
|
-
callbackOnCreateTemplates:
|
|
63
|
+
shouldSort: I,
|
|
64
|
+
callbackOnCreateTemplates: x || $
|
|
68
65
|
});
|
|
69
66
|
}
|
|
70
67
|
i ? t.current?.disable() : t.current?.enable();
|
|
71
|
-
const
|
|
72
|
-
u(r,
|
|
73
|
-
},
|
|
74
|
-
|
|
68
|
+
const a = ({ detail: { value: e } }) => {
|
|
69
|
+
u?.(r, s ? [.../* @__PURE__ */ new Set([...o, e])] : e);
|
|
70
|
+
}, m = ({ detail: { value: e } }) => {
|
|
71
|
+
s ? u?.(
|
|
75
72
|
r,
|
|
76
|
-
|
|
77
|
-
) : u(r, void 0);
|
|
73
|
+
o.filter((c) => c !== e)
|
|
74
|
+
) : u?.(r, void 0);
|
|
78
75
|
};
|
|
79
|
-
return t.current?.passedElement.element.addEventListener("addItem",
|
|
80
|
-
t.current?.passedElement.element.removeEventListener("addItem",
|
|
76
|
+
return t.current?.passedElement.element.addEventListener("addItem", a), t.current?.passedElement.element.addEventListener("removeItem", m), () => {
|
|
77
|
+
t.current?.passedElement.element.removeEventListener("addItem", a), t.current?.passedElement.element.removeEventListener("removeItem", m);
|
|
81
78
|
};
|
|
82
|
-
}, [i,
|
|
83
|
-
ref:
|
|
79
|
+
}, [f, i, s, r, u, l, n, v, h, o]), {
|
|
80
|
+
ref: C,
|
|
84
81
|
choicesRef: t
|
|
85
82
|
};
|
|
86
83
|
}
|
|
87
|
-
function
|
|
88
|
-
const { ref: i } =
|
|
84
|
+
function B(r) {
|
|
85
|
+
const { ref: i } = j({
|
|
89
86
|
...r,
|
|
90
87
|
searchEnabled: !r.disableSearch
|
|
91
88
|
});
|
|
92
|
-
return /* @__PURE__ */
|
|
89
|
+
return /* @__PURE__ */ k(
|
|
93
90
|
"select",
|
|
94
91
|
{
|
|
95
92
|
ref: i,
|
|
96
93
|
"data-testid": `select_${r.name}`,
|
|
97
|
-
...
|
|
94
|
+
...M(r, [
|
|
98
95
|
"className",
|
|
99
96
|
"size",
|
|
100
97
|
"value",
|
|
@@ -112,9 +109,9 @@ function H(r) {
|
|
|
112
109
|
}
|
|
113
110
|
);
|
|
114
111
|
}
|
|
115
|
-
|
|
112
|
+
z("Select.choicesjs", B);
|
|
116
113
|
export {
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
B as ChoiceSelect,
|
|
115
|
+
j as useChoices
|
|
119
116
|
};
|
|
120
117
|
//# sourceMappingURL=ChoicesSelect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChoicesSelect.js","sources":["../../../../../src/molecules/forms/select/components/ChoicesSelect.tsx"],"sourcesContent":["import Choices from \"choices.js\";\nimport cx from \"clsx\";\nimport { useEffect, useMemo, useRef } from \"react\";\
|
|
1
|
+
{"version":3,"file":"ChoicesSelect.js","sources":["../../../../../src/molecules/forms/select/components/ChoicesSelect.tsx"],"sourcesContent":["import Choices from \"choices.js\";\nimport cx from \"clsx\";\nimport { useEffect, useMemo, useRef } from \"react\";\n\nimport { registerComponent } from \"../../../../registries/components\";\nimport { cleanFormControlProps } from \"../../form-control/FormControl\";\nimport type { AllSelectProps } from \"../Select.interface\";\nimport { callbackOnCreateTemplates as defaultTemplateCallback } from \"./choices.template\";\n\nexport function useChoices({\n name,\n disabled,\n multiple,\n options,\n placeholder,\n searchEnabled = true,\n customProperties = {},\n size,\n value,\n required,\n onChange\n}: AllSelectProps) {\n const ref = useRef<any>();\n const choicesRef = useRef<Choices>();\n\n const opts = useMemo(() => {\n const isSelected = (itemValue: any) => [].concat(value as any).includes(itemValue as never);\n\n const opts = options.map((item: any) => {\n if (item.options) {\n item = {\n ...item,\n choices: item.options.map((optionItem: any) => ({\n ...optionItem,\n selected: isSelected(optionItem.value)\n }))\n };\n }\n\n return {\n ...item,\n selected: isSelected(item.value)\n };\n });\n\n if (!multiple && placeholder) {\n return [\n {\n disabled: required,\n label: placeholder,\n value: \"\"\n },\n ...opts\n ];\n }\n\n return opts;\n }, [options, value, required, multiple, placeholder]);\n\n useEffect(() => {\n if (choicesRef.current) {\n if (multiple) {\n choicesRef.current.clearStore();\n choicesRef.current.setChoices(opts as any, \"value\", \"label\", true);\n } else {\n choicesRef.current.setChoices(opts as any, \"value\", \"label\", true);\n }\n }\n }, [multiple, opts]);\n\n useEffect(() => {\n if (!choicesRef.current) {\n const {\n allowHTML = true,\n silent = true,\n removeItemButton = true,\n shouldSort = false,\n itemSelectText = \"\",\n callbackOnCreateTemplates\n } = customProperties as any;\n\n choicesRef.current = new Choices(ref.current, {\n ...(customProperties as any),\n allowHTML,\n silent,\n searchEnabled,\n removeItemButton,\n choices: opts,\n placeholder: placeholder as string,\n placeholderValue: \"\" as string,\n itemSelectText,\n shouldSort,\n callbackOnCreateTemplates: callbackOnCreateTemplates || defaultTemplateCallback\n } as any);\n }\n\n if (disabled) {\n choicesRef.current?.disable();\n } else {\n choicesRef.current?.enable();\n }\n\n const addItem = ({ detail: { value: newValue } }: any) => {\n onChange?.(name, multiple ? [...new Set([...(value as string[]), newValue])] : newValue);\n };\n\n const removeItem = ({ detail: { value: newValue } }: any) => {\n if (multiple) {\n onChange?.(\n name,\n (value as string[]).filter((v) => v !== newValue)\n );\n } else {\n onChange?.(name, undefined as any);\n }\n };\n\n choicesRef.current?.passedElement.element.addEventListener(\"addItem\", addItem);\n choicesRef.current?.passedElement.element.addEventListener(\"removeItem\", removeItem);\n\n return () => {\n choicesRef.current?.passedElement.element.removeEventListener(\"addItem\", addItem);\n choicesRef.current?.passedElement.element.removeEventListener(\"removeItem\", removeItem);\n };\n }, [customProperties, disabled, multiple, name, onChange, opts, placeholder, searchEnabled, size, value]);\n\n return {\n ref,\n choicesRef\n };\n}\n\nexport function ChoiceSelect(props: AllSelectProps) {\n const { ref } = useChoices({\n ...props,\n searchEnabled: !props.disableSearch\n });\n\n return (\n <select\n ref={ref}\n data-testid={`select_${props.name}`}\n {...cleanFormControlProps(props as any, [\n \"className\",\n \"size\",\n \"value\",\n \"options\",\n \"placeholder\",\n \"onChange\",\n \"allowHTML\",\n \"silent\",\n \"removeItemButton\",\n \"shouldSort\",\n \"itemSelectText\",\n \"customProperties\"\n ])}\n className={cx(\"form-control\", props.size && `form-control-${props.size}`)}\n />\n );\n}\n\nregisterComponent(\"Select.choicesjs\", ChoiceSelect);\n"],"names":["useChoices","name","disabled","multiple","options","placeholder","searchEnabled","customProperties","size","value","required","onChange","ref","useRef","choicesRef","opts","useMemo","isSelected","itemValue","item","optionItem","useEffect","allowHTML","silent","removeItemButton","shouldSort","itemSelectText","callbackOnCreateTemplates","Choices","defaultTemplateCallback","addItem","newValue","removeItem","v","ChoiceSelect","props","jsx","cleanFormControlProps","cx","registerComponent"],"mappings":";;;;;;;AASO,SAASA,EAAW;AAAA,EACzB,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC;AAAA,EACA,eAAAC,IAAgB;AAAA,EAChB,kBAAAC,IAAmB,CAAA;AAAA,EACnB,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AACF,GAAmB;AACjB,QAAMC,IAAMC,EAAA,GACNC,IAAaD,EAAA,GAEbE,IAAOC,EAAQ,MAAM;AACzB,UAAMC,IAAa,CAACC,MAAmB,CAAA,EAAG,OAAOT,CAAY,EAAE,SAASS,CAAkB,GAEpFH,IAAOX,EAAQ,IAAI,CAACe,OACpBA,EAAK,YAC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AA,CACD;AAAA,MACD,WAAWG,EAAG,gBAAgBH,EAAM,QAAQ,gBAAgBA,EAAM,IAAI,EAAE;AAAA,IAAA;AAAA,EAAA;AAG9E;AAEAI,EAAkB,oBAAoBL,CAAY;"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { jsxs as g, jsx as
|
|
2
|
-
import { c as
|
|
1
|
+
import { jsxs as g, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { c as x } from "../../../../chunks/clsx.js";
|
|
3
3
|
import { registerComponent as v } from "../../../../registries/components.js";
|
|
4
|
-
import { getEventValue as
|
|
5
|
-
import { cleanFormControlProps as
|
|
6
|
-
function
|
|
7
|
-
return /* @__PURE__ */
|
|
4
|
+
import { getEventValue as j } from "../../../../utils/getEventValue.js";
|
|
5
|
+
import { cleanFormControlProps as C } from "../../form-control/FormControl.js";
|
|
6
|
+
function i({ value: o, label: r, ...n }) {
|
|
7
|
+
return /* @__PURE__ */ e("option", { ...n, value: o, children: r });
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
const f = !!
|
|
9
|
+
function S({ name: o, id: r = o, size: n, value: u, multiple: l, onChange: m, options: p, placeholder: s, ...a }) {
|
|
10
|
+
const f = !!p[0].options;
|
|
11
11
|
return /* @__PURE__ */ g(
|
|
12
12
|
"select",
|
|
13
13
|
{
|
|
14
|
-
"data-testid": `select_${
|
|
15
|
-
...
|
|
16
|
-
className:
|
|
17
|
-
name:
|
|
18
|
-
id:
|
|
19
|
-
multiple:
|
|
20
|
-
value:
|
|
21
|
-
onChange: (
|
|
22
|
-
|
|
14
|
+
"data-testid": `select_${o}`,
|
|
15
|
+
...C(a),
|
|
16
|
+
className: x("form-control", n && `form-control-${n}`),
|
|
17
|
+
name: o,
|
|
18
|
+
id: r,
|
|
19
|
+
multiple: l,
|
|
20
|
+
value: u || "",
|
|
21
|
+
onChange: (t) => {
|
|
22
|
+
m && m(o, j(t));
|
|
23
23
|
},
|
|
24
24
|
children: [
|
|
25
|
-
|
|
26
|
-
f ?
|
|
25
|
+
s && !l && /* @__PURE__ */ e("option", { value: "", disabled: !0, children: s }),
|
|
26
|
+
f ? p.map(({ label: t, options: c }, $) => /* @__PURE__ */ e("optgroup", { label: t, children: c.map((h, d) => /* @__PURE__ */ e(i, { ...h }, `${r}-optgroup-${d}`)) }, r + "-" + $)) : p.map((t, c) => /* @__PURE__ */ e(i, { ...t }, `${r}-option-${c}`))
|
|
27
27
|
]
|
|
28
28
|
}
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
|
-
v("Select.html5",
|
|
31
|
+
v("Select.html5", S);
|
|
32
32
|
export {
|
|
33
|
-
|
|
33
|
+
S as HTMLSelect
|
|
34
34
|
};
|
|
35
35
|
//# sourceMappingURL=HtmlSelect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HtmlSelect.js","sources":["../../../../../src/molecules/forms/select/components/HtmlSelect.tsx"],"sourcesContent":["import cx from \"clsx\";\n\nimport { registerComponent } from \"../../../../registries/components\";\nimport { getEventValue } from \"../../../../utils/getEventValue\";\nimport { cleanFormControlProps } from \"../../form-control/FormControl\";\nimport { AllSelectProps, SelectOptionBaseProps } from \"../Select.interface\";\n\nfunction Option({ value, label, ...props }: SelectOptionBaseProps) {\n return (\n <option {...props} value={value as any}>\n {label}\n </option>\n );\n}\n\nexport function HTMLSelect({ name, id = name, size, value, multiple, onChange, options, placeholder, ...props }: AllSelectProps) {\n const hasGroup = !!options[0].options;\n\n return (\n <select\n data-testid={`select_${name}`}\n {...cleanFormControlProps(props as any)}\n className={cx(\"form-control\", size && `form-control-${size}`)}\n name={name}\n id={id}\n multiple={multiple}\n value={value || (\"\" as any)}\n onChange={(event) => {\n onChange && onChange(name, getEventValue(event));\n }}\n >\n {placeholder && !multiple && (\n <option value='' disabled>\n {placeholder}\n </option>\n )}\n {hasGroup\n ? options.map(({ label, options }) => {\n return (\n <optgroup key={
|
|
1
|
+
{"version":3,"file":"HtmlSelect.js","sources":["../../../../../src/molecules/forms/select/components/HtmlSelect.tsx"],"sourcesContent":["import cx from \"clsx\";\n\nimport { registerComponent } from \"../../../../registries/components\";\nimport { getEventValue } from \"../../../../utils/getEventValue\";\nimport { cleanFormControlProps } from \"../../form-control/FormControl\";\nimport { AllSelectProps, SelectOptionBaseProps } from \"../Select.interface\";\n\nfunction Option({ value, label, ...props }: SelectOptionBaseProps) {\n return (\n <option {...props} value={value as any}>\n {label}\n </option>\n );\n}\n\nexport function HTMLSelect({ name, id = name, size, value, multiple, onChange, options, placeholder, ...props }: AllSelectProps) {\n const hasGroup = !!options[0].options;\n\n return (\n <select\n data-testid={`select_${name}`}\n {...cleanFormControlProps(props as any)}\n className={cx(\"form-control\", size && `form-control-${size}`)}\n name={name}\n id={id}\n multiple={multiple}\n value={value || (\"\" as any)}\n onChange={(event) => {\n onChange && onChange(name, getEventValue(event));\n }}\n >\n {placeholder && !multiple && (\n <option value='' disabled>\n {placeholder}\n </option>\n )}\n {hasGroup\n ? options.map(({ label, options }, index) => {\n return (\n <optgroup key={id + \"-\" + index} label={label}>\n {options.map((props: SelectOptionBaseProps, index: number) => {\n return <Option key={`${id}-optgroup-${index}`} {...props} />;\n })}\n </optgroup>\n );\n })\n : (options as SelectOptionBaseProps[]).map((props, index) => {\n return <Option key={`${id}-option-${index}`} {...props} />;\n })}\n </select>\n );\n}\n\nregisterComponent(\"Select.html5\", HTMLSelect);\n"],"names":["Option","value","label","props","jsx","HTMLSelect","name","id","size","multiple","onChange","options","placeholder","hasGroup","jsxs","cleanFormControlProps","cx","event","getEventValue","index","registerComponent"],"mappings":";;;;;AAOA,SAASA,EAAO,EAAE,OAAAC,GAAO,OAAAC,GAAO,GAAGC,KAAgC;AACjE,SACE,gBAAAC,EAAC,UAAA,EAAQ,GAAGD,GAAO,OAAAF,GAChB,UAAAC,GACH;AAEJ;AAEO,SAASG,EAAW,EAAE,MAAAC,GAAM,IAAAC,IAAKD,GAAM,MAAAE,GAAM,OAAAP,GAAO,UAAAQ,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description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@tanstack/react-table": ">=8.20.6",
|
|
47
|
-
"@tsed/tailwind-formio": "3.0.0-rc.
|
|
48
|
-
"@tsed/typescript": "3.0.0-rc.
|
|
47
|
+
"@tsed/tailwind-formio": "3.0.0-rc.26",
|
|
48
|
+
"@tsed/typescript": "3.0.0-rc.26",
|
|
49
49
|
"microbundle": "0.13.0",
|
|
50
50
|
"vite": "7.1.5",
|
|
51
51
|
"vitest": "3.2.4"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Choices from "choices.js";
|
|
2
2
|
import cx from "clsx";
|
|
3
3
|
import { useEffect, useMemo, useRef } from "react";
|
|
4
|
-
import { useDebouncedCallback } from "use-debounce";
|
|
5
4
|
|
|
6
5
|
import { registerComponent } from "../../../../registries/components";
|
|
7
6
|
import { cleanFormControlProps } from "../../form-control/FormControl";
|
|
@@ -27,13 +26,13 @@ export function useChoices({
|
|
|
27
26
|
const opts = useMemo(() => {
|
|
28
27
|
const isSelected = (itemValue: any) => [].concat(value as any).includes(itemValue as never);
|
|
29
28
|
|
|
30
|
-
const opts = options.map((item) => {
|
|
29
|
+
const opts = options.map((item: any) => {
|
|
31
30
|
if (item.options) {
|
|
32
31
|
item = {
|
|
33
32
|
...item,
|
|
34
|
-
choices: item.options.map((
|
|
35
|
-
...
|
|
36
|
-
selected: isSelected(
|
|
33
|
+
choices: item.options.map((optionItem: any) => ({
|
|
34
|
+
...optionItem,
|
|
35
|
+
selected: isSelected(optionItem.value)
|
|
37
36
|
}))
|
|
38
37
|
};
|
|
39
38
|
}
|
|
@@ -58,10 +57,6 @@ export function useChoices({
|
|
|
58
57
|
return opts;
|
|
59
58
|
}, [options, value, required, multiple, placeholder]);
|
|
60
59
|
|
|
61
|
-
const onChangeCallback = useDebouncedCallback((name: string | undefined, value: any) => {
|
|
62
|
-
onChange?.(name, value);
|
|
63
|
-
}, 50);
|
|
64
|
-
|
|
65
60
|
useEffect(() => {
|
|
66
61
|
if (choicesRef.current) {
|
|
67
62
|
if (multiple) {
|
|
@@ -71,7 +66,7 @@ export function useChoices({
|
|
|
71
66
|
choicesRef.current.setChoices(opts as any, "value", "label", true);
|
|
72
67
|
}
|
|
73
68
|
}
|
|
74
|
-
}, [opts]);
|
|
69
|
+
}, [multiple, opts]);
|
|
75
70
|
|
|
76
71
|
useEffect(() => {
|
|
77
72
|
if (!choicesRef.current) {
|
|
@@ -82,9 +77,10 @@ export function useChoices({
|
|
|
82
77
|
shouldSort = false,
|
|
83
78
|
itemSelectText = "",
|
|
84
79
|
callbackOnCreateTemplates
|
|
85
|
-
} = customProperties;
|
|
80
|
+
} = customProperties as any;
|
|
81
|
+
|
|
86
82
|
choicesRef.current = new Choices(ref.current, {
|
|
87
|
-
...customProperties,
|
|
83
|
+
...(customProperties as any),
|
|
88
84
|
allowHTML,
|
|
89
85
|
silent,
|
|
90
86
|
searchEnabled,
|
|
@@ -105,17 +101,17 @@ export function useChoices({
|
|
|
105
101
|
}
|
|
106
102
|
|
|
107
103
|
const addItem = ({ detail: { value: newValue } }: any) => {
|
|
108
|
-
|
|
104
|
+
onChange?.(name, multiple ? [...new Set([...(value as string[]), newValue])] : newValue);
|
|
109
105
|
};
|
|
110
106
|
|
|
111
107
|
const removeItem = ({ detail: { value: newValue } }: any) => {
|
|
112
108
|
if (multiple) {
|
|
113
|
-
|
|
109
|
+
onChange?.(
|
|
114
110
|
name,
|
|
115
111
|
(value as string[]).filter((v) => v !== newValue)
|
|
116
112
|
);
|
|
117
113
|
} else {
|
|
118
|
-
|
|
114
|
+
onChange?.(name, undefined as any);
|
|
119
115
|
}
|
|
120
116
|
};
|
|
121
117
|
|
|
@@ -126,7 +122,7 @@ export function useChoices({
|
|
|
126
122
|
choicesRef.current?.passedElement.element.removeEventListener("addItem", addItem);
|
|
127
123
|
choicesRef.current?.passedElement.element.removeEventListener("removeItem", removeItem);
|
|
128
124
|
};
|
|
129
|
-
}, [disabled, onChange, opts, placeholder, searchEnabled, size, value]);
|
|
125
|
+
}, [customProperties, disabled, multiple, name, onChange, opts, placeholder, searchEnabled, size, value]);
|
|
130
126
|
|
|
131
127
|
return {
|
|
132
128
|
ref,
|
|
@@ -35,17 +35,17 @@ export function HTMLSelect({ name, id = name, size, value, multiple, onChange, o
|
|
|
35
35
|
</option>
|
|
36
36
|
)}
|
|
37
37
|
{hasGroup
|
|
38
|
-
? options.map(({ label, options }) => {
|
|
38
|
+
? options.map(({ label, options }, index) => {
|
|
39
39
|
return (
|
|
40
|
-
<optgroup key={
|
|
41
|
-
{options.map((props: SelectOptionBaseProps) => {
|
|
42
|
-
return <Option key={
|
|
40
|
+
<optgroup key={id + "-" + index} label={label}>
|
|
41
|
+
{options.map((props: SelectOptionBaseProps, index: number) => {
|
|
42
|
+
return <Option key={`${id}-optgroup-${index}`} {...props} />;
|
|
43
43
|
})}
|
|
44
44
|
</optgroup>
|
|
45
45
|
);
|
|
46
46
|
})
|
|
47
|
-
: (options as SelectOptionBaseProps[]).map((props) => {
|
|
48
|
-
return <Option key={
|
|
47
|
+
: (options as SelectOptionBaseProps[]).map((props, index) => {
|
|
48
|
+
return <Option key={`${id}-option-${index}`} {...props} />;
|
|
49
49
|
})}
|
|
50
50
|
</select>
|
|
51
51
|
);
|