diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-02 15:36:21 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | 655be4404630a20ae4ca40c4af84afcc2e63557b (patch) | |
| tree | b69cf241cfb4df7042f50be6a56b7c5f4414edd0 /src/components | |
| parent | e2daf7f81789c54b23ade72bd164492e7304d375 (diff) | |
refactor(hooks): replace useInputAutofocus with useAutofocus hook
* extract setTimeout logic using useTimeout
* change condition to be a function
* return a ref
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/organisms/toolbar/search.tsx | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/components/organisms/toolbar/search.tsx b/src/components/organisms/toolbar/search.tsx index 6a33aff..4429770 100644 --- a/src/components/organisms/toolbar/search.tsx +++ b/src/components/organisms/toolbar/search.tsx @@ -1,8 +1,7 @@ -import { forwardRef, type ForwardRefRenderFunction, useRef } from 'react'; +import { forwardRef, type ForwardRefRenderFunction } from 'react'; import { useIntl } from 'react-intl'; -import { useInputAutofocus } from '../../../utils/hooks'; +import { useAutofocus } from '../../../utils/hooks'; import { BooleanField, type BooleanFieldProps, Icon } from '../../atoms'; -import { FlippingLabel } from '../../molecules'; import { SearchModal, type SearchModalProps } from '../modals'; import searchStyles from './search.module.scss'; import sharedStyles from './toolbar-items.module.scss'; @@ -43,11 +42,9 @@ const SearchWithRef: ForwardRefRenderFunction<HTMLDivElement, SearchProps> = ( description: 'Search: Open label', }); - const searchInputRef = useRef<HTMLInputElement>(null); - useInputAutofocus({ - condition: isActive, + const searchInputRef = useAutofocus<HTMLInputElement>({ + condition: () => isActive, delay: 360, - ref: searchInputRef, }); return ( |
