Skip to content

Commit

Permalink
Refactor Autocomplete component to remove unused code and make onInpu…
Browse files Browse the repository at this point in the history
…tChange optional
  • Loading branch information
iacopolea committed Oct 17, 2024
1 parent 83825a6 commit 607fefa
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/stories/dropdowns/autocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ interface IOptGroup extends IOptGroupProps {
}

export interface AutocompleteProps extends IComboboxProps {
children: null;
onOptionClick?: ({ inputValue, selectionValue }: OnOptionClickArgs) => void;
onInputChange: (inputValue: string) => void;
onInputChange?: (inputValue: string) => void;
isCreatable?: boolean;
// promise to create new IOption
onCreateNewOption?: (inputValue: string) => Promise<IOption>;
options: Array<IOptGroup | IOption>;
}
Expand Down Expand Up @@ -88,15 +86,14 @@ const Autocomplete = ({ options, onOptionClick, onInputChange, onChange, isCreat
), [matchingOptions]);

const handleChange = useCallback<NonNullable<IComboboxProps['onChange']>>(event => {
console.log("event", event);
if (typeof onChange === 'function') {
onChange(event);
}

if (event.type === "input:change" && event.inputValue !== undefined) {
const sanitizedInputValue = event.inputValue.replace(/[.*+?^${}()|[\]\\]/giu, '\\$&');
setInputValue(sanitizedInputValue);
onInputChange(sanitizedInputValue);
if (typeof onInputChange === 'function') onInputChange(sanitizedInputValue);
}
if (event.type === "option:click" && typeof onOptionClick === 'function') {
// setSelectionValue(event.selectionValue);
Expand Down

0 comments on commit 607fefa

Please sign in to comment.