mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 04:58:46 -05:00
e65ede1d6a
[web] Autofocus on new project name input field GitOrigin-RevId: 4e26b2b5b6d39df942dc8ed293d3e4212028e4b0
17 lines
409 B
TypeScript
17 lines
409 B
TypeScript
import { useRef, useEffect } from 'react'
|
|
|
|
export function useRefWithAutoFocus<T extends HTMLElement = any>() {
|
|
const autoFocusedRef = useRef<T>(null)
|
|
|
|
useEffect(() => {
|
|
if (autoFocusedRef.current) {
|
|
window.requestAnimationFrame(() => {
|
|
if (autoFocusedRef.current) {
|
|
autoFocusedRef.current.focus()
|
|
}
|
|
})
|
|
}
|
|
}, [autoFocusedRef])
|
|
|
|
return { autoFocusedRef }
|
|
}
|