Skip to content

Commit

Permalink
docs(keyboard-key): add documentation (#4164)
Browse files Browse the repository at this point in the history
* feat(keyboard-key): component init

* chore(tools): plopfile syntax fix

* chore(tools): plopfile syntax fix

* chore(tools): plopfile syntax fix

* feat(keyboard-key):  styled w/ hook unit tests

* feat(keyboard-key):  added variants and styles

* chore(plop): update tsx dependency

* chore(keyboard-key): internal exports in core

* chore(keyboard-key): typedocs & build

* chore(docs): use KeyboardKey in nav

* docs(keyboard-key): init content

* feat(keyboard-key): change to infline-flex style

* docs(keybaord-key): added examples

* chore(keyboard-key): added stroy

* chore(keyboard-key): linting

* fix(keyboard-key): command logic

* feat(design-tokens): added new box shadows to support keyboard-keys

* chore(ci-cd): added chagesets

* fix(keyboard-key): boxShadow stylings

* fix(keyboard-key): remove null component wrapper

* fix(keyboard-key): aria-hidden

* chore(keyboard-key): refactor

* chore(keyboard-key): code cleanup

* chore(keyboard-key): code cleanup

* chore(keyboard-key): typedocs

* chore(keyboard-key): fix tests

* fix(keyboard-key): aria and diableBrowserShortcuts

* fix(keyboard-key): props fix

* chore(keyboard-key): playgorund storybook

* chore(keyboard-key): formatting fix

* chore(keyboard-key): stories update

* chore(keyboard-key): formatting fix

* chore(keyboard-key): typo

* Update .changeset/sweet-mugs-admire.md

Co-authored-by: Nora Krantz <[email protected]>

* Update .changeset/shaggy-sheep-confess.md

Co-authored-by: Nora Krantz <[email protected]>

* chore(keyboard-key): address PR comments

* feat(keyboard-tooltip): wip

* chore(tooltip): update types

* chore(tooltip): update types

* chore(tooltip): better var naming

* chore(tooltip): fail safe check

* chore(tooltip): linting

* chore(tooltip): linting

* chore(tooltip): yarn lock

* chore(tooltip): changeset

* chore(tooltip): fix spelling

* chore(tooltip): uppdate type name

* docs(keyboard-key): wip

* feat(tooltip): add anonymous keybaord action to tooltip

* fix(keyboard-key): ignore case sensitivty to overcome shift combo bug

* fix(keyboard-key): ignore case sensitivty to overcome shift combo bug

* Update packages/paste-core/components/tooltip/src/Tooltip.tsx

Co-authored-by: Sarah <[email protected]>

* fix(tooltip): update keyboardkey styles

* chore(tooltip): formatting

* docs(keyboard-key): hook examples

* docs(keyboard-key): fix composition notes

* docs(keyboard-key): fix docs search

* docs(keyboard-key): change example trigger

* docs(keyboard-key): fix build issue

* docs(keyboard-key): yanlock

* docs(keyboard-key): import fix

* docs(keyboard-key): lint and format

* docs(keyboard-key): changeset

* Apply suggestions from code review

Co-authored-by: Nora Krantz <[email protected]>

* docs(keyboard-key): address PR comments

* Apply suggestions from code review

Co-authored-by: Nora Krantz <[email protected]>

* docs(keyboard-key): address PR comments

* docs(keyboard-key): remopve unused import

* docs(keyboard-key): address PR comments

* docs(keyboard-key): address PR comments

* docs(keyboard-key): address PR comments

* docs(keyboard-key): pressed stlying example

---------

Co-authored-by: Nora Krantz <[email protected]>
Co-authored-by: Sarah <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 27, 2024
1 parent 7f39856 commit 42a4dcb
Show file tree
Hide file tree
Showing 12 changed files with 728 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .changeset/slow-jokes-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/keyboard-key": patch
"@twilio-paste/core": patch
---

[KeyboardKey] fixed issue with shift key being captured as capitals on subsequesnt key presses
3 changes: 3 additions & 0 deletions cypress/integration/sitemap-vrt/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export const SITEMAP = [
"/components/input/",
"/components/input/api",
"/components/input/changelog",
"components/keyboard-key",
"components/keyboard-key/api",
"components/keyboard-key/changelog",
"/components/label/",
"/components/label/api",
"/components/label/changelog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
Expand All @@ -49,11 +49,11 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control", "d", "v"]);
expect(result.current?.activeKeys).toEqual(["control", "d", "v"]);
});

await act(async () => {
fireEvent.keyUp(window, { key: "Control" });
fireEvent.keyUp(window, { key: "control" });
fireEvent.keyUp(window, { key: "d" });
});

