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.

Keep focus stable after destructive dialogs

pulse-triage[bot]54d43a70c13c
diff --git a/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx b/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx
index 333c1e6ca8..4d453ccdfa 100644
--- a/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx
+++ b/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx
@@ -28,6 +28,7 @@ interface AuditWebhookPanelProps {
export const AuditWebhookPanel: Component<AuditWebhookPanelProps> = (props) => {
const [urlToRemove, setUrlToRemove] = createSignal<string | null>(null);
+ let newUrlInputRef: HTMLInputElement | undefined;
const {
canManage,
handleAddWebhook,
@@ -124,6 +125,7 @@ export const AuditWebhookPanel: Component<AuditWebhookPanelProps> = (props) => {
</Show>
<div class="flex gap-3 pt-4 border-t border-border">
<input
+ ref={newUrlInputRef}
type="text"
placeholder="https://your-api.com/webhook"
class={`${formControl} flex-1`}
@@ -168,6 +170,7 @@ export const AuditWebhookPanel: Component<AuditWebhookPanelProps> = (props) => {
onClose={() => setUrlToRemove(null)}
panelClass="max-w-md"
ariaLabel="Remove audit webhook"
+ returnFocus={() => newUrlInputRef}
>
<div class="w-full p-6">
<h3 class="text-lg font-semibold text-base-content mb-2">Remove audit webhook?</h3>
diff --git a/frontend-modern/src/components/Settings/UserAssignmentsPanel.tsx b/frontend-modern/src/components/Settings/UserAssignmentsPanel.tsx
index 92968e0d4b..956365b26d 100644
--- a/frontend-modern/src/components/Settings/UserAssignmentsPanel.tsx
+++ b/frontend-modern/src/components/Settings/UserAssignmentsPanel.tsx
@@ -23,6 +23,7 @@ import { Dialog } from '@/components/shared/Dialog';
export const UserAssignmentsPanel: Component = () => {
const state = useUserAssignmentsPanelState();
const emptyStateCopy = () => getUserAssignmentsEmptyStateCopy();
+ let searchInputRef: HTMLInputElement | undefined;
return (
<div class="space-y-6">
@@ -30,6 +31,9 @@ export const UserAssignmentsPanel: Component = () => {
title="User Access"
action={
<SearchField
+ inputRef={(element) => {
+ searchInputRef = element;
+ }}
placeholder="Search users..."
value={state.searchQuery()}
onChange={state.setSearchQuery}
@@ -212,6 +216,7 @@ export const UserAssignmentsPanel: Component = () => {
closeOnBackdrop={false}
panelClass="max-w-lg"
ariaLabel={`Remove user access: ${getUserIdentityDisplayName(user())}`}
+ returnFocus={() => searchInputRef}
>
<div class="space-y-5 p-6">
<div>
diff --git a/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx b/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx
index 0d4f708dc4..ac1f37aaca 100644
--- a/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx
@@ -247,16 +247,15 @@ describe('RBAC paywall settings panels', () => {
});
it('shows readable SSO identity details and confirms deprovisioning', async () => {
- getUsersMock.mockResolvedValueOnce([
- {
- username: 'sso:oidc:okta:opaque_subject',
- displayName: 'Alice Example',
- email: '[email protected]',
- providerType: 'oidc',
- providerId: 'okta',
- roleIds: ['admin'],
- },
- ]);
+ const user = {
+ username: 'sso:oidc:okta:opaque_subject',
+ displayName: 'Alice Example',
+ email: '[email protected]',
+ providerType: 'oidc',
+ providerId: 'okta',
+ roleIds: ['admin'],
+ };
+ getUsersMock.mockResolvedValueOnce([user]).mockResolvedValueOnce([]);
render(() => <UserAssignmentsPanel />);
@@ -274,6 +273,10 @@ describe('RBAC paywall settings panels', () => {
expect(deleteUserMock).toHaveBeenCalledWith('sso:oidc:okta:opaque_subject');
});
expect(notificationSuccessMock).toHaveBeenCalledWith('User access removed for Alice Example');
+ await waitFor(() => {
+ expect(screen.queryByText('Alice Example')).not.toBeInTheDocument();
+ });
+ expect(screen.getByPlaceholderText('Search users...')).toHaveFocus();
});
it('does not render stale user data when assignment storage is unavailable', async () => {
diff --git a/frontend-modern/src/components/Settings/__tests__/settingsReadOnlyPanels.test.tsx b/frontend-modern/src/components/Settings/__tests__/settingsReadOnlyPanels.test.tsx
index 6bc88c8b2f..6a39a88e6f 100644
--- a/frontend-modern/src/components/Settings/__tests__/settingsReadOnlyPanels.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/settingsReadOnlyPanels.test.tsx
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { cleanup, render, screen, waitFor } from '@solidjs/testing-library';
+import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
import { SecurityAuthPanel } from '../SecurityAuthPanel';
@@ -160,6 +160,22 @@ describe('settings read-only panel states', () => {
expect(screen.getByRole('button', { name: /add endpoint/i })).toBeDisabled();
});
+ it('returns focus to the endpoint field after removing a webhook row', async () => {
+ render(() => <AuditWebhookPanel />);
+
+ const removeButton = await screen.findByRole('button', { name: 'Remove webhook endpoint' });
+ fireEvent.click(removeButton);
+ expect(screen.getByRole('dialog', { name: 'Remove audit webhook' })).toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Remove webhook' }));
+ await waitFor(() => {
+ expect(
+ screen.queryByRole('button', { name: 'Remove webhook endpoint' }),
+ ).not.toBeInTheDocument();
+ });
+ expect(screen.getByPlaceholderText('https://your-api.com/webhook')).toHaveFocus();
+ });
+
it('keeps audit webhook locked copy neutral when upgrade prompts are hidden', async () => {
hasFeatureMock.mockImplementation((feature: string) => feature !== 'audit_logging');
presentationPolicyHidesUpgradePromptsMock.mockReturnValue(true);
diff --git a/frontend-modern/src/components/shared/Dialog.tsx b/frontend-modern/src/components/shared/Dialog.tsx
index 96eca561e6..f00014d077 100644
--- a/frontend-modern/src/components/shared/Dialog.tsx
+++ b/frontend-modern/src/components/shared/Dialog.tsx
@@ -19,6 +19,7 @@ interface DialogProps {
ariaLabel?: string;
ariaLabelledBy?: string;
ariaDescribedBy?: string;
+ returnFocus?: () => HTMLElement | null | undefined;
}
export const Dialog: Component<DialogProps> = (props) => {
diff --git a/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx b/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx
index 53c1dda997..1d86f3a644 100644
--- a/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/Dialog.test.tsx
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
-import { createSignal } from 'solid-js';
+import { createSignal, Show } from 'solid-js';
import { Dialog } from '@/components/shared/Dialog';
import { dialogStackHasBlockingDialog } from '@/components/shared/useDialogState';
import dialogSource from '@/components/shared/Dialog.tsx?raw';
@@ -330,4 +330,42 @@ describe('Dialog', () => {
expect(focusSpy).toHaveBeenCalledWith({ preventScroll: true });
expect(trigger).toHaveFocus();
});
+
+ it('can return focus to a stable workflow target when the trigger is removed', async () => {
+ const [isOpen, setIsOpen] = createSignal(false);
+ const [showTrigger, setShowTrigger] = createSignal(true);
+ let stableTarget: HTMLButtonElement | undefined;
+ render(() => (
+ <>
+ <button ref={stableTarget} type="button">
+ Stable target
+ </button>
+ <Show when={showTrigger()}>
+ <button type="button" onClick={() => setIsOpen(true)}>
+ Remove item
+ </button>
+ </Show>
+ <Dialog
+ isOpen={isOpen()}
+ onClose={() => {
+ setShowTrigger(false);
+ setIsOpen(false);
+ }}
+ returnFocus={() => stableTarget}
+ >
+ <button type="button" onClick={() => setIsOpen(false)}>
+ Cancel
+ </button>
+ </Dialog>
+ </>
+ ));
+
+ const trigger = screen.getByRole('button', { name: 'Remove item' });
+ trigger.focus();
+ await fireEvent.click(trigger);
+ fireEvent.keyDown(document, { key: 'Escape' });
+
+ expect(screen.queryByRole('button', { name: 'Remove item' })).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Stable target' })).toHaveFocus();
+ });
});
diff --git a/frontend-modern/src/components/shared/useDialogState.ts b/frontend-modern/src/components/shared/useDialogState.ts
index 6b2a439305..3d4203136a 100644
--- a/frontend-modern/src/components/shared/useDialogState.ts
+++ b/frontend-modern/src/components/shared/useDialogState.ts
@@ -7,6 +7,7 @@ interface DialogStateOptions {
isOpen: boolean;
layout?: DialogLayout;
onClose: () => void;
+ returnFocus?: () => HTMLElement | null | undefined;
}
let openDialogCount = 0;
@@ -169,8 +170,15 @@ export function useDialogState(options: DialogStateOptions): {
const shouldRestoreFocus = isTopmostDialog(dialogId);
document.removeEventListener('keydown', onKeyDown);
unlockBodyScroll(dialogId);
- if (shouldRestoreFocus && previousFocus && document.contains(previousFocus)) {
- previousFocus.focus({ preventScroll: true });
+ if (shouldRestoreFocus) {
+ const requestedReturnFocus = options.returnFocus?.();
+ const returnTarget =
+ requestedReturnFocus && document.contains(requestedReturnFocus)
+ ? requestedReturnFocus
+ : previousFocus && document.contains(previousFocus)
+ ? previousFocus
+ : null;
+ returnTarget?.focus({ preventScroll: true });
}
});
});