15 lines
394 B
TypeScript
15 lines
394 B
TypeScript
import { useCallback, useRef } from 'react';
|
|
|
|
function usePreventAutoFocus<E extends HTMLElement = HTMLDivElement>() {
|
|
const ref = useRef<E>(null);
|
|
|
|
const onOpenAutoFocus = useCallback((event: Event) => {
|
|
event.preventDefault();
|
|
ref.current?.focus({ preventScroll: true });
|
|
}, []);
|
|
|
|
return { ref, onOpenAutoFocus, tabIndex: -1 as const };
|
|
}
|
|
|
|
export default usePreventAutoFocus;
|