@torpor/ui 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ import {
2
+ TabGroup,
3
+ TabList,
4
+ TabHeader,
5
+ TabTrigger,
6
+ TabContent,
7
+ } from "../../../src/TabGroup/index";
8
+
9
+ export default function TabGroupList() {
10
+ @render {
11
+ <TabGroup value={$props.value}>
12
+ <TabList>
13
+ @for (let item of $props.items) {
14
+ @key = item.id
15
+ <TabHeader as="h4">
16
+ <TabTrigger>{item.header}</TabTrigger>
17
+ </TabHeader>
18
+ }
19
+ </TabList>
20
+ @for (let item of $props.items) {
21
+ @key = item.id
22
+ <TabContent>{item.text}</TabContent>
23
+ }
24
+ </TabGroup>
25
+ }
26
+ }
@@ -0,0 +1,28 @@
1
+ import {
2
+ TabGroup,
3
+ TabList,
4
+ TabHeader,
5
+ TabTrigger,
6
+ TabContent,
7
+ } from "../../../src/TabGroup/index";
8
+
9
+ export default function TabGroupTrigger() {
10
+ @render {
11
+ <TabGroup value={$props.value}>
12
+ <TabList>
13
+ <TabHeader as="h4">
14
+ <TabTrigger>Header 1</TabTrigger>
15
+ </TabHeader>
16
+ <TabHeader as="h4">
17
+ <TabTrigger>Header 2</TabTrigger>
18
+ </TabHeader>
19
+ <TabHeader as="h4">
20
+ <TabTrigger>Header 3</TabTrigger>
21
+ </TabHeader>
22
+ </TabList>
23
+ <TabContent>Content 1</TabContent>
24
+ <TabContent>Content 2</TabContent>
25
+ <TabContent>Content 3</TabContent>
26
+ </TabGroup>
27
+ }
28
+ }
@@ -0,0 +1,54 @@
1
+ import { getByText, queryByText } from "@testing-library/dom";
2
+ import "@testing-library/jest-dom/vitest";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { $watch, mount } from "@torpor/view";
5
+ import { describe, expect, it } from "vitest";
6
+ import TabGroupList from "./components/TabGroupList.torp";
7
+
8
+ describe("TabGroup", () => {
9
+ it("Items in a for loop", async () => {
10
+ const user = userEvent.setup();
11
+
12
+ let $state = $watch({
13
+ value: "1",
14
+ items: [
15
+ { id: 0, header: "Item 1", text: "Content 1" },
16
+ { id: 1, header: "Item 2", text: "Content 2" },
17
+ { id: 2, header: "Item 3", text: "Content 3" },
18
+ ],
19
+ });
20
+
21
+ const container = document.createElement("div");
22
+ document.body.appendChild(container);
23
+ mount(container, TabGroupList, $state);
24
+
25
+ expect(queryByText(container, "Content 1")).not.toBeInTheDocument();
26
+ expect(queryByText(container, "Item 2")).toBeInTheDocument();
27
+ expect(queryByText(container, "Content 2")).toBeInTheDocument();
28
+ expect(queryByText(container, "Content 3")).not.toBeInTheDocument();
29
+
30
+ $state.items.splice(1, 1);
31
+
32
+ expect(queryByText(container, "Content 1")).not.toBeInTheDocument();
33
+ expect(queryByText(container, "Item 2")).not.toBeInTheDocument();
34
+ expect(queryByText(container, "Content 2")).not.toBeInTheDocument();
35
+ expect(queryByText(container, "Content 3")).not.toBeInTheDocument();
36
+
37
+ // Clicking header 1 should reveal body 1
38
+ await user.click(getByText(container, "Item 1"));
39
+ expect(queryByText(container, "Content 1")).toBeInTheDocument();
40
+
41
+ $state.items.push({ id: 3, header: "Item 4", text: "Content 4" });
42
+
43
+ expect(queryByText(container, "Content 1")).toBeInTheDocument();
44
+ expect(queryByText(container, "Content 2")).not.toBeInTheDocument();
45
+ expect(queryByText(container, "Content 3")).not.toBeInTheDocument();
46
+ expect(queryByText(container, "Item 4")).toBeInTheDocument();
47
+ expect(queryByText(container, "Content 4")).not.toBeInTheDocument();
48
+
49
+ // Clicking header 4 should reveal body 4
50
+ await user.click(getByText(container, "Item 4"));
51
+ expect(queryByText(container, "Content 1")).not.toBeInTheDocument();
52
+ expect(queryByText(container, "Content 4")).toBeInTheDocument();
53
+ });
54
+ });
@@ -0,0 +1,34 @@
1
+ import { getByText, queryByText } from "@testing-library/dom";
2
+ import "@testing-library/jest-dom/vitest";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { mount } from "@torpor/view";
5
+ import { describe, expect, it } from "vitest";
6
+ import TabGroupTrigger from "./components/TabGroupTrigger.torp";
7
+
8
+ describe("TabGroup", () => {
9
+ it("Item trigger", async () => {
10
+ const user = userEvent.setup();
11
+
12
+ const container = document.createElement("div");
13
+ document.body.appendChild(container);
14
+ mount(container, TabGroupTrigger);
15
+
16
+ expect(queryByText(container, "Content 1")).not.toBeInTheDocument();
17
+ expect(queryByText(container, "Content 2")).not.toBeInTheDocument();
18
+ expect(queryByText(container, "Content 3")).not.toBeInTheDocument();
19
+
20
+ // Clicking header 1 should reveal body 1
21
+ await user.click(getByText(container, "Header 1"));
22
+ expect(queryByText(container, "Content 1")).toBeInTheDocument();
23
+
24
+ // Clicking header 2 should hide body 1 and reveal body 2
25
+ await user.click(getByText(container, "Header 2"));
26
+ expect(queryByText(container, "Content 1")).not.toBeInTheDocument();
27
+ expect(queryByText(container, "Content 2")).toBeInTheDocument();
28
+
29
+ // Clicking header 2 again should keep body 2
30
+ await user.click(getByText(container, "Header 2"));
31
+ expect(queryByText(container, "Content 1")).not.toBeInTheDocument();
32
+ expect(queryByText(container, "Content 2")).toBeInTheDocument();
33
+ });
34
+ });
@@ -0,0 +1,17 @@
1
+ import { queryByText } from "@testing-library/dom";
2
+ import "@testing-library/jest-dom/vitest";
3
+ import { mount } from "@torpor/view";
4
+ import { describe, expect, it } from "vitest";
5
+ import TabGroupTrigger from "./components/TabGroupTrigger.torp";
6
+
7
+ describe("TabGroup", () => {
8
+ it("Item default value", async () => {
9
+ const container = document.createElement("div");
10
+ document.body.appendChild(container);
11
+ mount(container, TabGroupTrigger, { value: "1" });
12
+
13
+ expect(queryByText(container, "Content 1")).not.toBeInTheDocument();
14
+ expect(queryByText(container, "Content 2")).toBeInTheDocument();
15
+ expect(queryByText(container, "Content 3")).not.toBeInTheDocument();
16
+ });
17
+ });
@@ -0,0 +1,72 @@
1
+ import { fireEvent, getByText, queryByText } from "@testing-library/dom";
2
+ import "@testing-library/jest-dom/vitest";
3
+ import { mount } from "@torpor/view";
4
+ import { describe, expect, it } from "vitest";
5
+ import TabGroupKeyboard from "./components/TabGroupKeyboard.torp";
6
+
7
+ describe("TabGroup", () => {
8
+ it("Keyboard", async () => {
9
+ const container = document.createElement("div");
10
+ document.body.appendChild(container);
11
+ mount(container, TabGroupKeyboard, { value: "0" });
12
+
13
+ // Tests from https://www.w3.org/WAI/ARIA/apg/patterns/tabs/
14
+
15
+ // Enter or Space:
16
+ // * When focus is on the tab header for a collapsed panel, expands
17
+ // the associated panel. If the implementation allows only one panel
18
+ // to be expanded, and if another panel is expanded, collapses that
19
+ // panel
20
+ // * When focus is on the tab header for an expanded panel, collapses
21
+ // the panel if the implementation supports collapsing. Some
22
+ // implementations require one panel to be expanded at all times and
23
+ // allow only one panel to be expanded; so, they do not support a
24
+ // collapse function
25
+ // NOTE: I don't think we can test this
26
+ // NOTE: TabGroup headers are buttons so this functionality should be baked in by default
27
+ //screen.queryByText('Header 1').focus();
28
+ //expect(screen.queryByText('Content 1')).not.toBeInTheDocument();
29
+ //fireEvent(screen.getByText('Header 1'), { key: 'Space' });
30
+ //expect(screen.queryByText('Content 1')).toBeInTheDocument();
31
+ //fireEvent(screen.getByText('Header 1'), { key: 'Space' });
32
+ //expect(screen.queryByText('Content 1')).not.toBeInTheDocument();
33
+
34
+ // Tab: Moves focus to the next focusable element; all focusable
35
+ // elements in the tab are included in the page Tab sequence
36
+ // NOTE: I don't think we can test this
37
+ //fireEvent(screen.getByText('Header 1'), { key: 'Tab' });
38
+ //expect(document.activeElement).toBe(screen.queryByText('Header 2'));
39
+
40
+ // Shift + Tab: Moves focus to the previous focusable element; all
41
+ // focusable elements in the tab are included in the page Tab
42
+ // sequence
43
+ // NOTE: I don't think we can test this
44
+ //fireEvent(screen.getByText('Header 2'), { key: 'Tab', shiftKey: true });
45
+ //expect(document.activeElement).toBe(screen.queryByText('Header 1'));
46
+
47
+ // Right Arrow: If focus is on a tab header, moves focus to the next tab
48
+ // header. If focus is on the last tab header, either does nothing or
49
+ // moves focus to the first tab header
50
+ fireEvent(
51
+ getByText(container, "Header 1"),
52
+ new KeyboardEvent("keydown", { key: "ArrowRight" }),
53
+ );
54
+ expect(document.activeElement).toBe(queryByText(container, "Header 2"));
55
+
56
+ // Left Arrow: If focus is on a tab header, moves focus to the previous
57
+ // tab header. If focus is on the first tab header, either does nothing
58
+ // or moves focus to the last tab header
59
+ fireEvent(getByText(container, "Header 2"), new KeyboardEvent("keydown", { key: "ArrowLeft" }));
60
+ expect(document.activeElement).toBe(queryByText(container, "Header 1"));
61
+
62
+ // Home: When focus is on a tab header, moves focus to the first tab
63
+ // header
64
+ fireEvent(getByText(container, "Header 3"), new KeyboardEvent("keydown", { key: "Home" }));
65
+ expect(document.activeElement).toBe(queryByText(container, "Header 1"));
66
+
67
+ // End: When focus is on a tab header, moves focus to the last tab
68
+ // header
69
+ fireEvent(getByText(container, "Header 1"), new KeyboardEvent("keydown", { key: "End" }));
70
+ expect(document.activeElement).toBe(queryByText(container, "Header 3"));
71
+ });
72
+ });
package/tsup.config.ts CHANGED
@@ -6,7 +6,7 @@ type Config =
6
6
  | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
7
7
 
8
8
  export default defineConfig({
9
- entry: ["src/Accordion/index.ts", "src/motion.ts"],
9
+ entry: ["src/Accordion/index.ts", "src/TabGroup/index.ts", "src/motion.ts"],
10
10
  format: ["esm", "cjs"],
11
11
  dts: { entry: ["src/motion.ts"] },
12
12
  clean: true,