Skip to content

Commit

Permalink
♻️ Refactor closeList
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 committed Jun 1, 2021
1 parent 827e1a6 commit b7148c2
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/auto-complete-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const AutoCompleteInput = forwardRef<AutoCompleteInputProps, 'input'>(
} = autocomplete;

const isEmpty = item.filtered.length < 1 && !emptyState;
const hideList = () => closeList(state, dispatch);
const hideList = () => closeList(dispatch);

useOptionsFilter({ initialFilter });
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/auto-complete-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const AutoCompleteList = forwardRef<AutoCompleteListProps, 'div'>(
<CreateInput />
<EmptyState
onClick={() => {
closeList(state, dispatch);
closeList(dispatch);
}}
/>
</PopoverContent>
Expand Down
2 changes: 1 addition & 1 deletion src/auto-complete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const AutoCompleteBody = forwardRef<AutoComplete, 'div'>(
runIfFn(onChange, autoCompleteValue);
}, [autoCompleteValue]);

const onClose = () => closeList(state, dispatch);
const onClose = () => closeList(dispatch);

const resetInput = () => {
if (inputRef?.current) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/autocomplete-props/onSelectOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const runOnSelect = (
returnT(inputRef?.current).value = activeItem.value;
dispatch({ type: InputAction.Set, payload: activeItem.value });
dispatch({ type: AutoCompleteAction.Set, payload: activeItem.value });
if (closeOnselect) closeList(state, dispatch);
if (closeOnselect) closeList(dispatch);
runIfFn(cb);
}
if (inputRef?.current && focusInputOnSelect) inputRef.current.focus();
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const handleNavigation = (
dispatch({ type: ItemAction.ResetActive, payload: true });
e.preventDefault();
} else if (e.key === 'Escape') {
closeList(state, dispatch);
closeList(dispatch);
e.preventDefault();
}
};
3 changes: 1 addition & 2 deletions src/helpers/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export const useRefDimensions = (
return dimensions;
};

export const closeList = (state: State, dispatch: StoreDispatch) => {
export const closeList = (dispatch: StoreDispatch) => {
dispatch({ type: ListAction.Hide });
console.log(state);
};

0 comments on commit b7148c2

Please sign in to comment.