Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Make modal backgrounds genuinely inert

pulse-triage[bot]a1a5c53f48fb
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index f697de71f7..65449af698 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -1011,8 +1011,12 @@ named tabs, keyboard focus, dialog focus containment, and phone-width overflow
checks; journey 83 is the desktop/browser accessibility proof and is not
mobile-device proof.
The shared `Dialog` runtime in `useDialogState.ts` owns focus containment,
-body-scroll locking, and focus restoration for every modal and drawer. Closing
-an overlay must restore its previous trigger with `preventScroll`; a plain
+body-scroll locking, background isolation, and focus restoration for every
+modal and drawer. While a dialog is open, every body-level surface outside the
+topmost dialog portal is inert, including surfaces added after opening; nested
+dialogs make their underlying dialog inert. The final close restores each
+surface's pre-existing inert state. Closing an overlay must restore its
+previous trigger with `preventScroll`; a plain
`focus()` may make the app scroll shell jump to a virtualized or previously
off-screen trigger just as the operator dismisses the overlay. Escape belongs
to the top dialog and must stop the same keydown from reaching later global or
diff --git a/frontend-modern/browser-verification.json b/frontend-modern/browser-verification.json
index d0cf6ecc6e..c7e6fdbe9e 100644
--- a/frontend-modern/browser-verification.json
+++ b/frontend-modern/browser-verification.json
@@ -1,27 +1,18 @@
{
"version": 1,
- "base_sha": "a7f1a5e25ffd636c98ee51065c2fe0f0dc7086a6",
- "verified_at": "2026-08-30T14:28:38Z",
+ "base_sha": "712f1a3bfeff8f78de242b97fc66526d8f7c5761",
+ "verified_at": "2026-08-30T15:06:15Z",
"result": "passed",
"changed_paths": [
- "frontend-modern/src/api/availabilityHistory.ts",
- "frontend-modern/src/api/availabilityTargets.ts",
- "frontend-modern/src/features/standalone/AvailabilityChecksTable.tsx",
- "frontend-modern/src/features/standalone/AvailabilityFleetView.tsx",
- "frontend-modern/src/features/standalone/StandalonePageSurface.tsx",
- "frontend-modern/src/routing/resourceLinks.ts"
+ "frontend-modern/src/components/shared/Dialog.tsx",
+ "frontend-modern/src/components/shared/useDialogState.ts"
],
"content_sha256": {
- "frontend-modern/src/api/availabilityHistory.ts": "1fea7ef0612b872c387213e590b47fe42ecdb87ca2678b7b01b546273da65b0d",
- "frontend-modern/src/api/availabilityTargets.ts": "549826b1af427820b9d29d53cc68d895ae19a3e1a9426485fc34903972c55109",
- "frontend-modern/src/features/standalone/AvailabilityChecksTable.tsx": "eef59dc4eea1e7c4029cf3e89c29c7a7ed26484a67bdea213bfdc019ed3bb10e",
- "frontend-modern/src/features/standalone/AvailabilityFleetView.tsx": "e6a21fcd193c51b3e0d164ca549821c6d2bf34c92c45fe884b019b56f3c87127",
- "frontend-modern/src/features/standalone/StandalonePageSurface.tsx": "20d3a5c2107c5510d579e2456bd1aba741137f05acff8acca6805dc8fd387563",
- "frontend-modern/src/routing/resourceLinks.ts": "dee9a426de785e23390ba49c9067f55c8f923cecfce1247ff18f9b1004e0cc90"
+ "frontend-modern/src/components/shared/Dialog.tsx": "58b41841c2ac21939a9e1493754c314e77a1650d1d024de152ebbb39ba3d67a0",
+ "frontend-modern/src/components/shared/useDialogState.ts": "290cab00130c6de5731499a008cc432eb588c97c62e24d0b21940946d37e6e9c"
},
"routes": [
- "/standalone/availability?view=fleet",
- "/standalone/availability"
+ "/settings/infrastructure"
],
"viewports": [
{
@@ -34,17 +25,15 @@
}
],
"states": [
- "Fleet view rendered all seven mock availability targets with current status, method, source, last check, categorical state history, reachable-only latency history, coverage text, and revision boundaries",
- "The textual Reachable, Unreachable, Indeterminate, and Unknown legend remained visible without relying on color alone",
- "The resource detail drawer opened from an availability tile and preserved the existing canonical resource detail presentation",
- "The solar search state reduced the fleet to one matching target and persisted q=solar in the URL",
- "Table view restored all seven availability rows with the fleet parameter removed, and switching back restored view=fleet",
- "The 390 by 844 layout kept the fleet controls usable and stacked availability tiles into a readable single column"
+ "The Add infrastructure dialog remained visible and horizontally contained with its close control focused at desktop and narrow viewports",
+ "The active dialog portal stayed interactive while the app root and every other body-level surface were inert",
+ "A body-level surface added after opening became inert before inspection",
+ "Closing restored ordinary surfaces while preserving a surface that was already inert before opening"
],
"interactions": [
- "opened an availability tile and dismissed the canonical resource detail drawer",
- "entered and cleared the solar search filter while checking the URL-owned query state",
- "switched from Fleet to Table and back through the shared View control while checking URL and row or tile counts",
- "repeated the fleet inspection at desktop and narrow viewports and checked scrolling, clipping, history labels, and control placement"
+ "opened Add infrastructure from its real settings trigger at desktop and narrow viewports",
+ "verified a late-added background action could not be activated while the modal was open",
+ "closed with Escape and verified focus returned to the Add infrastructure trigger",
+ "activated the late-added action after close to verify restored operability"
]
}
diff --git a/frontend-modern/src/components/shared/Dialog.tsx b/frontend-modern/src/components/shared/Dialog.tsx
index aa1041ee46..96eca561e6 100644
--- a/frontend-modern/src/components/shared/Dialog.tsx
+++ b/frontend-modern/src/components/shared/Dialog.tsx
@@ -27,7 +27,7 @@ export const Dialog: Component<DialogProps> = (props) => {
return (
<Show when={props.isOpen}>
<Portal mount={document.body}>
- <div class="fixed inset-0 z-[1000]">
+ <div ref={state.setLayerRef} class="fixed inset-0 z-[1000]" data-dialog-layer>
<div
class="absolute inset-0 bg-black/60 backdrop-blur-sm transition-opacity duration-300"
data-dialog-backdrop
diff --git a/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx b/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx
index 02ac841ff1..53c1dda997 100644
--- a/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx
@@ -7,9 +7,20 @@ import dialogSource from '@/components/shared/Dialog.tsx?raw';
import dialogModelSource from '@/components/shared/dialogModel.ts?raw';
import dialogStateSource from '@/components/shared/useDialogState.ts?raw';
+function getBodyChild(element: HTMLElement): HTMLElement {
+ let bodyChild = element;
+ while (bodyChild.parentElement && bodyChild.parentElement !== document.body) {
+ bodyChild = bodyChild.parentElement;
+ }
+ return bodyChild;
+}
+
describe('Dialog', () => {
afterEach(() => {
cleanup();
+ document
+ .querySelectorAll('[data-dialog-test-background]')
+ .forEach((element) => element.remove());
document.body.style.overflow = '';
});
@@ -31,6 +42,8 @@ describe('Dialog', () => {
expect(dialogStateSource).toContain('openDialogCount');
expect(dialogStateSource).toContain('dialogStackHasBlockingDialog');
expect(dialogStateSource).toContain('getDialogFocusableElements');
+ expect(dialogStateSource).toContain('syncBackgroundInertness');
+ expect(dialogStateSource).toContain('MutationObserver');
expect(dialogModelSource).toContain('export function getDialogLayout');
expect(dialogModelSource).toContain('export function getDialogFocusableElements');
@@ -93,6 +106,91 @@ describe('Dialog', () => {
expect(dialogStackHasBlockingDialog()).toBe(false);
});
+ it('makes every body-level background surface inert while open and restores it on close', () => {
+ const background = document.createElement('main');
+ background.dataset.dialogTestBackground = 'true';
+ document.body.appendChild(background);
+
+ const { unmount } = render(() => (
+ <Dialog isOpen={true} onClose={() => undefined}>
+ <button type="button">Dialog action</button>
+ </Dialog>
+ ));
+
+ const dialogBodyChild = getBodyChild(screen.getByRole('dialog'));
+
+ expect(background).toHaveAttribute('inert');
+ expect(dialogBodyChild).not.toHaveAttribute('inert');
+
+ unmount();
+ expect(background).not.toHaveAttribute('inert');
+ });
+
+ it('preserves a pre-existing inert state after the final dialog closes', () => {
+ const background = document.createElement('main');
+ background.dataset.dialogTestBackground = 'true';
+ background.setAttribute('inert', '');
+ document.body.appendChild(background);
+
+ const { unmount } = render(() => (
+ <Dialog isOpen={true} onClose={() => undefined}>
+ <button type="button">Dialog action</button>
+ </Dialog>
+ ));
+
+ expect(background).toHaveAttribute('inert');
+ unmount();
+ expect(background).toHaveAttribute('inert');
+ });
+
+ it('keeps only the topmost dialog layer interactive', async () => {
+ const [innerOpen, setInnerOpen] = createSignal(false);
+ render(() => (
+ <>
+ <Dialog isOpen={true} onClose={() => undefined} ariaLabel="Outer dialog">
+ <button type="button" onClick={() => setInnerOpen(true)}>
+ Open inner dialog
+ </button>
+ </Dialog>
+ <Dialog isOpen={innerOpen()} onClose={() => setInnerOpen(false)} ariaLabel="Inner dialog">
+ <button type="button">Inner action</button>
+ </Dialog>
+ </>
+ ));
+
+ const outerDialog = screen.getByRole('dialog', { name: 'Outer dialog' });
+ const outerLayer = outerDialog.closest<HTMLElement>('[data-dialog-layer]');
+ expect(outerLayer).not.toBeNull();
+ expect(outerLayer).not.toHaveAttribute('inert');
+
+ fireEvent.click(screen.getByRole('button', { name: 'Open inner dialog' }));
+ await Promise.resolve();
+
+ const innerDialog = screen.getByRole('dialog', { name: 'Inner dialog' });
+ const innerLayer = innerDialog.closest<HTMLElement>('[data-dialog-layer]');
+ expect(innerLayer).not.toBeNull();
+ expect(getBodyChild(outerDialog)).toHaveAttribute('inert');
+ expect(getBodyChild(innerDialog)).not.toHaveAttribute('inert');
+
+ fireEvent.keyDown(document, { key: 'Escape' });
+ expect(getBodyChild(outerDialog)).not.toHaveAttribute('inert');
+ });
+
+ it('makes body-level surfaces added while a dialog is open inert', async () => {
+ render(() => (
+ <Dialog isOpen={true} onClose={() => undefined}>
+ <button type="button">Dialog action</button>
+ </Dialog>
+ ));
+
+ const lateSurface = document.createElement('aside');
+ lateSurface.dataset.dialogTestBackground = 'true';
+ document.body.appendChild(lateSurface);
+ await new Promise((resolve) => setTimeout(resolve, 0));
+
+ expect(lateSurface).toHaveAttribute('inert');
+ });
+
it('keeps keyboard focus trapped in the dialog', async () => {
const onClose = vi.fn();
render(() => (
diff --git a/frontend-modern/src/components/shared/useDialogState.ts b/frontend-modern/src/components/shared/useDialogState.ts
index ed3a4d8e8c..6b2a439305 100644
--- a/frontend-modern/src/components/shared/useDialogState.ts
+++ b/frontend-modern/src/components/shared/useDialogState.ts
@@ -12,43 +12,97 @@ interface DialogStateOptions {
let openDialogCount = 0;
let previousBodyOverflow = '';
const [dialogStackDepth, setDialogStackDepth] = createSignal(0);
-const dialogStack: symbol[] = [];
+interface DialogStackEntry {
+ id: symbol;
+ layer?: HTMLElement;
+}
+
+const dialogStack: DialogStackEntry[] = [];
+// Solid portals are body-level siblings of the app and of one another. Preserve
+// each sibling's existing state so nested dialogs can isolate the active layer
+// without permanently changing surfaces owned by another feature.
+const backgroundInertState = new Map<HTMLElement, boolean>();
+let bodyObserver: MutationObserver | undefined;
export function dialogStackHasBlockingDialog() {
return dialogStackDepth() > 0;
}
-function lockBodyScroll(dialogId: symbol) {
+function getBodyChildContaining(element: HTMLElement | undefined): HTMLElement | undefined {
+ if (!element || typeof document === 'undefined' || !document.body.contains(element)) {
+ return undefined;
+ }
+
+ let bodyChild = element;
+ while (bodyChild.parentElement && bodyChild.parentElement !== document.body) {
+ bodyChild = bodyChild.parentElement;
+ }
+ return bodyChild.parentElement === document.body ? bodyChild : undefined;
+}
+
+function syncBackgroundInertness() {
+ if (typeof document === 'undefined') return;
+
+ const topmostLayer = dialogStack[dialogStack.length - 1]?.layer;
+ const activeBodyChild = getBodyChildContaining(topmostLayer);
+
+ for (const child of Array.from(document.body.children)) {
+ if (!(child instanceof HTMLElement)) continue;
+ if (!backgroundInertState.has(child)) {
+ backgroundInertState.set(child, child.hasAttribute('inert'));
+ }
+ child.toggleAttribute('inert', child !== activeBodyChild);
+ }
+}
+
+function restoreBackgroundInertness() {
+ bodyObserver?.disconnect();
+ bodyObserver = undefined;
+ for (const [element, wasInert] of backgroundInertState) {
+ element.toggleAttribute('inert', wasInert);
+ }
+ backgroundInertState.clear();
+}
+
+function lockBodyScroll(dialogId: symbol, layer: HTMLElement | undefined) {
if (typeof document === 'undefined') return;
if (openDialogCount === 0) {
previousBodyOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
+ bodyObserver = new MutationObserver(syncBackgroundInertness);
+ bodyObserver.observe(document.body, { childList: true });
}
- dialogStack.push(dialogId);
+ dialogStack.push({ id: dialogId, layer });
openDialogCount = dialogStack.length;
setDialogStackDepth(openDialogCount);
+ syncBackgroundInertness();
}
function unlockBodyScroll(dialogId: symbol) {
if (typeof document === 'undefined') return;
- const stackIndex = dialogStack.lastIndexOf(dialogId);
+ const stackIndex = dialogStack.findIndex((entry) => entry.id === dialogId);
if (stackIndex !== -1) dialogStack.splice(stackIndex, 1);
openDialogCount = dialogStack.length;
setDialogStackDepth(openDialogCount);
if (openDialogCount === 0) {
document.body.style.overflow = previousBodyOverflow;
+ restoreBackgroundInertness();
+ } else {
+ syncBackgroundInertness();
}
}
function isTopmostDialog(dialogId: symbol) {
- return dialogStack[dialogStack.length - 1] === dialogId;
+ return dialogStack[dialogStack.length - 1]?.id === dialogId;
}
export function useDialogState(options: DialogStateOptions): {
handleBackdropClick: () => void;
layout: Accessor<DialogLayout>;
+ setLayerRef: (el: HTMLDivElement) => void;
setPanelRef: (el: HTMLDivElement) => void;
} {
+ let layerRef: HTMLDivElement | undefined;
let panelRef: HTMLDivElement | undefined;
const dialogId = Symbol('dialog');
@@ -57,7 +111,7 @@ export function useDialogState(options: DialogStateOptions): {
const previousFocus =
document.activeElement instanceof HTMLElement ? document.activeElement : null;
- lockBodyScroll(dialogId);
+ lockBodyScroll(dialogId, layerRef);
queueMicrotask(() => {
if (!panelRef || !document.contains(panelRef) || !isTopmostDialog(dialogId)) return;
@@ -128,6 +182,14 @@ export function useDialogState(options: DialogStateOptions): {
}
},
layout: () => getDialogLayout(options.layout),
+ setLayerRef: (el) => {
+ layerRef = el;
+ const entry = dialogStack.find((candidate) => candidate.id === dialogId);
+ if (entry) {
+ entry.layer = el;
+ syncBackgroundInertness();
+ }
+ },
setPanelRef: (el) => {
panelRef = el;
},