hi-tm 0.8.3 → 0.8.4
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.
|
@@ -118,7 +118,8 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
118
118
|
anyOption.content ??
|
|
119
119
|
anyOption.value ??
|
|
120
120
|
anyOption.name ??
|
|
121
|
-
anyOption.title
|
|
121
|
+
anyOption.title ??
|
|
122
|
+
anyOption.text;
|
|
122
123
|
return String(labelCandidate ?? '');
|
|
123
124
|
}, [getOptionLabel]);
|
|
124
125
|
const deriveValue = (0, react_1.useCallback)((option) => {
|
|
@@ -149,6 +150,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
149
150
|
(0, react_1.useEffect)(() => {
|
|
150
151
|
if (value === undefined || value === null) {
|
|
151
152
|
setSelectedValues([]);
|
|
153
|
+
if (!isMultiSelect) {
|
|
154
|
+
setInputValue('');
|
|
155
|
+
}
|
|
152
156
|
return;
|
|
153
157
|
}
|
|
154
158
|
const externalValues = Array.isArray(value) ? value : [value];
|
|
@@ -156,8 +160,12 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
156
160
|
const externalValuesString = JSON.stringify(externalValues.map(deriveValue));
|
|
157
161
|
if (currentValuesString !== externalValuesString) {
|
|
158
162
|
setSelectedValues(externalValues);
|
|
163
|
+
if (!isMultiSelect) {
|
|
164
|
+
const labelFromValue = externalValues.length > 0 ? deriveLabel(externalValues[0]) : '';
|
|
165
|
+
setInputValue(String(labelFromValue ?? ''));
|
|
166
|
+
}
|
|
159
167
|
}
|
|
160
|
-
}, [value, deriveValue]);
|
|
168
|
+
}, [value, deriveValue, deriveLabel, isMultiSelect]);
|
|
161
169
|
(0, react_1.useEffect)(() => {
|
|
162
170
|
if (!hasSearched) {
|
|
163
171
|
setFilteredOptions(options ?? []);
|
|
@@ -317,7 +325,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
317
325
|
const next = [option];
|
|
318
326
|
setSelectedValues(next);
|
|
319
327
|
emitSelection(next);
|
|
320
|
-
setInputValue(
|
|
328
|
+
setInputValue(deriveLabel(option));
|
|
321
329
|
setIsOpen(false);
|
|
322
330
|
setHasSearched(false);
|
|
323
331
|
}
|
|
@@ -342,7 +350,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
342
350
|
return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
|
|
343
351
|
label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
|
|
344
352
|
react_1.default.createElement("div", { className: `${styles.trigger} ${isDisabled ? 'bg-gray-100 cursor-not-allowed' : ''} ${isOpen ? 'border-blue-500 ring-2 ring-blue-100' : 'border-gray-300'}` },
|
|
345
|
-
react_1.default.createElement("div", { className: "flex-grow flex items-center min-w-0", onClick: handleInputAreaClick }, selectedValues.length > 0 ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full min-w-0" },
|
|
353
|
+
react_1.default.createElement("div", { className: "flex-grow flex items-center min-w-0", onClick: handleInputAreaClick }, isMultiSelect && selectedValues.length > 0 ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full min-w-0" },
|
|
346
354
|
react_1.default.createElement("div", { className: "flex items-center gap-1 overflow-x-auto no-scrollbar" }, selectedValues.map((val) => (react_1.default.createElement("div", { key: deriveValue(val), className: "flex-shrink-0 flex items-center bg-gray-200 rounded-md px-2 py-1" },
|
|
347
355
|
react_1.default.createElement("span", { className: "truncate max-w-[100px] text-sm" }, deriveLabel(val)),
|
|
348
356
|
react_1.default.createElement("button", { type: "button", onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon)))))),
|