Skip to content

Commit 745fd6b

Browse files
authored
[KeyComboTag] Fix arrow key icon rendering (#7493)
1 parent c7e62c1 commit 745fd6b

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

packages/core/src/components/hotkeys/keyComboTag.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ const KEY_ICONS: Record<string, { icon: React.JSX.Element; iconTitle: string; is
5151

5252
/** Reverse table of some CONFIG_ALIASES fields, for display by KeyComboTag */
5353
export const DISPLAY_ALIASES: Record<string, string> = {
54-
ArrowDown: "down",
55-
ArrowLeft: "left",
56-
ArrowRight: "right",
57-
ArrowUp: "up",
54+
arrowdown: "down",
55+
arrowleft: "left",
56+
arrowright: "right",
57+
arrowup: "up",
5858
};
5959

6060
export interface KeyComboTagProps extends Props {
@@ -93,7 +93,7 @@ export class KeyComboTagInternal extends AbstractPureComponent<KeyComboTagIntern
9393
}
9494

9595
private renderKey = (key: string, index: number) => {
96-
const keyString = DISPLAY_ALIASES[key] ?? key;
96+
const keyString = DISPLAY_ALIASES[key.toLowerCase()] ?? key;
9797
const icon = this.getKeyIcon(key);
9898
const reactKey = `key-${index}`;
9999
return (
@@ -114,7 +114,7 @@ export class KeyComboTagInternal extends AbstractPureComponent<KeyComboTagIntern
114114

115115
private getKeyIcon(key: string) {
116116
const { platformOverride } = this.props;
117-
const icon = KEY_ICONS[key];
117+
const icon = KEY_ICONS[key.toLowerCase()];
118118
if (icon?.isMacOnly && !isMac(platformOverride)) {
119119
return undefined;
120120
}

packages/core/test/hotkeys/keyComboTagTests.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,32 @@ import { KeyComboTagInternal } from "../../src/components/hotkeys/keyComboTag";
2222

2323
describe("KeyCombo", () => {
2424
it("renders key combo", () => {
25-
render(<KeyComboTagInternal combo="cmd+C" platformOverride="Mac" />);
26-
expect(screen.getByText("C")).not.to.be.undefined;
25+
const { container } = render(<KeyComboTagInternal combo="cmd+C" platformOverride="Mac" />);
26+
const icon = container.querySelector('[data-icon="key-command"]');
27+
28+
expect(icon).to.exist;
29+
expect(screen.getByText("cmd")).to.exist;
30+
expect(screen.getByText("C")).to.exist;
2731
});
2832

2933
it("should render minimal key combos on Mac using icons", () => {
3034
render(<KeyComboTagInternal combo="mod+C" minimal={true} platformOverride="Mac" />);
31-
expect(() => screen.getByText("cmd + C", { exact: false })).to.throw;
35+
36+
expect(screen.getByText("C")).to.exist;
37+
expect(screen.queryByText("ctrl")).to.not.exist;
3238
});
3339

3440
it("should render minimal key combos on non-Macs using text", () => {
3541
render(<KeyComboTagInternal combo="mod+C" minimal={true} platformOverride="Win32" />);
36-
const text = screen.getByText("ctrl + C", { exact: false }).innerText;
37-
expect(text).to.contain("ctrl");
38-
expect(text).to.contain("+");
39-
expect(text).to.contain("C");
42+
43+
expect(screen.getByText("ctrl + C")).to.exist;
44+
});
45+
46+
it("should render aliased keys with correct icon and text", () => {
47+
const { container } = render(<KeyComboTagInternal combo="arrowleft" />);
48+
const icon = container.querySelector('[data-icon="arrow-left"]');
49+
50+
expect(icon).to.exist;
51+
expect(screen.getByText("left")).to.exist;
4052
});
4153
});

0 commit comments

Comments
 (0)