focus content container only if it does not contain focus already

This commit is contained in:
NikolaBorislavovHristov 2019-08-18 22:13:05 +03:00
parent d43ca4b786
commit 70c40a22c9

View file

@ -31,16 +31,19 @@ const FocusableProvider = ({ children, onRoutesContainerDomTreeChange, onModalsC
return () => {
routesContainerDomTreeObserver.disconnect();
modalsContainerDomTreeObserver.disconnect();
}
};
}, [routesContainer, modalsContainer, onRoutesContainerDomTreeChange, onModalsContainerDomTreeChange]);
React.useEffect(() => {
if (focusable) {
if (focusable && !contentContainerRef.current.contains(document.activeElement)) {
contentContainerRef.current.focus();
}
}, [focusable]);
return (
<FocusableContext.Provider value={focusable}>
{React.cloneElement(React.Children.only(children), { ref: contentContainerRef, tabIndex: -1 })}
{React.cloneElement(React.Children.only(children), {
ref: contentContainerRef,
tabIndex: -1
})}
</FocusableContext.Provider>
);
};