Skip to content

Commit b94a46f

Browse files
committed
Fix combobox allowCustomInput bug
1 parent 6ab8f3d commit b94a46f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@near-pagoda/ui",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"description": "A React component library that implements the official NEAR design system.",
55
"license": "MIT",
66
"repository": {

src/components/Combobox.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,30 @@ export const Combobox = forwardRef<HTMLInputElement, Props>(
8383
onInputValueChange(event) {
8484
const query = event.inputValue?.toLowerCase() ?? '';
8585
const options = allowNone ? [noneOption, ...props.options] : props.options;
86+
8687
const results = options.filter((o) => {
8788
if (o.hidden) return false;
8889
const label = (o.label ?? o.value).toString().toLowerCase();
8990
return label.includes(query);
9091
});
92+
9193
setFilteredItems(results);
9294

93-
if (allowCustomInput) {
94-
props.onChange(event.inputValue || internalCurrentValueBeforeFocus.current || '');
95-
console.log('onInputValueChange', event.inputValue ?? '');
95+
if (allowCustomInput && event.inputValue) {
96+
const selected = results.find((option) => (option.label || option.value) === event.inputValue);
97+
if (selected) {
98+
if (selected.value !== props.value) {
99+
props.onChange(selected.value);
100+
}
101+
} else {
102+
if (event.selectedItem) {
103+
selectItem(null);
104+
}
105+
props.onChange(event.inputValue);
106+
}
96107
}
97108
},
98109
onSelectedItemChange(event) {
99-
console.log('onSelectedItemChange', event);
100-
101110
const newValue = event.selectedItem?.value === '__NONE__' ? null : (event.selectedItem?.value ?? null);
102111
internalCurrentValue.current = newValue;
103112

0 commit comments

Comments
 (0)