mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
171cd4f21c
[web] Add autofocus to React dashboard tag modals GitOrigin-RevId: 804fee108ab8e1c5bf97ade8032c4ea363baf7bb
17 lines
403 B
TypeScript
17 lines
403 B
TypeScript
import { useRef, useEffect } from 'react'
|
|
|
|
export function useRefWithAutoFocus<T extends HTMLElement = HTMLElement>() {
|
|
const autoFocusedRef = useRef<T>(null)
|
|
|
|
useEffect(() => {
|
|
if (autoFocusedRef.current) {
|
|
window.requestAnimationFrame(() => {
|
|
if (autoFocusedRef.current) {
|
|
autoFocusedRef.current.focus()
|
|
}
|
|
})
|
|
}
|
|
}, [])
|
|
|
|
return { autoFocusedRef }
|
|
}
|