Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-07-04 - Accessible Accordion Toggles
**Learning:** When React conditional rendering toggles between summary and full views (e.g., `collapsed ? <Summary /> : <Full />`), 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.
11 changes: 7 additions & 4 deletions components/accounts/ppp-savings-panel.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -34,6 +34,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) {
const [error, setError] = useState<string | null>(null);
const [copied, setCopied] = useState(false);
const [collapsed, setCollapsed] = useState(false);
const contentId = useId();

const mailtoHref = useMemo(() => {
if (!report?.recipientEmail || !draft) {
Expand Down Expand Up @@ -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 ? <ChevronDown className="h-4 w-4" /> : <ChevronUp className="h-4 w-4" />}
Expand All @@ -123,7 +126,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) {
{error ? <div className="border-b border-[var(--border-subtle)] p-5 text-sm font-semibold text-[var(--accent-danger)]">{error}</div> : null}

{report && collapsed ? (
<div className="flex flex-wrap items-center justify-between gap-3 p-5 text-sm">
<div id={contentId} className="flex flex-wrap items-center justify-between gap-3 p-5 text-sm">
<div className="flex flex-wrap gap-4 text-[var(--text-secondary)]">
<span>
<strong className="text-[var(--text-primary)]">{formatMoney(report.totalSavings)}</strong> savings
Expand All @@ -146,7 +149,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) {
) : null}
</div>
) : report ? (
<div className="grid gap-0 xl:grid-cols-[0.75fr_1.25fr]">
<div id={contentId} className="grid gap-0 xl:grid-cols-[0.75fr_1.25fr]">
<div className="border-b border-[var(--border-subtle)] p-6 xl:border-b-0 xl:border-r">
<div className="grid gap-3 sm:grid-cols-3 xl:grid-cols-1">
<div className="rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-elevated)] p-4">
Expand Down Expand Up @@ -238,7 +241,7 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) {
</div>
</div>
) : (
<div className="p-6 text-sm text-[var(--text-secondary)]">PPP savings will appear here after calculation.</div>
<div id={contentId} className="p-6 text-sm text-[var(--text-secondary)]">PPP savings will appear here after calculation.</div>
)}
</section>
);
Expand Down
Loading