Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe9d27fae5 |
No files matched your search
@@ -60,6 +60,7 @@
|
||||
"@vercel/config": "^0.3.0",
|
||||
"@vitejs/plugin-react": "^6.0.0",
|
||||
"babel-plugin-react-compiler": "1.0.0",
|
||||
"happy-dom": "^20.10.6",
|
||||
"msw": "2.12.11",
|
||||
"tailwindcss": "^4.0.0",
|
||||
"vite": "catalog:",
|
||||
|
||||
@@ -96,6 +96,7 @@ import {
|
||||
RECENT_THREAD_LIMIT,
|
||||
} from "./CommandPalette.logic";
|
||||
import { resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
|
||||
import { CommandPaletteDialogRoot } from "./CommandPaletteDialog";
|
||||
import { CommandPaletteResults } from "./CommandPaletteResults";
|
||||
import { AzureDevOpsIcon, BitbucketIcon, GitHubIcon, GitLabIcon } from "./Icons";
|
||||
import { ProjectFavicon } from "./ProjectFavicon";
|
||||
@@ -104,7 +105,6 @@ import { primaryServerKeybindingsAtom } from "../state/server";
|
||||
import { resolveShortcutCommand } from "../keybindings";
|
||||
import {
|
||||
Command,
|
||||
CommandDialog,
|
||||
CommandDialogPopup,
|
||||
CommandFooter,
|
||||
CommandInput,
|
||||
@@ -402,15 +402,15 @@ export function CommandPalette({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<OpenAddProjectCommandPaletteProvider openAddProject={openAddProject}>
|
||||
<ComposerHandleContext value={composerHandleRef}>
|
||||
<CommandDialog open={state.open} onOpenChange={setOpen}>
|
||||
{children}
|
||||
{children}
|
||||
<CommandPaletteDialogRoot open={state.open} onOpenChange={setOpen}>
|
||||
<CommandPaletteDialog
|
||||
open={state.open}
|
||||
openIntent={state.openIntent}
|
||||
setOpen={setOpen}
|
||||
clearOpenIntent={clearOpenIntent}
|
||||
/>
|
||||
</CommandDialog>
|
||||
</CommandPaletteDialogRoot>
|
||||
</ComposerHandleContext>
|
||||
</OpenAddProjectCommandPaletteProvider>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/** @vitest-environment happy-dom */
|
||||
|
||||
import { act, useState, type ReactNode } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
import { CommandPaletteDialogRoot, CommandPaletteDialogTrigger } from "./CommandPaletteDialog";
|
||||
import { CommandDialogPopup } from "./ui/command";
|
||||
|
||||
interface DialogStateOwnerProps {
|
||||
readonly children: ReactNode;
|
||||
}
|
||||
|
||||
function DialogStateOwner(props: DialogStateOwnerProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
{props.children}
|
||||
<CommandPaletteDialogRoot open={open} onOpenChange={setOpen}>
|
||||
{open ? (
|
||||
<CommandDialogPopup data-testid="command-palette-dialog">
|
||||
<button type="button">Dialog action</button>
|
||||
</CommandDialogPopup>
|
||||
) : null}
|
||||
</CommandPaletteDialogRoot>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function AppShell(props: { readonly onRender: () => void }) {
|
||||
props.onRender();
|
||||
|
||||
return (
|
||||
<CommandPaletteDialogTrigger
|
||||
render={<button type="button" data-testid="command-palette-trigger" />}
|
||||
>
|
||||
Search
|
||||
</CommandPaletteDialogTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
let root: Root | null = null;
|
||||
|
||||
afterEach(() => {
|
||||
if (root) {
|
||||
act(() => root?.unmount());
|
||||
root = null;
|
||||
}
|
||||
document.body.replaceChildren();
|
||||
});
|
||||
|
||||
describe("CommandPaletteDialog", () => {
|
||||
it("isolates dialog state while restoring focus to its detached trigger", async () => {
|
||||
const shellRender = vi.fn();
|
||||
const container = document.createElement("div");
|
||||
const previouslyFocusedInput = document.createElement("input");
|
||||
document.body.append(previouslyFocusedInput, container);
|
||||
root = createRoot(container);
|
||||
|
||||
await act(async () => {
|
||||
root?.render(
|
||||
<DialogStateOwner>
|
||||
<AppShell onRender={shellRender} />
|
||||
</DialogStateOwner>,
|
||||
);
|
||||
});
|
||||
|
||||
const trigger = document.querySelector<HTMLButtonElement>(
|
||||
'[data-testid="command-palette-trigger"]',
|
||||
);
|
||||
expect(trigger).not.toBeNull();
|
||||
previouslyFocusedInput.focus();
|
||||
|
||||
await act(async () => trigger?.click());
|
||||
|
||||
expect(document.querySelector('[data-testid="command-palette-dialog"]')).not.toBeNull();
|
||||
expect(shellRender).toHaveBeenCalledTimes(1);
|
||||
|
||||
await act(async () => {
|
||||
document.dispatchEvent(new KeyboardEvent("keydown", { bubbles: true, key: "Escape" }));
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(document.querySelector('[data-testid="command-palette-dialog"]')).toBeNull();
|
||||
expect(document.activeElement).toBe(trigger);
|
||||
});
|
||||
expect(shellRender).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { ComponentProps } from "react";
|
||||
|
||||
import { CommandCreateHandle, CommandDialog, CommandDialogTrigger } from "./ui/command";
|
||||
|
||||
const commandPaletteDialogHandle = CommandCreateHandle();
|
||||
|
||||
export function CommandPaletteDialogRoot(
|
||||
props: Omit<ComponentProps<typeof CommandDialog>, "handle">,
|
||||
) {
|
||||
return <CommandDialog handle={commandPaletteDialogHandle} {...props} />;
|
||||
}
|
||||
|
||||
export function CommandPaletteDialogTrigger(
|
||||
props: Omit<ComponentProps<typeof CommandDialogTrigger>, "handle">,
|
||||
) {
|
||||
return <CommandDialogTrigger handle={commandPaletteDialogHandle} {...props} />;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ import { sortThreads } from "../lib/threadSort";
|
||||
import { SidebarUpdatePill } from "./sidebar/SidebarUpdatePill";
|
||||
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
|
||||
import { useIsMobile } from "~/hooks/useMediaQuery";
|
||||
import { CommandDialogTrigger } from "./ui/command";
|
||||
import { CommandPaletteDialogTrigger } from "./CommandPaletteDialog";
|
||||
import { useSettings, useUpdateSettings } from "~/hooks/useSettings";
|
||||
import { primaryServerKeybindingsAtom } from "../state/server";
|
||||
import {
|
||||
@@ -2856,7 +2856,7 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(
|
||||
<SidebarGroup className="px-2 pt-2 pb-1">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<CommandDialogTrigger
|
||||
<CommandPaletteDialogTrigger
|
||||
render={
|
||||
<SidebarMenuButton
|
||||
size="sm"
|
||||
@@ -2872,7 +2872,7 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent(
|
||||
{commandPaletteShortcutLabel}
|
||||
</Kbd>
|
||||
) : null}
|
||||
</CommandDialogTrigger>
|
||||
</CommandPaletteDialogTrigger>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroup>
|
||||
|
||||
Generated
+321
-273
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user