diff --git a/.Jules/palette.md b/.Jules/palette.md new file mode 100644 index 0000000..1a64430 --- /dev/null +++ b/.Jules/palette.md @@ -0,0 +1,3 @@ +## 2024-07-04 - Accessible Accordion Toggles +**Learning:** When React conditional rendering toggles between summary and full views (e.g., `collapsed ? : `), screen readers lose track of the `aria-controls` target if the `id` is only on the expanded content. The `id` must be applied to *both* branch elements to ensure an unbroken association in all states. +**Action:** Use `useId()` to generate a unique ID and assign it to all conditional branches of an accordion's content. diff --git a/components/accounts/ppp-savings-panel.tsx b/components/accounts/ppp-savings-panel.tsx index e6d961b..da576cc 100644 --- a/components/accounts/ppp-savings-panel.tsx +++ b/components/accounts/ppp-savings-panel.tsx @@ -1,6 +1,6 @@ "use client"; -import { useMemo, useState } from "react"; +import { useId, useMemo, useState } from "react"; import DOMPurify from "isomorphic-dompurify"; import { Calculator, ChevronDown, ChevronUp, Copy, Download, Loader2, Mail } from "lucide-react"; import type { PppSavingsReport } from "@/lib/application/runtime/ppp-savings-service"; @@ -34,6 +34,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) { const [error, setError] = useState(null); const [copied, setCopied] = useState(false); const [collapsed, setCollapsed] = useState(false); + const contentId = useId(); const mailtoHref = useMemo(() => { if (!report?.recipientEmail || !draft) { @@ -102,6 +103,8 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) { type="button" onClick={() => setCollapsed((value) => !value)} aria-expanded={!collapsed} + aria-controls={contentId} + aria-label={collapsed ? "Expand PPP savings details" : "Collapse PPP savings details"} className="inline-flex items-center justify-center gap-2 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-elevated)] px-4 py-3 text-sm font-semibold text-[var(--text-secondary)] transition hover:border-[var(--border-strong)] hover:text-[var(--text-primary)]" > {collapsed ? : } @@ -123,7 +126,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) { {error ?
{error}
: null} {report && collapsed ? ( -
+
{formatMoney(report.totalSavings)} savings @@ -146,7 +149,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) { ) : null}
) : report ? ( -
+
@@ -238,7 +241,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) {
) : ( -
PPP savings will appear here after calculation.
+
PPP savings will appear here after calculation.
)} );