Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(search): select a row when a command palette submenu opens (#11463)

pseudoyu2213e7369715
diff --git a/packages/views/search/search-command.test.tsx b/packages/views/search/search-command.test.tsx
index 672c4b2367..553dcf516c 100644
--- a/packages/views/search/search-command.test.tsx
+++ b/packages/views/search/search-command.test.tsx
@@ -1096,6 +1096,20 @@ describe("SearchCommand", () => {
expect(renderedValues().every((v) => v.startsWith("status:"))).toBe(true);
});
+ it("selects the first row of a submenu opened with an empty query, and the root's on the way back", async () => {
+ const user = userEvent.setup();
+ renderSearch();
+ await rowText("Change status...");
+ await user.keyboard("{Enter}");
+
+ expect(screen.getByRole("navigation", { name: "Current menu" })).toHaveTextContent("MUL-42Change status");
+ expect(selectedValue()).toBe(renderedValues()[0]);
+
+ await user.keyboard("{ArrowDown}{Backspace}");
+ expect(await screen.findByPlaceholderText(PLACEHOLDER)).toBeInTheDocument();
+ expect(selectedValue()).toBe(renderedValues()[0]);
+ });
+
it("ranks the issue's command first when its name is typed", async () => {
const user = userEvent.setup();
renderSearch();
diff --git a/packages/views/search/search-command.tsx b/packages/views/search/search-command.tsx
index 476a7cec83..d9da9e29ae 100644
--- a/packages/views/search/search-command.tsx
+++ b/packages/views/search/search-command.tsx
@@ -182,6 +182,9 @@ function PaletteFrame({
const current = stack[stack.length - 1] ?? null;
const inputValue = current ? pageQuery : rawQuery;
+ // The selected row's value. cmdk picks the first row only when it is empty.
+ const [selected, setSelected] = useState("");
+
const inputRef = useRef<HTMLInputElement>(null);
const listRef = useRef<HTMLDivElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
@@ -190,6 +193,8 @@ function PaletteFrame({
if (stack.length !== prevDepthRef.current) {
navDirectionRef.current = stack.length > prevDepthRef.current ? 1 : -1;
prevDepthRef.current = stack.length;
+ // It names a row of the page left behind. Cleared before the new rows mount.
+ setSelected("");
}
const navDirection = navDirectionRef.current;
const pageKey = current ? `${stack.length}:${current.page.type}` : "root";
@@ -279,6 +284,8 @@ function PaletteFrame({
data-mc="command-palette"
label={t(($) => $.title)}
shouldFilter={false}
+ value={selected}
+ onValueChange={setSelected}
onPointerDownCapture={recordIntent}
onClickCapture={recordIntent}
onKeyDownCapture={(e) => {