fix: admin: alt+NUMBER navigation shouldn't work while dialogs are open
Massimo Melina committed
Jun 9, 2024 at 11:05 UTC
d4729d129b316d4f84486d7f962278fa0c6b0925
2 files changed
+6
-1
admin/src/App.ts
+2
-1
@@ -4,7 +4,7 @@ import { createElement as h, Fragment, useState } from 'react'
4
import { HashRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom'
5
import MainMenu, { getMenuLabel, mainMenu } from './MainMenu'
6
import { AppBar, Box, Drawer, IconButton, ThemeProvider, Toolbar, Typography } from '@mui/material'
7
-import { Dialogs } from './dialog'
7
+import { anyDialogOpen, Dialogs } from './dialog'
8
import { useMyTheme } from './theme'
9
import { useBreakpoint} from './mui'
10
import { LoginRequired } from './LoginRequired'
@@ -49,6 +49,7 @@ function Routed() {
49
const xs = current?.noPaddingOnMobile ? 0 : 1
50
const navigate = useNavigate()
51
useEventListener('keydown', ({ key, ctrlKey, altKey }) => {
52
+ if (anyDialogOpen()) return
53
if (!(isMac ? ctrlKey : altKey)) return // alt doesn't work on Mac, but it is the only suitable key on Windows
54
const idx = Number(xlate(key, { 0: 10 })) // key 0 is after 9 and works as 10
55
if (!idx) return
shared/dialogs.ts
+4
@@ -211,4 +211,8 @@ function closeDialogAt(i: number, value?: any) {
211
const [d] = dialogs.splice(i,1)
212
;(focusBak.pop() as any)?.focus?.() // if element is not HTMLElement, it doesn't have focus method
213
return d?.onClose?.(value)
214
+}
215
+
216
+export function anyDialogOpen() {
217
+ return dialogs.length > 0
218
}
\ No newline at end of file