-
-
Notifications
You must be signed in to change notification settings - Fork 589
Expand file tree
/
Copy pathRSwitch.stories.ts
More file actions
88 lines (76 loc) · 2.28 KB
/
Copy pathRSwitch.stories.ts
File metadata and controls
88 lines (76 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import type { Meta, StoryObj } from "@storybook/vue3-vite";
import { expect, userEvent, within } from "storybook/test";
import { ref } from "vue";
import RSwitch from "./RSwitch.vue";
const meta: Meta<typeof RSwitch> = {
title: "Forms/RSwitch",
component: RSwitch,
argTypes: {
label: { control: "text" },
size: { control: "inline-radio", options: ["default", "small"] },
disabled: { control: "boolean" },
},
render: (args) => ({
components: { RSwitch },
setup: () => {
const value = ref(false);
return { args, value };
},
template: `
<div class="r-v2 r-v2-dark" style="padding: 32px; background: #07070f;">
<RSwitch v-model="value" v-bind="args" />
</div>
`,
}),
};
export default meta;
type Story = StoryObj<typeof RSwitch>;
export const Default: Story = {
args: { ariaLabel: "Toggle setting" },
};
export const WithLabel: Story = {
args: { label: "Notifications" },
};
export const Checked: Story = {
render: (args) => ({
components: { RSwitch },
setup: () => {
const value = ref(true);
return { args, value };
},
template: `
<div class="r-v2 r-v2-dark" style="padding: 32px; background: #07070f;">
<RSwitch v-model="value" v-bind="args" />
</div>
`,
}),
args: { label: "Notifications" },
};
export const Small: Story = {
args: { label: "Compact toggle", size: "small" },
};
export const Disabled: Story = {
args: { label: "Disabled", disabled: true },
};
// Keyboard: Tab focuses the switch, Space/Enter toggle it.
export const KeyboardToggle: Story = {
name: "Keyboard toggle (play)",
args: { label: "Notifications" },
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
const sw = canvas.getByRole("switch");
await step("Tab moves focus onto the switch", async () => {
await userEvent.tab();
expect(sw).toHaveFocus();
expect(sw).toHaveAttribute("aria-checked", "false");
});
await step("Space toggles it on", async () => {
await userEvent.keyboard(" ");
expect(sw).toHaveAttribute("aria-checked", "true");
});
await step("Enter toggles it back off", async () => {
await userEvent.keyboard("{Enter}");
expect(sw).toHaveAttribute("aria-checked", "false");
});
},
};