A full-featured CRM built with React, shadcn/ui, and Supabase.
Address code review on the Base UI migration
erwanMarmelab1ee3e8d6d619
diff --git a/src/components/admin/select-input.tsx b/src/components/admin/select-input.tsxindex a786b3f0..ba166d93 100644--- a/src/components/admin/select-input.tsx+++ b/src/components/admin/select-input.tsx@@ -238,19 +238,11 @@ export const SelectInput = (props: SelectInputProps) => {}// Handle reset functionality- const handleReset = (e: React.MouseEvent<HTMLDivElement>) => {- e.stopPropagation();+ const handleReset = () => {field.onChange(emptyValue);};- // The clear button sits inside the trigger, and Base UI opens the select on- // mousedown. Since the popup is aligned over the trigger, the mouseup would land- // on the popup and no click would ever reach the button. Swallowing the mousedown- // keeps the select closed so the click below can run.- const handleResetMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {- e.preventDefault();- e.stopPropagation();- };+ const isClearable = !!field.value && field.value !== emptyValue;return (<>@@ -279,7 +271,10 @@ export const SelectInput = (props: SelectInputProps) => {onValueChange={handleChangeWithCreateSupport}><SelectTrigger- className={cn("w-full transition-all hover:bg-accent")}+ className={cn(+ "w-full transition-all hover:bg-accent",+ isClearable && "pr-11",+ )}disabled={field.disabled}aria-labelledby={labelId}>@@ -295,18 +290,6 @@ export const SelectInput = (props: SelectInputProps) => {return choice ? renderMenuItemOption(choice) : value;}}</SelectValue>-- {field.value && field.value !== emptyValue ? (- <div- role="button"- aria-label={translate("ra.action.clear_input_value")}- className="p-0 ml-auto pointer-events-auto hover:bg-transparent text-muted-foreground opacity-50 hover:opacity-100"- onClick={handleReset}- onMouseDown={handleResetMouseDown}- >- <X className="h-4 w-4" />- </div>- ) : null}</SelectTrigger><SelectContent>{finalChoices?.map((choice) => {@@ -330,6 +313,16 @@ export const SelectInput = (props: SelectInputProps) => {})}</SelectContent></Select>+ {isClearable ? (+ <button+ type="button"+ aria-label={translate("ra.action.clear_input_value")}+ className="absolute right-7 top-1/2 -translate-y-1/2 rounded-sm 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"+ onClick={handleReset}+ >+ <X className="h-4 w-4" />+ </button>+ ) : null}</div><InputHelperText helperText={helperText} /></FormField>diff --git a/src/components/atomic-crm/contacts/ContactEdit.test.tsx b/src/components/atomic-crm/contacts/ContactEdit.test.tsxindex 2dabfc23..b3096ea5 100644--- a/src/components/atomic-crm/contacts/ContactEdit.test.tsx+++ b/src/components/atomic-crm/contacts/ContactEdit.test.tsx@@ -146,7 +146,7 @@ describe("ContactEdit", () => {);});- it("keeps the select closed when pressing the clear button of the email type", async () => {+ it("clears the email type from the keyboard and with the mouse", async () => {// Arrange: the email type select holds "Work", so its clear button is shown.const screen = await render(<ContactEditWithEmailsAndPhones silent />);await expect@@ -157,17 +157,20 @@ describe("ContactEdit", () => {.first();await expect.element(clearButton).toBeInTheDocument();- // Act: Base UI opens a select on mousedown, not on click. A plain .click()- // is too fast to expose that, so press and let the popup have its frames.- clearButton- .element()- .dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));- await new Promise((resolve) =>- requestAnimationFrame(() => requestAnimationFrame(resolve)),- );-- // Assert: the popup must not have opened, otherwise it would cover the- // trigger and swallow the mouseup, leaving the value uncleared.+ // Assert: it is a real button, reachable with a keyboard. It used to be a+ // div[role=button] nested inside the trigger, which no Tab could reach.+ const element = clearButton.element() as HTMLElement;+ expect(element.tagName).toBe("BUTTON");+ element.focus();+ expect(document.activeElement).toBe(element);++ // Act & assert: pressing it clears the value, so the button goes away with+ // it. While it sat inside the trigger, Base UI opened the select on the+ // mousedown and the popup swallowed the rest of the gesture instead.+ await clearButton.click();+ // assert on the element, not the locator: the phone row has a clear button+ // of its own, which the locator would resolve to once this one is gone.+ await expect.poll(() => element.isConnected).toBe(false);expect(document.querySelector('[data-slot="select-content"]')).toBeNull();});});diff --git a/src/components/atomic-crm/settings/SettingsPageMobile.tsx b/src/components/atomic-crm/settings/SettingsPageMobile.tsxindex bb641c45..c8157912 100644--- a/src/components/atomic-crm/settings/SettingsPageMobile.tsx+++ b/src/components/atomic-crm/settings/SettingsPageMobile.tsx@@ -504,6 +504,7 @@ const ThemeRow = () => {}size="lg"variant="outline"+ spacing={0}className="w-full"><ToggleGroupItemdiff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsxindex 83d70e73..38c6e9ce 100644--- a/src/components/ui/command.tsx+++ b/src/components/ui/command.tsx@@ -12,7 +12,7 @@ import {DialogTitle,} from "@/components/ui/dialog"import { InputGroup, InputGroupAddon } from "@/components/ui/input-group"-import { CheckIcon, SearchIcon } from "lucide-react"+import { SearchIcon } from "lucide-react"function Command({className,@@ -159,7 +159,6 @@ function CommandItem({{...props}>{children}- <CheckIcon className="ml-auto opacity-0 group-has-data-[slot=command-shortcut]/command-item:hidden group-data-[checked=true]/command-item:opacity-100" /></CommandPrimitive.Item>)}diff --git a/src/components/ui/sidebar.tsx b/src/components/ui/sidebar.tsxindex 6f64cee1..12060323 100644--- a/src/components/ui/sidebar.tsx+++ b/src/components/ui/sidebar.tsx@@ -21,6 +21,7 @@ import { Skeleton } from "@/components/ui/skeleton"import {Tooltip,TooltipContent,+ TooltipProvider,TooltipTrigger,} from "@/components/ui/tooltip"import { PanelLeftIcon } from "lucide-react"@@ -128,23 +129,25 @@ function SidebarProvider({return (<SidebarContext.Provider value={contextValue}>- <div- data-slot="sidebar-wrapper"- style={- {- "--sidebar-width": SIDEBAR_WIDTH,- "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,- ...style,- } as React.CSSProperties- }- className={cn(- "group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",- className- )}- {...props}- >- {children}- </div>+ <TooltipProvider delay={0}>+ <div+ data-slot="sidebar-wrapper"+ style={+ {+ "--sidebar-width": SIDEBAR_WIDTH,+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,+ ...style,+ } as React.CSSProperties+ }+ className={cn(+ "group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",+ className+ )}+ {...props}+ >+ {children}+ </div>+ </TooltipProvider></SidebarContext.Provider>)}diff --git a/vitest.config.ts b/vitest.config.tsindex bbcdae59..d8b7c91f 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -31,6 +31,13 @@ export default defineConfig({name: "app",globals: true,setupFiles: ["./src/index.css"],+ // These are browser integration tests: a click can run a mutation, close a+ // sheet and wait for a toast. The 1s default budget of expect.poll (and of+ // expect.element, which is built on it) holds on an idle machine but not on+ // a loaded runner, where the same assertion was measured at 3.3s. This only+ // raises the ceiling before giving up, so a genuinely broken assertion still+ // fails, just later.+ expect: { poll: { timeout: 5000 } },browser: {headless: true,provider: playwright(),