try to find focusable candidate before focus the container

This commit is contained in:
NikolaBorislavovHristov 2019-09-16 13:57:08 +03:00
parent 33b6bb0290
commit 5bddb97fa9

View file

@ -35,7 +35,12 @@ const FocusableProvider = ({ children, onRoutesContainerChildrenChange, onModals
}, [routesContainer, modalsContainer, onRoutesContainerChildrenChange, onModalsContainerChildrenChange]);
React.useEffect(() => {
if (focusable && !contentContainerRef.current.contains(document.activeElement)) {
contentContainerRef.current.focus();
const focusableElement = contentContainerRef.current.querySelector('[tabindex]:not([tabindex="-1"])');
if (focusableElement instanceof HTMLElement) {
focusableElement.focus();
} else {
contentContainerRef.current.focus();
}
}
}, [focusable]);
return (