prevent focus root element when route became focusable

This commit is contained in:
NikolaBorislavovHristov 2019-08-09 14:10:32 +03:00
parent 1c2b2c1911
commit d7ad6517a7

View file

@ -21,10 +21,6 @@ const FocusableProvider = ({ children, onRoutesContainerDomTreeChange, onModalsC
modalsContainer: modalsContainer, modalsContainer: modalsContainer,
contentContainer: contentContainerRef.current contentContainer: contentContainerRef.current
}); });
if (focusable) {
contentContainerRef.current.focus();
}
setFocusable(focusable); setFocusable(focusable);
}; };
const routesContainerDomTreeObserver = new MutationObserver(onDomTreeChange); const routesContainerDomTreeObserver = new MutationObserver(onDomTreeChange);
@ -39,7 +35,7 @@ const FocusableProvider = ({ children, onRoutesContainerDomTreeChange, onModalsC
}, [routesContainer, modalsContainer, onRoutesContainerDomTreeChange, onModalsContainerDomTreeChange]); }, [routesContainer, modalsContainer, onRoutesContainerDomTreeChange, onModalsContainerDomTreeChange]);
return ( return (
<FocusableContext.Provider value={focusable}> <FocusableContext.Provider value={focusable}>
{React.cloneElement(React.Children.only(children), { ref: contentContainerRef, tabIndex: -1 })} {React.cloneElement(React.Children.only(children), { ref: contentContainerRef })}
</FocusableContext.Provider> </FocusableContext.Provider>
); );
}; };