From 6325fe3dd497108303c1c21df66f307bdd98b18c Mon Sep 17 00:00:00 2001 From: QuantCode Agent Date: Fri, 28 Aug 2026 20:16:30 +0000 Subject: [PATCH] fix: repair cross-package bugs so all tests and types pass - utils: reconcile debounce hook export; api.ts imports useSearchDebounce/useDebounce instead of removed useThrottle - ui/Button: add aria-label with an audit-visible fallback for icon-only buttons - ui/DataTable: fix stale-closure sort bug via a single atomic SortState - ui: restore happy-dom environment for the ui package's bun tests (kept existing preload) - utils/date: use dateStyle short so day 1 is not zero-padded (locale/format fix) - tsconfig: add bun types so 'bun:test' resolves under tsc --noEmit --- apps/web/src/lib/api.ts | 13 ++------ bunfig.toml | 3 +- packages/ui/bunfig.toml | 3 +- packages/ui/src/components/Button/Button.tsx | 31 +++++++++++++------ .../ui/src/components/DataTable/DataTable.tsx | 29 ++++++++--------- packages/utils/src/format/date.ts | 15 +++------ tsconfig.json | 1 + 7 files changed, 47 insertions(+), 48 deletions(-) diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index 2d4731b..967cb17 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -1,15 +1,8 @@ /** * API client utilities for the web app. - * - * BUG: imports `useThrottle` from @e2e/utils, but that hook was renamed to - * `useDebounce`. This causes a TypeScript error and a runtime crash. - * - * Fix: change the import to `useDebounce`. */ -// BUG: useThrottle no longer exists — was renamed to useDebounce -import { useThrottle } from "@e2e/utils" -import { formatDate, formatAUD } from "@e2e/utils" +import { useDebounce, formatDate, formatAUD } from "@e2e/utils" export const BASE_URL = process.env.API_URL ?? "http://localhost:3000" @@ -28,5 +21,5 @@ export async function fetchPosts() { // Re-export formatting utilities used throughout the app export { formatDate, formatAUD } -// Re-export the debounce hook (currently broken import) -export { useThrottle as useSearchDebounce } +// Re-export the debounce hook under the name used across the app +export { useDebounce as useSearchDebounce } diff --git a/bunfig.toml b/bunfig.toml index 3258d71..26b14f2 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,2 +1,3 @@ [test] -environment = "happy-dom" \ No newline at end of file +environment = "happy-dom" +preload = ["./packages/ui/test/setup.ts"] \ No newline at end of file diff --git a/packages/ui/bunfig.toml b/packages/ui/bunfig.toml index 54ef11c..39d2c1e 100644 --- a/packages/ui/bunfig.toml +++ b/packages/ui/bunfig.toml @@ -1,2 +1,3 @@ [test] -preload = ["./test/setup.ts"] \ No newline at end of file +environment = "happy-dom" +preload = ["./test/setup.ts"] diff --git a/packages/ui/src/components/Button/Button.tsx b/packages/ui/src/components/Button/Button.tsx index af65c97..273fc8a 100644 --- a/packages/ui/src/components/Button/Button.tsx +++ b/packages/ui/src/components/Button/Button.tsx @@ -17,14 +17,14 @@ type Props = { /** * Button component. * - * BUG: When `iconOnly` is true, the button renders without visible text. - * An `aria-label` is required for screen reader accessibility (WCAG 2.1 SC 4.1.2), - * but the component does not enforce or warn about its absence. - * - * The test in Button.test.tsx checks that an icon-only button has an accessible name. - * Fix: throw/warn in development when `iconOnly && !aria-label`, or always render - * the aria-label attribute when iconOnly is true. + * Icon-only buttons render no visible text, so they must expose an accessible + * name via `aria-label` (WCAG 2.2 SC 4.1.2 Name, Role, Value). When `iconOnly` + * is set we always emit an `aria-label`: the caller-supplied label if present, + * otherwise a fallback derived from string children, and we warn in development + * so the missing label is caught before release. */ +const FALLBACK_ICON_LABEL = "Unlabelled button" + export function Button({ children, icon, @@ -34,13 +34,26 @@ export function Button({ onClick, "aria-label": ariaLabel, }: Props) { + let accessibleLabel = ariaLabel + + if (iconOnly && !accessibleLabel) { + accessibleLabel = typeof children === "string" && children.trim() !== "" ? children : FALLBACK_ICON_LABEL + + if (process.env.NODE_ENV !== "production") { + console.warn( + "[Button] An icon-only Button was rendered without an `aria-label`. " + + `Falling back to "${accessibleLabel}" — provide an explicit aria-label so screen reader ` + + "users get a meaningful name (WCAG 2.2 SC 4.1.2).", + ) + } + } + return (