Expand All @@ -73,15 +73,15 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
fireEvent.keyDown(window, { key: "b" });
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "b"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "b"]));
expect(onCombinationPress).toHaveBeenCalled();
});
});
Expand All @@ -97,15 +97,15 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
fireEvent.keyDown(window, { key: "d" });
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control", "d"]);
expect(result.current?.activeKeys).toEqual(["control", "d"]);
expect(onCombinationPress).not.toHaveBeenCalled();
});
});
Expand All @@ -121,7 +121,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
Expand All @@ -130,7 +130,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "v", "b"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "v", "b"]));
expect(onCombinationPress).not.toHaveBeenCalled();
});
});
Expand All @@ -148,15 +148,15 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
fireEvent.keyDown(window, { key: "b" });
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "b"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "b"]));
expect(onCombinationPress).not.toHaveBeenCalled();
});
});
Expand All @@ -180,7 +180,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
Expand All @@ -189,7 +189,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control", "d", "v"]);
expect(result.current?.activeKeys).toEqual(["control", "d", "v"]);
});

await act(async () => {
Expand Down Expand Up @@ -222,15 +222,15 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
fireEvent.keyDown(window, { key: "b" });
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "b"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "b"]));
expect(onCombinationPress1).toHaveBeenCalled();
expect(onCombinationPress2).not.toHaveBeenCalled();
});
Expand All @@ -241,7 +241,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "b", "c"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "b", "c"]));
expect(onCombinationPress1).not.toHaveBeenCalled();
expect(onCombinationPress2).not.toHaveBeenCalled();
});
Expand All @@ -251,7 +251,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "c"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "c"]));
expect(onCombinationPress1).not.toHaveBeenCalled();
expect(onCombinationPress2).toHaveBeenCalled();
});
Expand All @@ -277,15 +277,15 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(["Control"]);
expect(result.current?.activeKeys).toEqual(["control"]);
});

await act(async () => {
fireEvent.keyDown(window, { key: "b" });
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "b"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "b"]));
expect(onCombinationPress1).toHaveBeenCalled();
expect(onCombinationPress2).not.toHaveBeenCalled();
});
Expand All @@ -296,7 +296,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "b", "c"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "b", "c"]));
expect(onCombinationPress1).not.toHaveBeenCalled();
expect(onCombinationPress2).not.toHaveBeenCalled();
});
Expand All @@ -306,7 +306,7 @@ describe("Hooks", () => {
});

await waitFor(() => {
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["Control", "c"]));
expect(result.current?.activeKeys).toEqual(expect.arrayContaining(["control", "c"]));
expect(onCombinationPress1).not.toHaveBeenCalled();
expect(onCombinationPress2).not.toHaveBeenCalled();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/keyboard-key/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"category": "typography",
"status": "production",
"description": "A keyboard key distinguishes a keyboard command or shortcut from other text.",
"description": "A Keyboard Key distinguishes a keyboard command or shortcut from other text.",
"author": "Twilio Inc.",
"license": "MIT",
"main:dev": "src/index.tsx",
Expand Down
7 changes: 4 additions & 3 deletions packages/paste-core/components/keyboard-key/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useKeyEvents = (): { activeKeys: string[] } => {
const handleKeyDown = (e: KeyboardEvent): void => {
if (!e.repeat) {
setActiveKeys((prev) => {
return Array.from(new Set([...prev, e.key]));
return Array.from(new Set([...prev, e.key.toLowerCase()]));
});
}
};
Expand All @@ -41,7 +41,7 @@ const useKeyEvents = (): { activeKeys: string[] } => {
if (e.key === "Meta") {
setActiveKeys([]);
} else {
setActiveKeys((prev) => [...prev].filter((k) => k !== e.key));
setActiveKeys((prev) => [...prev].filter((k) => k.toLowerCase() !== e.key.toLowerCase()));
}
};

Expand All @@ -59,7 +59,8 @@ const useKeyEvents = (): { activeKeys: string[] } => {
};

const stringArrayMatches = (arr1: string[], arr2: string[]): boolean =>
JSON.stringify(arr1.sort((a, b) => a.localeCompare(b))) === JSON.stringify(arr2.sort((a, b) => a.localeCompare(b)));
JSON.stringify(arr1.sort((a, b) => a.localeCompare(b)).map((s) => s.toLowerCase())) ===
JSON.stringify(arr2.sort((a, b) => a.localeCompare(b)));

export const useKeyCombination = ({
keys,
Expand Down
1 change: 1 addition & 0 deletions packages/paste-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@twilio-paste/inline-control-group": "^13.0.2",
"@twilio-paste/input": "^9.1.3",
"@twilio-paste/input-box": "^10.1.1",
"@twilio-paste/keyboard-key": "^0.0.0",
"@twilio-paste/label": "^13.1.1",
"@twilio-paste/lexical-library": "^4.2.0",
"@twilio-paste/list": "^8.2.1",
Expand Down
Loading

0 comments on commit 42a4dcb

Please sign in to comment.