UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

18 lines (17 loc) 779 B
import React from 'react'; import { createElemPropsHook } from '@workday/canvas-kit-react/common'; import { useComboboxModel } from './useComboboxModel'; /** * Reset the cursor to the selected item when the Menu is closed */ export const useComboboxResetCursorToSelected = createElemPropsHook(useComboboxModel)(model => { const visible = model.state.visibility !== 'hidden'; React.useEffect(() => { // when closed, the cursor should reset to the selected item if something is selected if (!visible && model.state.selectedIds.length) { model.events.goTo({ id: model.state.selectedIds[0] }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [visible, model.events, model.state.selectedIds]); return {}; });