diff --git a/src/frontend/components/UI/Dialog/components/Dialog.tsx b/src/frontend/components/UI/Dialog/components/Dialog.tsx index 345872b89b..7f98fa4a40 100644 --- a/src/frontend/components/UI/Dialog/components/Dialog.tsx +++ b/src/frontend/components/UI/Dialog/components/Dialog.tsx @@ -39,20 +39,21 @@ export const Dialog: React.FC = ({ onClose }) => { const [open, setOpen] = useState(true) - const [focusOnClose, setFocusOnClose] = useState(null) const { disableDialogBackdropClose } = useContext(ContextProvider) useEffect(() => { - setFocusOnClose(document.querySelector('*:focus')) + // HACK: Focussing the dialog using JS does not seem to work + // Instead, simulate one or two tab presses + // One tab to focus the dialog + window.api.gamepadAction({ action: 'tab' }) + // Second tab to skip the close button if it's shown + if (showCloseButton) window.api.gamepadAction({ action: 'tab' }) }, []) const close = useCallback(() => { setOpen(false) onClose() - if (focusOnClose) { - setTimeout(() => focusOnClose.focus(), 200) - } - }, [onClose, focusOnClose]) + }, [onClose]) return (