fix: admin: alt+NUMBER navigation shouldn't work while dialogs are open

Massimo Melina committed Jun 9, 2024 at 11:05 UTC a81d552303088c5a0ecc0b6ea5e55d6d8419b05a
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'
@@ -50,6 +50,7 @@ function Routed() {
50 const xs = current?.noPaddingOnMobile ? 0 : 1
51 const navigate = useNavigate()
52 useEventListener('keydown', ({ key, ctrlKey, altKey }) => {
53 + if (anyDialogOpen()) return
54 if (!(isMac ? ctrlKey : altKey)) return // alt doesn't work on Mac, but it is the only suitable key on Windows
55 const idx = Number(xlate(key, { 0: 10 })) // key 0 is after 9 and works as 10
56 if (!idx) return
shared/dialogs.ts
+4
@@ -213,4 +213,8 @@ function closeDialogAt(i: number, value?: any) {
213 const [d] = dialogs.splice(i,1)
214 ;(focusBak.pop() as any)?.focus?.() // if element is not HTMLElement, it doesn't have focus method
215 return d?.onClose?.(value)
216 +}
217 +
218 +export function anyDialogOpen() {
219 + return dialogs.length > 0
220 }
\ No newline at end of file