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 in-app help dialogs keyboard accessible

pulse-triage[bot]32400d3a9c9f
diff --git a/frontend-modern/src/components/shared/HelpIcon.tsx b/frontend-modern/src/components/shared/HelpIcon.tsx
index fcb37b04c8..15f15100be 100644
--- a/frontend-modern/src/components/shared/HelpIcon.tsx
+++ b/frontend-modern/src/components/shared/HelpIcon.tsx
@@ -1,4 +1,4 @@
-import { Component, Show } from 'solid-js';
+import { Component, Show, createUniqueId } from 'solid-js';
import { Portal } from 'solid-js/web';
import CircleHelp from 'lucide-solid/icons/circle-help';
import ExternalLink from 'lucide-solid/icons/external-link';
@@ -11,6 +11,8 @@ export type { HelpIconProps } from './helpIconModel';
export const HelpIcon: Component<HelpIconProps> = (props) => {
const state = useHelpIconState(props);
const helpContent = state.helpContent();
+ const popoverId = `help-popover-${createUniqueId()}`;
+ const titleId = `${popoverId}-title`;
// Don't render if no content available
if (!helpContent) {
@@ -27,6 +29,7 @@ export const HelpIcon: Component<HelpIconProps> = (props) => {
aria-label={`Help: ${helpContent.title}`}
aria-expanded={state.isOpen()}
aria-haspopup="dialog"
+ aria-controls={state.isOpen() ? popoverId : undefined}
>
<CircleHelp class={helpIconSizeClasses[state.size()]} strokeWidth={2} />
</button>
@@ -35,8 +38,9 @@ export const HelpIcon: Component<HelpIconProps> = (props) => {
<Portal mount={document.body}>
<div
ref={state.setPopoverRef}
+ id={popoverId}
role="dialog"
- aria-labelledby="help-popover-title"
+ aria-labelledby={titleId}
class="fixed z-[9999] bg-surface rounded-md shadow-sm border border-border overflow-hidden animate-in fade-in-0 zoom-in-95 duration-150"
style={{
top: `${state.popoverPosition().top}px`,
@@ -47,13 +51,14 @@ export const HelpIcon: Component<HelpIconProps> = (props) => {
>
{/* Header */}
<div class="px-3 py-2 bg-surface-alt border-b border-border flex items-center justify-between gap-2">
- <span id="help-popover-title" class="text-sm font-medium text-base-content">
+ <span id={titleId} class="text-sm font-medium text-base-content">
{helpContent.title}
</span>
<button
+ ref={state.setCloseButtonRef}
type="button"
- class="p-0.5 text-slate-400 hover:text-muted rounded transition-colors"
- onClick={() => state.setIsOpen(false)}
+ class="inline-flex min-h-11 min-w-11 items-center justify-center rounded text-slate-400 transition-colors hover:text-muted sm:min-h-8 sm:min-w-8"
+ onClick={state.closeAndRestoreFocus}
aria-label="Close help"
>
<X class="w-3.5 h-3.5" strokeWidth={2} />
diff --git a/frontend-modern/src/components/shared/__tests__/HelpIcon.test.tsx b/frontend-modern/src/components/shared/__tests__/HelpIcon.test.tsx
index eaf013cfe3..a490ccbe31 100644
--- a/frontend-modern/src/components/shared/__tests__/HelpIcon.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/HelpIcon.test.tsx
@@ -22,6 +22,7 @@ vi.mock('@/content/help', () => ({
describe('HelpIcon', () => {
afterEach(() => {
vi.restoreAllMocks();
+ vi.unstubAllGlobals();
});
it('keeps the help icon on shell, runtime, and model owners', () => {
@@ -57,4 +58,57 @@ describe('HelpIcon', () => {
expect(screen.getByText('Inline description')).toBeInTheDocument();
expect(screen.getByText('Example A')).toBeInTheDocument();
});
+
+ it('moves focus into the portalled dialog and restores it when closed', async () => {
+ vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
+ callback(0);
+ return 1;
+ });
+ render(() => (
+ <HelpIcon
+ inline={{
+ title: 'Inline help',
+ description: 'Inline description',
+ }}
+ />
+ ));
+
+ const trigger = screen.getByRole('button', { name: 'Help: Inline help' });
+ fireEvent.click(trigger);
+
+ const dialog = await screen.findByRole('dialog', { name: 'Inline help' });
+ const close = screen.getByRole('button', { name: 'Close help' });
+ expect(close).toHaveFocus();
+ expect(close).toHaveClass('min-h-11', 'min-w-11', 'sm:min-h-8', 'sm:min-w-8');
+ expect(trigger).toHaveAttribute('aria-controls', dialog.id);
+ expect(dialog).toHaveAttribute('aria-labelledby');
+ expect(document.getElementById(dialog.getAttribute('aria-labelledby')!)).toHaveTextContent(
+ 'Inline help',
+ );
+
+ fireEvent.click(close);
+ expect(screen.queryByRole('dialog', { name: 'Inline help' })).not.toBeInTheDocument();
+ expect(trigger).toHaveFocus();
+ });
+
+ it('uses distinct labels when more than one help dialog is open', async () => {
+ vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
+ callback(0);
+ return 1;
+ });
+ render(() => (
+ <>
+ <HelpIcon inline={{ title: 'First help', description: 'First description' }} />
+ <HelpIcon inline={{ title: 'Second help', description: 'Second description' }} />
+ </>
+ ));
+
+ fireEvent.click(screen.getByRole('button', { name: 'Help: First help' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Help: Second help' }));
+
+ const first = await screen.findByRole('dialog', { name: 'First help' });
+ const second = await screen.findByRole('dialog', { name: 'Second help' });
+ expect(first.id).not.toBe(second.id);
+ expect(first.getAttribute('aria-labelledby')).not.toBe(second.getAttribute('aria-labelledby'));
+ });
});
diff --git a/frontend-modern/src/components/shared/useHelpIconState.ts b/frontend-modern/src/components/shared/useHelpIconState.ts
index 2710fffba1..7cc1920490 100644
--- a/frontend-modern/src/components/shared/useHelpIconState.ts
+++ b/frontend-modern/src/components/shared/useHelpIconState.ts
@@ -13,12 +13,17 @@ export function useHelpIconState(props: HelpIconProps) {
const [isOpen, setIsOpen] = createSignal(false);
const [popoverPosition, setPopoverPosition] = createSignal({ top: 0, left: 0 });
const [buttonRef, setButtonRef] = createSignal<HTMLButtonElement>();
+ const [closeButtonRef, setCloseButtonRef] = createSignal<HTMLButtonElement>();
const [popoverRef, setPopoverRef] = createSignal<HTMLDivElement>();
const helpContent = createMemo(() => resolveHelpContent(props));
const size = createMemo(() => getHelpIconSize(props.size));
const maxWidth = createMemo(() => getHelpPopoverMaxWidth(props.maxWidth));
const preferredPosition = createMemo(() => getHelpPopoverPreferredPosition(props.position));
+ const closeAndRestoreFocus = () => {
+ setIsOpen(false);
+ buttonRef()?.focus({ preventScroll: true });
+ };
createEffect(() => {
if (!isOpen() || !buttonRef()) return;
@@ -37,6 +42,7 @@ export function useHelpIconState(props: HelpIconProps) {
viewportHeight: window.innerHeight,
}),
);
+ closeButtonRef()?.focus({ preventScroll: true });
});
});
@@ -54,8 +60,7 @@ export function useHelpIconState(props: HelpIconProps) {
const handleEscape = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
- setIsOpen(false);
- button?.focus();
+ closeAndRestoreFocus();
}
};
@@ -83,6 +88,7 @@ export function useHelpIconState(props: HelpIconProps) {
return {
buttonRef,
+ closeAndRestoreFocus,
helpContent,
isOpen,
maxWidth,
@@ -90,6 +96,7 @@ export function useHelpIconState(props: HelpIconProps) {
popoverRef,
preferredPosition,
setButtonRef,
+ setCloseButtonRef,
setIsOpen,
setPopoverRef,
size,