Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion apps/web/src/components/files/FileBrowserPanel.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { describe, expect, it, vi } from "vite-plus/test";
import { page, userEvent } from "vite-plus/test/browser";

import { COMPOSER_MENTION_DRAG_TYPE } from "~/components/chat/composerMentionDrag";
import { RightPanelSheet } from "~/components/RightPanelSheet";
import { dismissContextMenu } from "~/contextMenuFallback";
import { isMacPlatform } from "~/lib/utils";
import { render } from "../../../test/render";
import { act, render } from "../../../test/render";
import FileBrowserPanel from "./FileBrowserPanel";
import { dispatchPreviewAction } from "../preview/previewActionBus";
import { writeExpandedDirectories } from "./fileTreeExpansion";
Expand Down Expand Up @@ -297,6 +298,47 @@ describe("FileBrowserPanel", () => {
await expect.element(search).toHaveFocus();
});

it("Escape in the file search clears it without closing the panel sheet", async () => {
const onCloseSheet = vi.fn();
await using _screen = await render(
<RightPanelSheet animationDurationMs={0} open onClose={onCloseSheet}>
<FileBrowserPanel
environmentId={EnvironmentId.make("env-files")}
cwd="/repo"
projectName="repo"
selectedPath={null}
selectedPathRevealId={0}
onOpenFile={() => {}}
workspaceMutationId={null}
/>
</RightPanelSheet>,
);
const search = page.getByRole("searchbox", { name: "Search repo files" });
await userEvent.fill(search, "read");
for (const composition of [
{ key: "Escape", isComposing: true, keyCode: 27 },
{ key: "Escape", isComposing: false, keyCode: 229 },
]) {
// Safari ends the composition just before the Escape keydown.
await act(() => {
search.element().dispatchEvent(new CompositionEvent("compositionend", { bubbles: true }));
search
.element()
.dispatchEvent(new KeyboardEvent("keydown", { ...composition, bubbles: true }));
});
await expect.element(search).toHaveValue("read");
}
expect(search.element().getAttribute("type")).toBe("text");

await userEvent.keyboard("{Escape}");
await expect.element(search).toHaveValue("");
expect(onCloseSheet).not.toHaveBeenCalled();

(search.element() as HTMLElement).focus();
await userEvent.keyboard("{Escape}");
await vi.waitFor(() => expect(onCloseSheet).toHaveBeenCalledOnce());
});

it("keeps expanded folders when the panel remounts", async () => {
const panel = () => (
<FileBrowserPanel
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/components/files/FileBrowserPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ function FileSearchField({
const gt = useGT();
return (
<InputGroup variant="ghost" className="h-7 min-w-0 flex-1">
{/* Native search inputs clear on Escape even during IME composition. */}
<InputGroupInput
ref={ref}
type="search"
type="text"
role="searchbox"
name={props.name}
size="sm"
value={props.value}
Expand All @@ -116,7 +118,9 @@ function FileSearchField({
spellCheck={false}
onChange={(event) => props.onValueChange(event.target.value)}
onKeyDown={(event) => {
if (event.key !== "Escape") return;
if (event.key !== "Escape" || event.nativeEvent.isComposing || event.keyCode === 229)
return;
if (props.value) event.stopPropagation();
props.onClose();
event.currentTarget.blur();
}}
Expand Down
Loading