Skip to content

Commit

Permalink
fix(useFocus): use useLayoutMount to prevent layout jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Jul 10, 2024
1 parent d0c8233 commit f295032
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/use-focus/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCreation } from '../use-creation'
import { useEventListener } from '../use-event-listener'
import { useMount } from '../use-mount'
import { useLayoutMount } from '../use-layout-mount'
import { useSafeState } from '../use-safe-state'
import { useStableFn } from '../use-stable-fn'
import { normalizeElement, useTargetElement } from '../use-target-element'
Expand Down Expand Up @@ -49,7 +49,7 @@ export function useFocus<T extends HTMLElement = HTMLElement>(
useEventListener(el, 'focus', () => setFocused(true))
useEventListener(el, 'blur', () => setFocused(false))

useMount(() => {
useLayoutMount(() => {
const isCurrentFocused = isElActive(el)

if (focused && !isCurrentFocused) focus()
Expand Down

0 comments on commit f295032

Please sign in to comment.