Skip to content

Commit

Permalink
Fix focus theft on initial render
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Moore committed Nov 28, 2024
1 parent ed8396b commit c894833
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,24 @@ export const GenericTile = ({
...restProps
}: GenericTileProps): JSX.Element => {
const [isFlipped, setIsFlipped] = useState<boolean>(false)

const isMountingRef = useRef(false)
const infoButtonRef = useRef<HTMLButtonElement>(null)
const infoButtonReturnRef = useRef<HTMLButtonElement>(null)

useEffect(() => {
if (isFlipped) {
infoButtonReturnRef.current!.focus()
isMountingRef.current = true
}, [])

useEffect(() => {
if (!isMountingRef.current) {
if (isFlipped) {
infoButtonReturnRef.current!.focus()
} else {
infoButtonRef.current!.focus()
}
} else {
infoButtonRef.current!.focus()
isMountingRef.current = false
}
}, [isFlipped])

Expand Down

0 comments on commit c894833

Please sign in to comment.