diff --git a/packages/taler-auditor-webui/src/components/menu/SideBar.tsx b/packages/taler-auditor-webui/src/components/menu/SideBar.tsx index 9d2ecf1a2..ee2aa97ca 100644 --- a/packages/taler-auditor-webui/src/components/menu/SideBar.tsx +++ b/packages/taler-auditor-webui/src/components/menu/SideBar.tsx @@ -5,6 +5,7 @@ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import type { VNode } from "preact"; +import { useEffect, useRef } from "preact/hooks"; import { Link, useLocation } from "wouter-preact"; import { useConfigContext } from "../../context/config.js"; import { Paths } from "../../routing/monitoringRoutes.js"; @@ -19,6 +20,17 @@ export function Sidebar({ mobile = false, onClose }: Props): VNode { const config = useConfigContext(); const { i18n } = useTranslationContext(); const [location] = useLocation(); + const closeButton = useRef(null); + useEffect(() => { + if (!mobile) return; + // The mobile drawer covers the page, so move focus into it and give it + // back to the menu button once the drawer closes. + const opener = document.activeElement; + closeButton.current?.focus(); + return () => { + if (opener instanceof HTMLElement && opener.isConnected) opener.focus(); + }; + }, [mobile]); const entries = [ { path: Paths.overview, label: Overview }, { @@ -61,6 +73,7 @@ export function Sidebar({ mobile = false, onClose }: Props): VNode { {mobile && (