Skip to content

refactor(frontend): migrate AddProjectDialog to Radix Dialog - #813

Merged
backnotprop merged 2 commits into
feat/single-server-runtimefrom
refactor/add-project-dialog-radix
May 28, 2026
Merged

backnotprop merged 2 commits into
feat/single-server-runtimefrom
refactor/add-project-dialog-radix

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

What changed

Migrates AddProjectDialog (apps/frontend/src/components/landing/AddProjectDialog.tsx) from a hand-rolled modal to the app's existing shadcn-style Radix Dialog wrapper (components/ui/dialog.tsx), the same one AppSettingsDialog uses. This gains proper focus-trapping, scroll-lock, Escape handling, and consistent fade/zoom motion — and eliminates the second modal implementation in the app.

The directory-listing/typeahead logic, daemonApiClient.listDirectories calls, Recent/Directories rendering, and the component's props are unchanged. This is purely a presentational/behavioral swap of the modal shell.

Removed (now provided by Radix)

  • fixed inset-0 z-50 … backdrop-blur overlay + nested panel wrappers → DialogOverlay (inside DialogContent)
  • Manual backdrop-click-to-close → Radix onPointerDownOutside
  • Manual Escape branch in handleKeyDown → Radix onEscapeKeyDown (no double-fire; the input's keydown no longer touches Escape)
  • if (!open) return null → <Dialog open={open}> controls mounting
  • requestAnimationFrame(() => inputRef.current?.focus()) → onOpenAutoFocus

Preserved command-palette behavior

  1. Top-anchored max-w-lg layout. Overridden via className="top-[15vh] max-w-lg translate-y-0 max-h-none" on DialogContent. (See cn() finding below.)
  2. Search-input autofocus. onOpenAutoFocus={(e) => { e.preventDefault(); inputRef.current?.focus(); }}.
  3. Keyboard nav coexistence. Arrow/Tab/Enter list navigation in the input's onKeyDown is unchanged. Escape is now owned by Radix.
  4. Footer hint bar + Recent/Directories list render unchanged.

a11y / polish

  • Kept the custom inline X in the search row and passed hideClose to suppress the built-in one — exactly one close button. Added focus:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 to it so its focus state matches the built-in close button.
  • Added an sr-only DialogTitle ("Add a project") — Radix requires a title for screen readers (mirrors AppSettingsDialog).

cn() tailwind-merge finding

cn() DOES use tailwind-merge (apps/frontend/src/lib/utils.ts → twMerge(clsx(inputs))). So the className overrides on DialogContent cleanly replace the base classes rather than appending alongside conflicting ones:

  • base top-[50%] → top-[15vh]
  • base translate-y-[-50%] → translate-y-0
  • base max-w-4xl → max-w-lg
  • base max-h-[min(640px,85vh)] → max-h-none (restores the original panel's no-max-height; the inner list keeps its own max-h-72 scroll cap)
  • base left-[50%] translate-x-[-50%] retained → horizontal centering preserved

No explicit inner-wrapper workaround was needed.

Call site

apps/frontend/src/app/Layout.tsx:85 (<AddProjectDialog open={addProjectOpen} onOpenChange={setAddProjectOpen} />) is unchanged — props map 1:1 onto <Dialog open onOpenChange>. Typecheck confirms.

Verification

  • bun run typecheck (apps/frontend): no errors in AddProjectDialog.tsx. The only error reported (vitest.browser.config.ts — missing @vitest/browser-playwright) is pre-existing (reproduces with this change stashed) and unrelated.
  • bun run build (apps/frontend): Vite build + single-file build verification pass.
  • Root bun test: 1329 pass, 0 fail (after the standard vendor.sh step).
  • oxlint / oxfmt --check on the modified file: clean.

Visual/interaction confirmation is deferred to human PR review. There is no React Testing Library or browser automation in this environment, so the four preserved behaviors (top-anchored positioning, search autofocus, keyboard nav, single close button) were reasoned through in adversarial self-review and code-review but not clicked through live. I did not verify it visually.

Swap the hand-rolled modal shell (fixed inset-0 overlay, manual backdrop
click, manual Escape, if (!open) return null) for the existing shadcn-style
Radix Dialog wrapper (components/ui/dialog.tsx), gaining focus-trapping,
scroll-lock, and consistent fade/zoom motion shared with AppSettingsDialog.

Preserved command-palette behavior:
- Top-anchored max-w-lg layout via className overrides on DialogContent
  (top-[15vh] translate-y-0 max-w-lg max-h-none). cn() uses tailwind-merge,
  so these override the centered/max-w-4xl base classes cleanly.
- Search-input autofocus via onOpenAutoFocus (preventDefault + focus input)
  instead of requestAnimationFrame.
- Arrow/Tab/Enter list navigation in the input's onKeyDown is unchanged;
  Escape is now owned by Radix (manual branch removed, no double-fire).
- Custom inline X kept with hideClose (single close button); added a
  focus-visible ring to match the built-in close button's a11y.
- Added sr-only DialogTitle for screen-reader compliance.

Directory-listing/typeahead logic, daemonApiClient calls, Recent/Directories
rendering, and props are unchanged. Call site (Layout.tsx) needs no change.
…Description

- max-h-none did not override the base max-h-[min(640px,85vh)] (tailwind-merge
  doesn't dedupe none vs arbitrary); inner list max-h-72 already governs height.
- Add sr-only DialogDescription to satisfy Radix a11y and silence the dev warning.
backnotprop added a commit that referenced this pull request May 28, 2026
@backnotprop
backnotprop merged commit e5394a8 into feat/single-server-runtime May 28, 2026
@backnotprop
backnotprop deleted the refactor/add-project-dialog-radix branch May 29, 2026 01:57
backnotprop added a commit that referenced this pull request May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant