Fix roving tab index crash compareDocumentPosition
(#12594)
* Fix roving tab index crash `compareDocumentPosition` Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
3e7511cc5d
commit
930b4e2424
3 changed files with 7 additions and 10 deletions
|
@ -18,7 +18,7 @@ import React, {
|
|||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useLayoutEffect,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useReducer,
|
||||
|
@ -144,7 +144,7 @@ export const reducer: Reducer<IState, Action> = (state: IState, action: Action)
|
|||
}
|
||||
if (document.activeElement === document.body) {
|
||||
// if the focus got reverted to the body then the user was likely focused on the unmounted element
|
||||
state.activeRef?.current?.focus();
|
||||
setTimeout(() => state.activeRef?.current?.focus(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ export const useRovingTabIndex = <T extends HTMLElement>(
|
|||
}
|
||||
|
||||
// setup (after refs)
|
||||
useLayoutEffect(() => {
|
||||
useEffect(() => {
|
||||
context.dispatch({
|
||||
type: Type.Register,
|
||||
payload: { ref },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue