diff --git a/src/components/MenuItem/MenuItem.test.tsx b/src/components/MenuItem/MenuItem.test.tsx index 4c359920..94345301 100644 --- a/src/components/MenuItem/MenuItem.test.tsx +++ b/src/components/MenuItem/MenuItem.test.tsx @@ -84,22 +84,6 @@ describe('', () => { expect(onInitialItemChange).toHaveBeenCalledTimes(1); }); - it('conditionally calls `onInitialItemChange`', () => { - const onActiveItemChange = jest.fn(); - const context = { - activeIndex: 1, - onActiveItemChange, - }; - - const { rerender } = render( - - ); - expect(onActiveItemChange).toHaveBeenCalledTimes(0); - - rerender(); - expect(onActiveItemChange).toHaveBeenCalledTimes(1); - }); - it('changes the active state of the menu item', () => { render(); diff --git a/src/core/Context.tsx b/src/core/Context.tsx index 6aa655c0..485dfe9f 100644 --- a/src/core/Context.tsx +++ b/src/core/Context.tsx @@ -10,7 +10,6 @@ export interface TypeaheadContextType { initialItem?: Option; inputNode: HTMLInputElement | null; isOnlyResult: boolean; - onActiveItemChange: OptionHandler; onAdd: OptionHandler; onInitialItemChange: (option?: Option) => void; onMenuItemClick: (option: Option, event: SelectEvent) => void; @@ -24,7 +23,6 @@ export const defaultContext = { initialItem: undefined, inputNode: null, isOnlyResult: false, - onActiveItemChange: noop, onAdd: noop, onInitialItemChange: noop, onMenuItemClick: noop, diff --git a/src/core/TypeaheadManager.tsx b/src/core/TypeaheadManager.tsx index 0c77bb67..ca037937 100644 --- a/src/core/TypeaheadManager.tsx +++ b/src/core/TypeaheadManager.tsx @@ -44,7 +44,6 @@ const TypeaheadManager = (props: TypeaheadManagerProps) => { initialItem: props.initialItem, inputNode: props.inputNode, isOnlyResult: props.isOnlyResult, - onActiveItemChange: props.onActiveItemChange, onAdd: props.onAdd, onInitialItemChange: props.onInitialItemChange, onMenuItemClick: props.onMenuItemClick, diff --git a/src/core/useItem.tsx b/src/core/useItem.tsx index 920527cd..86d0ae5a 100644 --- a/src/core/useItem.tsx +++ b/src/core/useItem.tsx @@ -30,7 +30,6 @@ function useItem({ activeIndex, id, isOnlyResult, - onActiveItemChange, onInitialItemChange, onMenuItemClick, setItem, @@ -46,8 +45,6 @@ function useItem({ useEffect(() => { if (position === activeIndex) { - onActiveItemChange(option); - // Automatically scroll the menu as the user keys through it. const node = itemRef.current; @@ -57,7 +54,7 @@ function useItem({ scrollMode: 'if-needed', }); } - }, [activeIndex, onActiveItemChange, option, position]); + }, [activeIndex, option, position]); const handleClick = useCallback( (e: MouseEvent) => { diff --git a/src/core/useTypeahead.ts b/src/core/useTypeahead.ts index 48bf2be0..f9195c09 100644 --- a/src/core/useTypeahead.ts +++ b/src/core/useTypeahead.ts @@ -254,17 +254,10 @@ function useTypeahead( } function onActiveIndexChange(index: number) { - setState((currentState) => ({ + setState({ activeIndex: index, - activeItem: index >= 0 ? currentState.activeItem : undefined, - })); - } - - function onActiveItemChange(activeItem: Option) { - // Don't update the active item if it hasn't changed. - if (!isEqual(activeItem, state.activeItem)) { - setState({ activeItem }); - } + activeItem: index >= 0 ? items[index] : undefined, + }); } function onBlur(e: React.FocusEvent) { @@ -451,7 +444,6 @@ function useTypeahead( inputRef: setInputNode, isMenuShown, isOnlyResult, - onActiveItemChange, onAdd, onBlur, onChange: onInputChange, diff --git a/src/types.ts b/src/types.ts index b20aecec..b18b7f5c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -139,7 +139,6 @@ export interface TypeaheadManagerProps extends TypeaheadPropsAndState { inputRef: RefCallback; isMenuShown: boolean; isOnlyResult: boolean; - onActiveItemChange: OptionHandler; onAdd: OptionHandler; onChange: ChangeEventHandler; onClear: () => void;