Skip to content

Commit b40e2cd

Browse files
authored
Fix keyboard shortcut help layout (#509)
1 parent 19cc6ee commit b40e2cd

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { renderToStaticMarkup } from "react-dom/server";
2+
import { describe, expect, test, vi } from "vite-plus/test";
3+
import type { HotkeyAction } from "../../hooks/useHotKey";
4+
import { HotkeyList } from "./HotkeyList";
5+
6+
vi.mock("./Hotkey", () => ({
7+
Hotkey: ({ action }: { action: HotkeyAction }) =>
8+
action === "sidebar.selected.move" ? null : <span>{action}</span>,
9+
}));
10+
11+
vi.mock("./HotkeyLabel", () => ({
12+
HotkeyLabel: ({ action }: { action: HotkeyAction }) => <span>{action}</span>,
13+
}));
14+
15+
describe("HotkeyList", () => {
16+
test("keeps a grid cell for actions without a shortcut", () => {
17+
const markup = renderToStaticMarkup(
18+
<HotkeyList hotkeys={["sidebar.selected.move", "request.send"]} />,
19+
);
20+
21+
expect(markup).toContain(
22+
'<span>sidebar.selected.move</span><div class="ml-4"></div><span>request.send</span>',
23+
);
24+
});
25+
});

apps/yaak-client/components/core/HotkeyList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export const HotkeyList = ({ hotkeys, bottomSlot, className }: Props) => {
1818
{hotkeys.map((hotkey) => (
1919
<Fragment key={hotkey}>
2020
<HotkeyLabel className="truncate" action={hotkey} />
21-
<Hotkey className="ml-4" action={hotkey} />
21+
{/* Keep this grid cell when Hotkey renders nothing so later rows stay aligned. */}
22+
<div className="ml-4">
23+
<Hotkey action={hotkey} />
24+
</div>
2225
</Fragment>
2326
))}
2427
{bottomSlot}

0 commit comments

Comments
 (0)