Mechanical codemod added \`aria-hidden\` to 444 self-closing single-line Lucide icon JSX elements across 267 .tsx files in: - shared/, layout/, dashboard/ - admin/ (all sections) - clients/, berths/, yachts/, companies/, interests/, documents/ - reminders/, reservations/, residential/, expenses/, email/ The regex targeted only the safe pattern \`<IconName className="..." />\` (no other props, self-closing, capitalized component name). Every match inspected is a decorative companion to visible text or sits inside a button whose accessible name comes from \`aria-label\` / sr-only text — the icon itself should not be announced. Screen readers no longer double-read the icon + the adjacent label text (e.g. "Pencil Pencil Edit" → just "Edit"). The existing @axe-core/playwright smoke test (\`20-accessibility.spec.ts\`) continues to pass. Test suite stays at 1315/1315 vitest. typescript clean. Closes task #69 (aria-hidden sweep) from the AUDIT-2026-05-12 follow-ups backlog. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
136 lines
4.3 KiB
TypeScript
136 lines
4.3 KiB
TypeScript
'use client';
|
|
|
|
import { useMemo, useState } from 'react';
|
|
import { Check, ChevronsUpDown } from 'lucide-react';
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
} from '@/components/ui/command';
|
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
|
import { cn } from '@/lib/utils';
|
|
import { subdivisionsForCountry } from '@/lib/i18n/subdivisions';
|
|
import type { CountryCode } from '@/lib/i18n/countries';
|
|
|
|
interface SubdivisionComboboxProps {
|
|
value: string | null | undefined;
|
|
onChange: (code: string | null) => void;
|
|
/**
|
|
* Country whose subdivisions populate the dropdown. When the country
|
|
* has no recognized subdivisions, the trigger renders disabled with
|
|
* an empty-state hint so the form still lays out.
|
|
*/
|
|
country: CountryCode | null | undefined;
|
|
placeholder?: string;
|
|
disabled?: boolean;
|
|
className?: string;
|
|
clearable?: boolean;
|
|
id?: string;
|
|
'data-testid'?: string;
|
|
/** Open the dropdown on first render. Used by inline-edit wrappers. */
|
|
defaultOpen?: boolean;
|
|
/** Notified whenever the dropdown opens/closes. Inline-edit wrappers use
|
|
* this to auto-exit edit mode when the user dismisses without picking. */
|
|
onOpenChange?: (open: boolean) => void;
|
|
}
|
|
|
|
export function SubdivisionCombobox({
|
|
value,
|
|
onChange,
|
|
country,
|
|
placeholder = 'Select region…',
|
|
disabled,
|
|
className,
|
|
clearable = true,
|
|
id,
|
|
'data-testid': testId,
|
|
defaultOpen = false,
|
|
onOpenChange,
|
|
}: SubdivisionComboboxProps) {
|
|
const [open, setOpen] = useState(defaultOpen);
|
|
const handleOpenChange = (next: boolean) => {
|
|
setOpen(next);
|
|
onOpenChange?.(next);
|
|
};
|
|
|
|
const options = useMemo(() => {
|
|
if (!country) return [];
|
|
return subdivisionsForCountry(country);
|
|
}, [country]);
|
|
|
|
const selected = value ? options.find((o) => o.code === value) : undefined;
|
|
const noCountry = !country;
|
|
const noSubdivisions = !noCountry && options.length === 0;
|
|
const isDisabled = disabled || noCountry || noSubdivisions;
|
|
|
|
let triggerLabel: string;
|
|
if (selected) triggerLabel = selected.name;
|
|
else if (noCountry) triggerLabel = 'Pick a country first';
|
|
else if (noSubdivisions) triggerLabel = 'No regions available';
|
|
else triggerLabel = placeholder;
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={handleOpenChange} modal>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
id={id}
|
|
variant="outline"
|
|
role="combobox"
|
|
aria-expanded={open}
|
|
disabled={isDisabled}
|
|
className={cn('w-full justify-between', !selected && 'text-muted-foreground', className)}
|
|
data-testid={testId}
|
|
>
|
|
<span className="truncate text-sm">{triggerLabel}</span>
|
|
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" aria-hidden />
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-[320px] p-0" align="start">
|
|
<Command>
|
|
<CommandInput placeholder={`Search ${country ?? 'regions'}…`} />
|
|
<CommandList>
|
|
<CommandEmpty>No region found.</CommandEmpty>
|
|
{clearable && value ? (
|
|
<CommandGroup>
|
|
<CommandItem
|
|
value="__clear__"
|
|
onSelect={() => {
|
|
onChange(null);
|
|
setOpen(false);
|
|
}}
|
|
className="text-muted-foreground"
|
|
>
|
|
Clear selection
|
|
</CommandItem>
|
|
</CommandGroup>
|
|
) : null}
|
|
<CommandGroup>
|
|
{options.map((opt) => (
|
|
<CommandItem
|
|
key={opt.code}
|
|
value={`${opt.name} ${opt.code}`}
|
|
onSelect={() => {
|
|
onChange(opt.code);
|
|
setOpen(false);
|
|
}}
|
|
>
|
|
<Check
|
|
className={cn('mr-2 h-4 w-4', value === opt.code ? 'opacity-100' : 'opacity-0')}
|
|
/>
|
|
<span className="flex-1 truncate text-sm">{opt.name}</span>
|
|
<span className="text-xs text-muted-foreground">{opt.code}</span>
|
|
</CommandItem>
|
|
))}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
);
|
|
}
|