Skip to content

Commit c0e9c0b

Browse files
committed
Introduce onInputValueChange prop to SelectBox and MultiSelectBox components
1 parent efe4800 commit c0e9c0b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/components/input-elements/MultiSelectBox/MultiSelectBox.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface MultiSelectBoxProps extends React.HTMLAttributes<HTMLDivElement
3333
defaultValue?: string[];
3434
value?: string[];
3535
onValueChange?: (value: string[]) => void;
36+
onInputValueChange?: (value: string) => void;
3637
placeholder?: string;
3738
disabled?: boolean;
3839
icon?: React.ElementType | React.JSXElementConstructor<any>;
@@ -44,6 +45,7 @@ const MultiSelectBox = React.forwardRef<HTMLDivElement, MultiSelectBoxProps>((pr
4445
defaultValue,
4546
value,
4647
onValueChange,
48+
onInputValueChange,
4749
placeholder = "Select...",
4850
disabled = false,
4951
icon,
@@ -87,6 +89,11 @@ const MultiSelectBox = React.forwardRef<HTMLDivElement, MultiSelectBoxProps>((pr
8789
onValueChange?.(newSelectedItems);
8890
};
8991

92+
const handleInputValueChange = (e: React.ChangeEvent<HTMLInputElement>) => {
93+
setSearchQuery(e.target.value);
94+
onInputValueChange?.(e.target.value);
95+
};
96+
9097
const handleReset = () => {
9198
setSelectedValue([]);
9299
onValueChange?.([]);
@@ -224,7 +231,7 @@ const MultiSelectBox = React.forwardRef<HTMLDivElement, MultiSelectBoxProps>((pr
224231
fontSize.sm,
225232
fontWeight.md,
226233
)}
227-
onChange={(e) => setSearchQuery(e.target.value)}
234+
onChange={handleInputValueChange}
228235
/>
229236
</div>
230237
<SelectedValueContext.Provider

src/components/input-elements/SelectBox/SelectBox.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface SelectBoxProps extends React.HTMLAttributes<HTMLDivElement> {
3737
defaultValue?: string;
3838
value?: string;
3939
onValueChange?: (value: string) => void;
40+
onInputValueChange?: (value: string) => void;
4041
placeholder?: string;
4142
disabled?: boolean;
4243
icon?: React.ElementType | React.JSXElementConstructor<any>;
@@ -48,6 +49,7 @@ const SelectBox = React.forwardRef<HTMLDivElement, SelectBoxProps>((props, ref)
4849
defaultValue,
4950
value,
5051
onValueChange,
52+
onInputValueChange,
5153
placeholder = "Select...",
5254
disabled = false,
5355
icon,
@@ -56,6 +58,7 @@ const SelectBox = React.forwardRef<HTMLDivElement, SelectBoxProps>((props, ref)
5658
onKeyDown,
5759
...other
5860
} = props;
61+
5962
const valueToNameMapping = useMemo(() => constructValueToNameMapping(children), [children]);
6063

6164
const [selectedValue, setSelectedValue] = useInternalState(defaultValue, value);
@@ -107,6 +110,8 @@ const SelectBox = React.forwardRef<HTMLDivElement, SelectBoxProps>((props, ref)
107110
const handleInputValueChange = (e: React.ChangeEvent<HTMLInputElement>) => {
108111
setSearchQuery(e.target.value);
109112
setInputValue(e.target.value);
113+
114+
onInputValueChange?.(e.target.value);
110115
};
111116

112117
const [hoveredValue, handleKeyDown] = useSelectOnKeyDown(

0 commit comments

Comments
 (0)