A full-featured CRM built with React, shadcn/ui, and Supabase.
Fix a11y and positioning regressions from the Base UI migration
erwanMarmelabaa735311df96
diff --git a/e2e/onboarding.spec.ts b/e2e/onboarding.spec.tsindex c870ad4a..416e28b2 100644--- a/e2e/onboarding.spec.ts+++ b/e2e/onboarding.spec.ts@@ -73,7 +73,9 @@ test("user onboarding", async ({ page, isMobile, menu, dismissToast }) => {await expect(page.getByText("2/3 done")).toBeVisible();- await page.getByRole("button", { name: "Add note" }).click();+ await page+ .getByRole(isMobile ? "button" : "link", { name: "Add note" })+ .click();await page.waitForLoadState("networkidle");diff --git a/src/components/admin/autocomplete-input.tsx b/src/components/admin/autocomplete-input.tsxindex 3be80a31..e0ccf1ae 100644--- a/src/components/admin/autocomplete-input.tsx+++ b/src/components/admin/autocomplete-input.tsx@@ -225,11 +225,13 @@ export const AutocompleteInput = (/></FormLabel>)}- <FormControl>- <Popover open={open} onOpenChange={handleOpenChange} modal={modal}>- <div className="relative">- <PopoverTrigger- render={+ <Popover open={open} onOpenChange={handleOpenChange} modal={modal}>+ <div className="relative">+ <PopoverTrigger+ render={+ // FormControl goes on the button: the Popover root renders no+ // element, so the id and aria-invalid it injects would be lost+ <FormControl><Buttonvariant="outline"role="combobox"@@ -240,96 +242,98 @@ export const AutocompleteInput = ("w-full justify-between h-auto py-1.75 font-normal",isClearable && "pr-9",)}- />- }+ >+ <div className="min-w-0 flex flex-1 items-center gap-2 overflow-hidden text-left">+ {selectedChoice ? (+ getInputText(selectedChoice)+ ) : (+ <span className="text-muted-foreground">+ {placeholder}+ </span>+ )}+ </div>+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />+ </Button>+ </FormControl>+ }+ />+ {isClearable && (+ <button+ type="button"+ aria-label={translate("ra.action.clear_input_value")}+ className="absolute right-8 top-1/2 -translate-y-1/2 text-muted-foreground opacity-50 hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 rounded-sm"+ onClick={handleReset}>- <div className="min-w-0 flex flex-1 items-center gap-2 overflow-hidden text-left">- {selectedChoice ? (- getInputText(selectedChoice)- ) : (- <span className="text-muted-foreground">{placeholder}</span>- )}- </div>- <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />- </PopoverTrigger>- {isClearable && (- <button- type="button"- aria-label={translate("ra.action.clear_input_value")}- className="absolute right-8 top-1/2 -translate-y-1/2 text-muted-foreground opacity-50 hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 rounded-sm"- onClick={handleReset}- >- <X className="h-4 w-4" />- </button>- )}- </div>- <PopoverContent className="w-full max-w-(--anchor-width) p-0">- {/* We handle the filtering ourselves */}- <Command shouldFilter={!isFromReference}>- <CommandInput- placeholder="Search..."- value={filterValue}- onValueChange={(filter) => {- setFilterValue(filter);- requestAnimationFrame(() => {- listRef.current?.scrollTo(0, 0);- });- // We don't want the ChoicesContext to filter the choices if the input- // is not from a reference as it would also filter out the selected values- if (isFromReference) {- setFilters(filterToQuery(filter));- }- }}- />- <CommandList ref={listRef}>- <CommandEmpty>No matching item found.</CommandEmpty>- <CommandGroup>- {finalChoices.map((choice) => {- const isCreateItem =- !!createItem && choice?.id === createItem.id;- const disabled = getOptionDisabled(choice);+ <X className="h-4 w-4" />+ </button>+ )}+ </div>+ <PopoverContent className="w-full max-w-(--anchor-width) p-0">+ {/* We handle the filtering ourselves */}+ <Command shouldFilter={!isFromReference}>+ <CommandInput+ placeholder="Search..."+ value={filterValue}+ onValueChange={(filter) => {+ setFilterValue(filter);+ requestAnimationFrame(() => {+ listRef.current?.scrollTo(0, 0);+ });+ // We don't want the ChoicesContext to filter the choices if the input+ // is not from a reference as it would also filter out the selected values+ if (isFromReference) {+ setFilters(filterToQuery(filter));+ }+ }}+ />+ <CommandList ref={listRef}>+ <CommandEmpty>No matching item found.</CommandEmpty>+ <CommandGroup>+ {finalChoices.map((choice) => {+ const isCreateItem =+ !!createItem && choice?.id === createItem.id;+ const disabled = getOptionDisabled(choice);- const choiceText = getChoiceText(- isCreateItem ? createItem : choice,- );+ const choiceText = getChoiceText(+ isCreateItem ? createItem : choice,+ );- return (- <CommandItem- key={getChoiceValue(choice)}- keywords={- isCreateItem || React.isValidElement(choiceText)- ? undefined- : [choiceText]- }- value={- isCreateItem- ? // if it's the create option, include the filter value so it is shown in the command input- // characters before and after the filter value are required- // to show the option when the filter value starts or ends with a space- `?${filterValue}?`- : getChoiceValue(choice)- }- onSelect={() => handleChangeWithCreateSupport(choice)}- disabled={disabled}- >- <Check- className={cn(- "mr-2 h-4 w-4",- field.value === getChoiceValue(choice)- ? "opacity-100"- : "opacity-0",- )}- />- {choiceText}- </CommandItem>- );- })}- </CommandGroup>- </CommandList>- </Command>- </PopoverContent>- </Popover>- </FormControl>+ return (+ <CommandItem+ key={getChoiceValue(choice)}+ keywords={+ isCreateItem || React.isValidElement(choiceText)+ ? undefined+ : [choiceText]+ }+ value={+ isCreateItem+ ? // if it's the create option, include the filter value so it is shown in the command input+ // characters before and after the filter value are required+ // to show the option when the filter value starts or ends with a space+ `?${filterValue}?`+ : getChoiceValue(choice)+ }+ onSelect={() => handleChangeWithCreateSupport(choice)}+ disabled={disabled}+ >+ <Check+ className={cn(+ "mr-2 h-4 w-4",+ field.value === getChoiceValue(choice)+ ? "opacity-100"+ : "opacity-0",+ )}+ />+ {choiceText}+ </CommandItem>+ );+ })}+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover><InputHelperText helperText={props.helperText} /><FormError /></FormField>diff --git a/src/components/admin/list-pagination.tsx b/src/components/admin/list-pagination.tsxindex cbf90f79..178c0cc1 100644--- a/src/components/admin/list-pagination.tsx+++ b/src/components/admin/list-pagination.tsx@@ -123,7 +123,7 @@ export const ListPagination = ({<SelectTrigger className="h-8 w-fit"><SelectValue placeholder={perPage} /></SelectTrigger>- <SelectContent side="top">+ <SelectContent side="top" alignItemWithTrigger={false}>{rowsPerPageOptions.map((pageSize) => (<SelectItem key={pageSize} value={`${pageSize}`}>{pageSize}diff --git a/src/components/admin/select-input.tsx b/src/components/admin/select-input.tsxindex c1c1cecb..9a9dca5e 100644--- a/src/components/admin/select-input.tsx+++ b/src/components/admin/select-input.tsx@@ -183,7 +183,7 @@ export const SelectInput = (props: SelectInputProps) => {} else {// Find the choice by value and pass it to field.onChangeconst choice = allChoices?.find(- (choice) => getChoiceValue(choice) === value,+ (choice) => String(getChoiceValue(choice)) === value,);field.onChange(choice ? getChoiceValue(choice) : value);}@@ -264,9 +264,6 @@ export const SelectInput = (props: SelectInputProps) => {)}<div className="relative"><Select- // Re-mounting the select when the controlled value changes avoids a stale- // internal state edge case where onValueChange can briefly receive "".- key={`select:${field.value?.toString() ?? emptyValue}`}value={field.value?.toString() || emptyValue}onValueChange={handleChangeWithCreateSupport}>diff --git a/src/components/atomic-crm/companies/AutocompleteCompanyInput.test.tsx b/src/components/atomic-crm/companies/AutocompleteCompanyInput.test.tsxnew file mode 100644index 00000000..cce8bc43--- /dev/null+++ b/src/components/atomic-crm/companies/AutocompleteCompanyInput.test.tsx@@ -0,0 +1,42 @@+import { Form } from "ra-core";+import { describe, expect, it } from "vitest";+import { render } from "vitest-browser-react";++import { ReferenceInput } from "@/components/admin/reference-input";+import { buildCompany, StoryWrapper } from "@/test/StoryWrapper";++import { AutocompleteCompanyInput } from "./AutocompleteCompanyInput";++describe("AutocompleteCompanyInput", () => {+ it("keeps the current company when creating a new one fails", async () => {+ // Arrange: a record already linked to Acme, and a create that rejects.+ const screen = await render(+ <StoryWrapper+ data={{ companies: [buildCompany({ id: 1, name: "Acme" })] }}+ dataProvider={{+ create: () => Promise.reject(new Error("Network error")),+ }}+ >+ <Form record={{ company_id: 1 }}>+ <ReferenceInput source="company_id" reference="companies">+ <AutocompleteCompanyInput label="Company" />+ </ReferenceInput>+ </Form>+ </StoryWrapper>,+ );+ const combobox = screen.getByRole("combobox", { name: "Company" });+ await expect.element(combobox).toHaveTextContent("Acme");++ // Act+ await combobox.click();+ await screen.getByPlaceholder("Search...").fill("Foo");+ await screen.getByRole("option", { name: "Create Foo" }).click();++ // Assert: the error is reported and the create sentinel was not stored+ // in place of the selected company.+ await expect+ .element(screen.getByText("An error occurred while creating the company"))+ .toBeVisible();+ await expect.element(combobox).toHaveTextContent("Acme");+ });+});diff --git a/src/components/atomic-crm/dashboard/DashboardStepper.test.tsx b/src/components/atomic-crm/dashboard/DashboardStepper.test.tsxindex 6aec2347..bc8a5911 100644--- a/src/components/atomic-crm/dashboard/DashboardStepper.test.tsx+++ b/src/components/atomic-crm/dashboard/DashboardStepper.test.tsx@@ -35,15 +35,14 @@ describe("DashboardStepper", () => {.toHaveAttribute("href", "/contacts/create");});- it("shows the add note button as disabled while no contact exists", async () => {+ it("shows the add note link as disabled while no contact exists", async () => {// Arrange: at step 1 the stepper disables "Add note".const screen = await render(<FirstStep />);- const addNote = screen.getByRole("button", { name: "Add note" });+ const addNote = screen.getByRole("link", { name: "Add note" });await expect.element(addNote).toBeVisible();- // Assert: it is announced as disabled, and it also LOOKS disabled. Base UI- // renders it as a link, on which the native :disabled pseudo-class never- // matches, so styling it relies on the data-disabled attribute instead.+ // Assert: it is announced as disabled, and it also LOOKS disabled. A link+ // has no native disabled state, so both are set by hand.await expect.element(addNote).toHaveAttribute("aria-disabled", "true");const style = getComputedStyle(addNote.element());expect(style.pointerEvents).toBe("none");diff --git a/src/components/atomic-crm/dashboard/DashboardStepper.tsx b/src/components/atomic-crm/dashboard/DashboardStepper.tsxindex 1267e8e0..51f6af74 100644--- a/src/components/atomic-crm/dashboard/DashboardStepper.tsx+++ b/src/components/atomic-crm/dashboard/DashboardStepper.tsx@@ -8,6 +8,7 @@ import { useState } from "react";import { Link } from "react-router";import { useIsMobile } from "@/hooks/use-mobile";+import { cn } from "@/lib/utils";import { ContactCreateSheet } from "../contacts/ContactCreateSheet";import { DataImportButton } from "../dataImport/DataImportButton";import useAppBarHeight from "../misc/useAppBarHeight";@@ -138,24 +139,25 @@ export const DashboardStepper = ({})}</Button>) : (- <Button- disabled={step < 2}- className="w-fit"- render={- <Link- to={createPath({- resource: "contacts",- type: "show",- id: contactId,- })}- />- }- nativeButton={false}+ <Link+ to={createPath({+ resource: "contacts",+ type: "show",+ id: contactId,+ })}+ aria-disabled={step < 2 || undefined}+ tabIndex={step < 2 ? -1 : undefined}+ className={buttonVariants({+ className: cn(+ "w-fit",+ step < 2 && "pointer-events-none opacity-50",+ ),+ })}>{translate("resources.notes.action.add", {_: "Add note",})}- </Button>+ </Link>)}</div></div>diff --git a/src/components/ui/separator.tsx b/src/components/ui/separator.tsxindex 692f8a9b..5a5000fd 100644--- a/src/components/ui/separator.tsx+++ b/src/components/ui/separator.tsx@@ -6,12 +6,15 @@ import { cn } from "@/lib/utils"function Separator({className,orientation = "horizontal",+ decorative = true,...props-}: SeparatorPrimitive.Props) {+}: SeparatorPrimitive.Props & { decorative?: boolean }) {return (<SeparatorPrimitivedata-slot="separator"orientation={orientation}+ // A purely visual divider stays out of the accessibility tree, as Radix did+ {...(decorative && { role: "none", "aria-orientation": undefined })}className={cn("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",classNamediff --git a/src/components/ui/tooltip.test.tsx b/src/components/ui/tooltip.test.tsxindex c7df072e..cbc5f37c 100644--- a/src/components/ui/tooltip.test.tsx+++ b/src/components/ui/tooltip.test.tsx@@ -1,3 +1,4 @@+import { afterEach, vi } from "vitest"import { render } from "vitest-browser-react"import {@@ -6,7 +7,16 @@ import {TooltipTrigger,} from "@/components/ui/tooltip"+afterEach(() => {+ vi.useRealTimers()+})+it("opens without waiting when no provider wraps it", async () => {+ // Base UI falls back to a 600ms open delay when nothing provides one, and that+ // delay runs on setTimeout. With setTimeout frozen, only an instant open can+ // show the tooltip, whatever the runner load (expect.element polls on real timers).+ vi.useFakeTimers({ toFake: ["setTimeout"] })+const screen = await render(<Tooltip><TooltipTrigger render={<button type="button" />}>@@ -18,9 +28,5 @@ it("opens without waiting when no provider wraps it", async () => {await screen.getByRole("button", { name: "Hover me" }).hover()- // Base UI falls back to a 600ms open delay when nothing provides one, so this- // budget is what tells an instant tooltip from the default.- await expect- .element(screen.getByText("Helpful"), { timeout: 400 })- .toBeVisible()+ await expect.element(screen.getByText("Helpful")).toBeVisible()})