Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / components / hooks / useDrawerContactFocus.ts
blob6a1bd5df5e8038acab589f44cc1825196ab5e955
1 import type { RefObject } from 'react';
2 import { useEffect, useRef } from 'react';
4 import type { SelectedDrawerOption } from '@proton/components/components/drawer/views/DrawerView';
5 import { CONTACT_TAB } from '@proton/components/components/drawer/views/interface';
7 const useDrawerParent = (searchInputRef: RefObject<HTMLInputElement>, tab: SelectedDrawerOption) => {
8     const animationEnded = useRef(false);
10     const onFocusSearchInput = () => {
11         searchInputRef?.current?.focus();
12         animationEnded.current = true;
13     };
15     // When we switch tab (contact, contact group, setting), we also want to focus the search input
16     useEffect(() => {
17         if (animationEnded.current && tab.value === CONTACT_TAB.CONTACT) {
18             onFocusSearchInput();
19         }
20     }, [tab]);
22     return { onFocusSearchInput };
25 export default useDrawerParent;