Skip to content

Commit cd76f33

Browse files
committed
Ensure button focus by retrying with an interval until it becomes active
- check if is focused every 10ms and try again focus to make it as fast as possible
1 parent 10e1310 commit cd76f33

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • packages/ui/src/components/editor/common/Button

‎packages/ui/src/components/editor/common/Button/Button.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ export const Button: FC<Props> = (props) => {
2020

2121
useEffect(() => {
2222
if (props.is_focused) {
23-
button_ref.current?.focus()
23+
const interval = setInterval(() => {
24+
if (
25+
button_ref.current &&
26+
document.activeElement !== button_ref.current
27+
) {
28+
button_ref.current.focus()
29+
} else {
30+
clearInterval(interval)
31+
}
32+
}, 10)
33+
return () => clearInterval(interval)
2434
}
2535
}, [props.is_focused])
2636

0 commit comments

Comments
 (0)