Skip to content

Commit

Permalink
Introduce onInputValueChange prop to SelectBox and MultiSelectBox com…
Browse files Browse the repository at this point in the history
…ponents
  • Loading branch information
rebasedming committed May 19, 2023
1 parent efe4800 commit c0e9c0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface MultiSelectBoxProps extends React.HTMLAttributes<HTMLDivElement
defaultValue?: string[];
value?: string[];
onValueChange?: (value: string[]) => void;
onInputValueChange?: (value: string) => void;
placeholder?: string;
disabled?: boolean;
icon?: React.ElementType | React.JSXElementConstructor<any>;
Expand All @@ -44,6 +45,7 @@ const MultiSelectBox = React.forwardRef<HTMLDivElement, MultiSelectBoxProps>((pr
defaultValue,
value,
onValueChange,
onInputValueChange,
placeholder = "Select...",
disabled = false,
icon,
Expand Down Expand Up @@ -87,6 +89,11 @@ const MultiSelectBox = React.forwardRef<HTMLDivElement, MultiSelectBoxProps>((pr
onValueChange?.(newSelectedItems);
};

const handleInputValueChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchQuery(e.target.value);
onInputValueChange?.(e.target.value);
};

const handleReset = () => {
setSelectedValue([]);
onValueChange?.([]);
Expand Down Expand Up @@ -224,7 +231,7 @@ const MultiSelectBox = React.forwardRef<HTMLDivElement, MultiSelectBoxProps>((pr
fontSize.sm,
fontWeight.md,
)}
onChange={(e) => setSearchQuery(e.target.value)}
onChange={handleInputValueChange}
/>
</div>
<SelectedValueContext.Provider
Expand Down
5 changes: 5 additions & 0 deletions src/components/input-elements/SelectBox/SelectBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface SelectBoxProps extends React.HTMLAttributes<HTMLDivElement> {
defaultValue?: string;
value?: string;
onValueChange?: (value: string) => void;
onInputValueChange?: (value: string) => void;
placeholder?: string;
disabled?: boolean;
icon?: React.ElementType | React.JSXElementConstructor<any>;
Expand All @@ -48,6 +49,7 @@ const SelectBox = React.forwardRef<HTMLDivElement, SelectBoxProps>((props, ref)
defaultValue,
value,
onValueChange,
onInputValueChange,
placeholder = "Select...",
disabled = false,
icon,
Expand All @@ -56,6 +58,7 @@ const SelectBox = React.forwardRef<HTMLDivElement, SelectBoxProps>((props, ref)
onKeyDown,
...other
} = props;

const valueToNameMapping = useMemo(() => constructValueToNameMapping(children), [children]);

const [selectedValue, setSelectedValue] = useInternalState(defaultValue, value);
Expand Down Expand Up @@ -107,6 +110,8 @@ const SelectBox = React.forwardRef<HTMLDivElement, SelectBoxProps>((props, ref)
const handleInputValueChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchQuery(e.target.value);
setInputValue(e.target.value);

onInputValueChange?.(e.target.value);
};

const [hoveredValue, handleKeyDown] = useSelectOnKeyDown(
Expand Down

0 comments on commit c0e9c0b

Please sign in to comment.