Skip to content

Commit e88d290

Browse files
committed
Controller navigation hacks: Transferring focus
Restoring the focussed element on dialog close is already handled by MUI, we don't need this code ourselves Moving focus on dialog open *should* work automatically as well, however it doesn't. I've tried various methods with element properties and JS, nothing seems to work. As a band-aid fix for now, we simulate 1-2 tab presses to focus the dialog content
1 parent 0d5ab0e commit e88d290

File tree

1 file changed

+7
-6
lines changed
  • src/frontend/components/UI/Dialog/components

1 file changed

+7
-6
lines changed

src/frontend/components/UI/Dialog/components/Dialog.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ export const Dialog: React.FC<DialogProps> = ({
3939
onClose
4040
}) => {
4141
const [open, setOpen] = useState(true)
42-
const [focusOnClose, setFocusOnClose] = useState<HTMLElement | null>(null)
4342
const { disableDialogBackdropClose } = useContext(ContextProvider)
4443

4544
useEffect(() => {
46-
setFocusOnClose(document.querySelector<HTMLElement>('*:focus'))
45+
// HACK: Focussing the dialog using JS does not seem to work
46+
// Instead, simulate one or two tab presses
47+
// One tab to focus the dialog
48+
window.api.gamepadAction({ action: 'tab' })
49+
// Second tab to skip the close button if it's shown
50+
if (showCloseButton) window.api.gamepadAction({ action: 'tab' })
4751
}, [])
4852

4953
const close = useCallback(() => {
5054
setOpen(false)
5155
onClose()
52-
if (focusOnClose) {
53-
setTimeout(() => focusOnClose.focus(), 200)
54-
}
55-
}, [onClose, focusOnClose])
56+
}, [onClose])
5657

5758
return (
5859
<MuiDialog

0 commit comments

Comments
 (0)