@becket-ui/react 0.1.2 → 0.2.0
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.
- package/dist/components/Box.d.ts +20 -0
- package/dist/components/Box.d.ts.map +1 -0
- package/dist/components/Box.js +21 -0
- package/dist/components/Box.js.map +1 -0
- package/dist/components/Button.d.ts +15 -12
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Container.d.ts +21 -0
- package/dist/components/Container.d.ts.map +1 -0
- package/dist/components/Container.js +21 -0
- package/dist/components/Container.js.map +1 -0
- package/dist/components/Glyphs.d.ts +16 -0
- package/dist/components/Glyphs.d.ts.map +1 -0
- package/dist/components/Glyphs.js +83 -0
- package/dist/components/Glyphs.js.map +1 -0
- package/dist/components/Icon.d.ts +20 -0
- package/dist/components/Icon.d.ts.map +1 -0
- package/dist/components/Icon.js +23 -0
- package/dist/components/Icon.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/guides/building-with-becket.md +269 -0
- package/package.json +5 -4
- package/dist/components/Button.test.js +0 -45
- package/dist/components/Button.test.js.map +0 -1
- package/dist/components/Dialog.test.js +0 -89
- package/dist/components/Dialog.test.js.map +0 -1
- package/dist/components/Drawer.test.js +0 -50
- package/dist/components/Drawer.test.js.map +0 -1
- package/dist/components/Field.test.js +0 -33
- package/dist/components/Field.test.js.map +0 -1
- package/dist/components/Menu.test.js +0 -69
- package/dist/components/Menu.test.js.map +0 -1
- package/dist/components/Switch.test.js +0 -28
- package/dist/components/Switch.test.js.map +0 -1
- package/dist/components/Tabs.test.js +0 -41
- package/dist/components/Tabs.test.js.map +0 -1
- package/dist/components/Tooltip.test.js +0 -58
- package/dist/components/Tooltip.test.js.map +0 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Writing app code with Becket UI
|
|
2
|
+
|
|
3
|
+
How to write React screens with `@becket-ui/react`. It's written for people and for agents: Claude
|
|
4
|
+
Design while it builds a design, Claude Code when it turns a design into app code, and any coding
|
|
5
|
+
agent connected to the Becket MCP. If you follow this guide, the code reads top to bottom, uses
|
|
6
|
+
Becket for everything Becket can do, and keeps working in dark and light themes.
|
|
7
|
+
|
|
8
|
+
Each rule says **Must** (required) or **Prefer / Avoid** (the default; deviate with a reason in a
|
|
9
|
+
comment).
|
|
10
|
+
|
|
11
|
+
## 1. Setup, once per app
|
|
12
|
+
|
|
13
|
+
- Install `@becket-ui/react` and `@becket-ui/tokens`. Import `@becket-ui/tokens/index.css` **once**,
|
|
14
|
+
at the app entry.
|
|
15
|
+
- The theme lives on `<html data-theme="dark|light">` (dark is the default). Set it at the app root,
|
|
16
|
+
never inside a screen. There is **no provider** and no theme wrapper.
|
|
17
|
+
- `index.css` already paints the page background, text color and font from the theme. Don't repeat
|
|
18
|
+
that on a wrapper `div`.
|
|
19
|
+
|
|
20
|
+
## 2. Must use a Becket component when one exists
|
|
21
|
+
|
|
22
|
+
Raw elements with inline styles are the most common mistake. Use this table:
|
|
23
|
+
|
|
24
|
+
| Instead of | Use |
|
|
25
|
+
| ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| page wrapper `div` (max width, centering, gutters) | `Container as="main" size="md"` |
|
|
27
|
+
| plain block `div` with padding, background or radius | `Box padding="md" background="subtle" radius="md"` |
|
|
28
|
+
| `div` with `display: flex; flex-direction: column` | `VStack` / `Stack` |
|
|
29
|
+
| `div` with `display: flex` (row) | `HStack`, or `Flex` for wrap, grow and basis |
|
|
30
|
+
| `div` with `display: grid` | `SimpleGrid columns={{ base: 1, md: 2 }}` |
|
|
31
|
+
| `h1`–`h6` with font styles | `Heading as="h1" size="2xl"` |
|
|
32
|
+
| `p` / `span` with font size or color | `Text fontSize="sm" color="muted"` |
|
|
33
|
+
| bold `span` | `Text as="strong"` |
|
|
34
|
+
| `hr`, or a 1px `div` | `Separator` (`orientation="vertical"` inside a row) |
|
|
35
|
+
| `button` | `Button visual="primary\|secondary\|neutral\|outline"` |
|
|
36
|
+
| `input` + `label` | `Field` + `FieldLabel` + `FieldControl`, or `TextField label` |
|
|
37
|
+
| `select` / `textarea` | `Select` / `Textarea` (or `FieldSelect` / `FieldTextarea` inside `Field`) |
|
|
38
|
+
| checkbox / radio / toggle `input` | `Checkbox`, `RadioGroup` + `Radio`, `Switch` |
|
|
39
|
+
| `table`, `tr`, `td` | `Table`, `Thead`, `Tbody`, `Tr`, `Th`, `Td` |
|
|
40
|
+
| panel `div` with border and padding | `Card` + `CardHeader` / `CardBody` / `CardFooter` |
|
|
41
|
+
| pill `span` | `Tag` (label) or `Badge` (count or status) |
|
|
42
|
+
| inline `svg` icon | `Icon` around your SVG, or a built-in glyph (`SearchIcon`, `ChevronDownIcon`, …); add `label` only when it carries meaning |
|
|
43
|
+
| `a` | `Link` |
|
|
44
|
+
| `a` styled as a button (call to action) | `Button as="a" href="…"` (anchor props are typed) |
|
|
45
|
+
| custom modal, side panel, dropdown, tabs or tooltip | `Dialog`, `Drawer`, `Menu`, `Tabs`, `Tooltip` |
|
|
46
|
+
|
|
47
|
+
Raw elements are fine for semantics Becket doesn't cover (`form`, `main`, `nav`, `section`,
|
|
48
|
+
`ul`/`li`). Render them through a layout component's `as` prop when they also lay things out:
|
|
49
|
+
`<VStack as="form" gap="md">`.
|
|
50
|
+
|
|
51
|
+
**Known gaps** (until these ship, an inline `style` with tokens is allowed, with a `TODO` naming the
|
|
52
|
+
ticket):
|
|
53
|
+
|
|
54
|
+
- Font weight on `Text`: no `weight` prop yet (MAV-106). Use `Text as="strong"` for bold.
|
|
55
|
+
- Status colors on `Badge` and `Tag`: no `success` / `warning` / `danger` visuals yet (MAV-107).
|
|
56
|
+
Don't use a brand visual (`primary`, `secondary`) to mean a status.
|
|
57
|
+
|
|
58
|
+
## 3. Prefer props, then tokens. Never classes, never literals
|
|
59
|
+
|
|
60
|
+
Style with component props, written inline where the component is used. That's Becket's design
|
|
61
|
+
language: `gap`, `align`, `justify`, `visual`, `size`, `invalid`, `columns`.
|
|
62
|
+
|
|
63
|
+
- **Spacing:** semantic `gap="xs|sm|md|lg|xl"` (or the Fibonacci steps `1 2 3 5 8 13 21 34`). Never
|
|
64
|
+
pixel numbers.
|
|
65
|
+
- **When you need your own CSS** (a known gap above, or a one-off like `minWidth: 0`), use token
|
|
66
|
+
variables: `var(--beckui--colors-muted)`, `var(--beckui--spacing-lg)`, `var(--beckui--sizes-4xl)`,
|
|
67
|
+
`var(--beckui--radii-md)`. Never hex, `rgb()`, or raw pixel values for spacing and color.
|
|
68
|
+
- **Must not** write or copy `.beckui--*` class names. They're generated, not API.
|
|
69
|
+
- **Avoid** named styled wrappers, CSS files per screen, or style objects defined away from the
|
|
70
|
+
element. A reader shouldn't have to look anything up to see how an element looks.
|
|
71
|
+
- **Colors carry meaning:** `primary` (yellow), `secondary` (sage) and `tertiary` (amber) are brand
|
|
72
|
+
identity; `danger`, `warning` and `success` are status only.
|
|
73
|
+
|
|
74
|
+
## 4. Avoid hasty abstraction: inline first, extract on the third copy
|
|
75
|
+
|
|
76
|
+
Write markup inline. Extract a local component only when the same markup appears **three times** in
|
|
77
|
+
the same feature. Then:
|
|
78
|
+
|
|
79
|
+
- Build it only from Becket components and tokens; a helper made of raw `div`s and `span`s is the
|
|
80
|
+
same mistake, just moved.
|
|
81
|
+
- Keep it in the same file, or next to it, until a second feature needs it.
|
|
82
|
+
- Name it for what it shows (`MemberName`), not how (`TitleCell`).
|
|
83
|
+
|
|
84
|
+
## 5. Prefer inversion of control: compose, don't configure
|
|
85
|
+
|
|
86
|
+
Pass content in instead of adding flags: `children`, element props (`actions={<Button>…</Button>}`),
|
|
87
|
+
and Becket's compound parts (`CardHeader` / `CardBody` / `CardFooter`, `DialogHeader` /
|
|
88
|
+
`DialogFooter`, `TabList` / `Tab` / `TabPanel`). A screen component with `showX`, `isY` and
|
|
89
|
+
`variantZ` booleans is a sign to invert.
|
|
90
|
+
|
|
91
|
+
## 6. Prefer native HTML and zero JavaScript
|
|
92
|
+
|
|
93
|
+
Becket is native-first. Prefer the components and props that work without client JavaScript.
|
|
94
|
+
Interactive ones (`Tabs`, `Menu`, `Tooltip`, controlled `Dialog` / `Drawer`) ship JS. Use them when
|
|
95
|
+
the interaction needs them, not for static content. Put `'use client'` only on the leaf component
|
|
96
|
+
that holds state or handlers, never on a whole page or barrel file.
|
|
97
|
+
|
|
98
|
+
## 7. State and effects
|
|
99
|
+
|
|
100
|
+
- **Derive, don't sync:** compute values from props and state during render
|
|
101
|
+
(`const activeCount = members.filter((m) => m.isActive).length`). Don't mirror them into state
|
|
102
|
+
with an effect.
|
|
103
|
+
- **Effects** are only for syncing with something outside React (subscriptions, timers, storage).
|
|
104
|
+
Theme and analytics belong at the app root.
|
|
105
|
+
- **Must not mutate** state, props or shared constants. Create new values with spread, `map`,
|
|
106
|
+
`filter` or `toSorted()`.
|
|
107
|
+
- Keep each piece of state in one place, as low in the tree as it can live.
|
|
108
|
+
|
|
109
|
+
## 8. Accessibility (WCAG 2.2 AA)
|
|
110
|
+
|
|
111
|
+
- Every control has a name: a visible label (`TextField label`, `FieldLabel`, `Switch label`) or
|
|
112
|
+
`aria-label` when the label is visual only, such as a `Switch` in a table row:
|
|
113
|
+
``aria-label={`Access for ${member.name}`}``.
|
|
114
|
+
- One `h1` per page. Headings follow the document outline (`Heading as="h2"` for sections).
|
|
115
|
+
- Use `Button` for actions and `Link` for navigation, never a clickable `div`.
|
|
116
|
+
- Don't rely on color alone for status: keep the text ("Active", "Invited").
|
|
117
|
+
|
|
118
|
+
## 9. TypeScript and naming
|
|
119
|
+
|
|
120
|
+
- Type props explicitly (`type MemberTableProps = { … }`). Let TypeScript infer locals. Must not use
|
|
121
|
+
`any`.
|
|
122
|
+
- Use string unions and `as const` data instead of `enum`:
|
|
123
|
+
`const ROLES = ['owner', 'admin', 'member'] as const`.
|
|
124
|
+
- Use stable keys from data (`key={member.id}`), never the array index for lists that change.
|
|
125
|
+
- Callback props are `onX`; handlers inside are `handleX`. Booleans start with `is`, `has`, `should`
|
|
126
|
+
or `can`.
|
|
127
|
+
- Functions say what they do (`selectActiveMembers`, `formatSeatCount`), not `getX`. Keep
|
|
128
|
+
initialisms in one case (`userID`, `inviteURL`).
|
|
129
|
+
- Sort imports: third-party (React, then `@becket-ui/react`), then absolute app modules, then
|
|
130
|
+
relative.
|
|
131
|
+
- Comment **why**, not what. A `TODO` names its ticket: `// TODO (MAV-106): use Text weight`.
|
|
132
|
+
|
|
133
|
+
## 10. Example: a settings screen
|
|
134
|
+
|
|
135
|
+
### Avoid
|
|
136
|
+
|
|
137
|
+
From a real Claude Design handoff. It uses Becket's Tabs, Table and Switch correctly, but builds
|
|
138
|
+
everything else from raw markup:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
<div style={{ minHeight: '100vh', background: 'var(--beckui--colors-background)', padding: '48px 24px' }}>
|
|
142
|
+
<div style={{ maxWidth: 880, display: 'flex', flexDirection: 'column', gap: 28 }}>
|
|
143
|
+
<h1 style={{ margin: 0, fontSize: 'var(--beckui--font-sizes-2xl)', fontWeight: 600 }}>Workspace settings</h1>
|
|
144
|
+
<p style={{ margin: 0, color: 'var(--beckui--colors-muted)' }}>Manage how the workspace behaves.</p>
|
|
145
|
+
{PREFS.map((pref, i) => (
|
|
146
|
+
<div key={pref.k}>
|
|
147
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 24, padding: '16px 0' }}>
|
|
148
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
149
|
+
<span style={{ fontWeight: 600 }}>{pref.title}</span>
|
|
150
|
+
<span style={{ color: 'var(--beckui--colors-muted)' }}>{pref.desc}</span>
|
|
151
|
+
</div>
|
|
152
|
+
<Switch checked={prefs[pref.k]} onCheckedChange={…} aria-label={pref.title} />
|
|
153
|
+
</div>
|
|
154
|
+
{i < PREFS.length - 1 && <div style={{ height: 1, background: 'var(--beckui--colors-border)' }} />}
|
|
155
|
+
</div>
|
|
156
|
+
))}
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
What's wrong:
|
|
162
|
+
|
|
163
|
+
- Flex `div`s instead of `VStack` / `HStack`.
|
|
164
|
+
- `h1` / `p` / `span` instead of `Heading` / `Text`.
|
|
165
|
+
- A 1px `div` instead of `Separator`.
|
|
166
|
+
- Pixel gaps.
|
|
167
|
+
- A background the CSS already paints.
|
|
168
|
+
- A cryptic data key (`k`).
|
|
169
|
+
|
|
170
|
+
### Prefer
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
import { useState } from "react";
|
|
174
|
+
import {
|
|
175
|
+
Card,
|
|
176
|
+
CardBody,
|
|
177
|
+
Container,
|
|
178
|
+
Heading,
|
|
179
|
+
HStack,
|
|
180
|
+
Separator,
|
|
181
|
+
Switch,
|
|
182
|
+
Text,
|
|
183
|
+
VStack,
|
|
184
|
+
} from "@becket-ui/react";
|
|
185
|
+
|
|
186
|
+
const PREFERENCES = [
|
|
187
|
+
{
|
|
188
|
+
id: "public",
|
|
189
|
+
title: "Public workspace",
|
|
190
|
+
description: "Anyone with the link can request to join.",
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: "guests",
|
|
194
|
+
title: "Allow guests",
|
|
195
|
+
description: "Invite people outside your domain with limited access.",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
id: "sso",
|
|
199
|
+
title: "Require SSO",
|
|
200
|
+
description: "Members sign in through your identity provider.",
|
|
201
|
+
},
|
|
202
|
+
] as const;
|
|
203
|
+
|
|
204
|
+
type PreferenceID = (typeof PREFERENCES)[number]["id"];
|
|
205
|
+
|
|
206
|
+
export function WorkspaceSettings() {
|
|
207
|
+
const [enabled, setEnabled] = useState<Record<PreferenceID, boolean>>({
|
|
208
|
+
public: false,
|
|
209
|
+
guests: true,
|
|
210
|
+
sso: true,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<Container as="main" size="md">
|
|
215
|
+
<VStack gap="xl">
|
|
216
|
+
<VStack gap="xs">
|
|
217
|
+
<Heading as="h1" size="2xl">
|
|
218
|
+
Workspace settings
|
|
219
|
+
</Heading>
|
|
220
|
+
<Text fontSize="sm" color="muted">
|
|
221
|
+
Manage how the workspace behaves for everyone in it.
|
|
222
|
+
</Text>
|
|
223
|
+
</VStack>
|
|
224
|
+
|
|
225
|
+
<Card visual="outline" fullWidth>
|
|
226
|
+
<CardBody>
|
|
227
|
+
<VStack gap="md">
|
|
228
|
+
{PREFERENCES.map((preference, index) => (
|
|
229
|
+
<VStack key={preference.id} gap="md">
|
|
230
|
+
{index > 0 && <Separator />}
|
|
231
|
+
<HStack justify="between" align="center" gap="lg">
|
|
232
|
+
<VStack gap="xs">
|
|
233
|
+
<Text as="strong" fontSize="sm">
|
|
234
|
+
{preference.title}
|
|
235
|
+
</Text>
|
|
236
|
+
<Text fontSize="sm" color="muted">
|
|
237
|
+
{preference.description}
|
|
238
|
+
</Text>
|
|
239
|
+
</VStack>
|
|
240
|
+
<Switch
|
|
241
|
+
aria-label={preference.title}
|
|
242
|
+
checked={enabled[preference.id]}
|
|
243
|
+
onCheckedChange={(isOn) =>
|
|
244
|
+
setEnabled((current) => ({ ...current, [preference.id]: isOn }))
|
|
245
|
+
}
|
|
246
|
+
/>
|
|
247
|
+
</HStack>
|
|
248
|
+
</VStack>
|
|
249
|
+
))}
|
|
250
|
+
</VStack>
|
|
251
|
+
</CardBody>
|
|
252
|
+
</Card>
|
|
253
|
+
</VStack>
|
|
254
|
+
</Container>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
No raw layout or text elements are left: `Container` renders the `main` landmark, and every visual
|
|
260
|
+
decision is a prop with a token value.
|
|
261
|
+
|
|
262
|
+
## 11. Before you finish
|
|
263
|
+
|
|
264
|
+
- [ ] No flex or grid `div`s, no `h1`–`h6` / `p` / `span` with font styles, no 1px divider `div`s.
|
|
265
|
+
- [ ] No hex or `rgb()` colors, no pixel spacing, no `.beckui--*` classes.
|
|
266
|
+
- [ ] Every inline `style` uses tokens and has a `TODO (MAV-…)` naming the gap it covers.
|
|
267
|
+
- [ ] Local helpers exist only for markup used three or more times, and are built from Becket.
|
|
268
|
+
- [ ] Every control has an accessible name; status isn't shown by color alone.
|
|
269
|
+
- [ ] Theme is set at the app root; `index.css` is imported once.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@becket-ui/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Becket React component library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"files": [
|
|
27
|
-
"dist"
|
|
27
|
+
"dist",
|
|
28
|
+
"guides"
|
|
28
29
|
],
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
@@ -37,13 +38,13 @@
|
|
|
37
38
|
"access": "public"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"@becket-ui/tokens": "^0.
|
|
41
|
+
"@becket-ui/tokens": "^0.2.0",
|
|
41
42
|
"react": ">=19",
|
|
42
43
|
"react-dom": ">=19"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@becket-ui/a11y": "0.0.0",
|
|
46
|
-
"@becket-ui/tokens": "0.
|
|
47
|
+
"@becket-ui/tokens": "0.2.0",
|
|
47
48
|
"@pandacss/dev": "^1.12.1",
|
|
48
49
|
"@storybook/react": "^10.6.0",
|
|
49
50
|
"@storybook/react-vite": "^10.6.0",
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { render, screen } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
import { assertNoAxeViolations } from "@becket-ui/a11y";
|
|
6
|
-
import { Button } from "./Button";
|
|
7
|
-
describe("Button", () => {
|
|
8
|
-
it('defaults to type="button"', () => {
|
|
9
|
-
render(/* @__PURE__ */ jsx(Button, { children: "Save" }));
|
|
10
|
-
expect(screen.getByRole("button", { name: "Save" }).getAttribute("type")).toBe("button");
|
|
11
|
-
});
|
|
12
|
-
it('keeps an explicit type="submit"', () => {
|
|
13
|
-
render(/* @__PURE__ */ jsx(Button, { type: "submit", children: "Send" }));
|
|
14
|
-
expect(screen.getByRole("button", { name: "Send" }).getAttribute("type")).toBe("submit");
|
|
15
|
-
});
|
|
16
|
-
it("does not set type when as is not button", () => {
|
|
17
|
-
render(
|
|
18
|
-
/* @__PURE__ */ jsx(Button, { as: "a", href: "#save", children: "Save" })
|
|
19
|
-
);
|
|
20
|
-
expect(screen.getByRole("link", { name: "Save" }).hasAttribute("type")).toBe(false);
|
|
21
|
-
});
|
|
22
|
-
it("does not submit a wrapping form", async () => {
|
|
23
|
-
const onSubmit = vi.fn((event) => event.preventDefault());
|
|
24
|
-
const user = userEvent.setup();
|
|
25
|
-
render(
|
|
26
|
-
/* @__PURE__ */ jsx(
|
|
27
|
-
"form",
|
|
28
|
-
{
|
|
29
|
-
onSubmit: (event) => {
|
|
30
|
-
event.preventDefault();
|
|
31
|
-
onSubmit(event.nativeEvent);
|
|
32
|
-
},
|
|
33
|
-
children: /* @__PURE__ */ jsx(Button, { children: "Confirm" })
|
|
34
|
-
}
|
|
35
|
-
)
|
|
36
|
-
);
|
|
37
|
-
await user.click(screen.getByRole("button", { name: "Confirm" }));
|
|
38
|
-
expect(onSubmit).not.toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
it("has no axe violations on a named button", async () => {
|
|
41
|
-
const { container } = render(/* @__PURE__ */ jsx(Button, { children: "Save" }));
|
|
42
|
-
await assertNoAxeViolations(container);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
//# sourceMappingURL=Button.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Button.test.tsx"],"sourcesContent":["import { describe, expect, it, vi } from 'vitest';\nimport { render, screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { assertNoAxeViolations } from '@becket-ui/a11y';\n\nimport { Button } from './Button';\n\ndescribe('Button', () => {\n it('defaults to type=\"button\"', () => {\n render(<Button>Save</Button>);\n expect(screen.getByRole('button', { name: 'Save' }).getAttribute('type')).toBe('button');\n });\n\n it('keeps an explicit type=\"submit\"', () => {\n render(<Button type=\"submit\">Send</Button>);\n expect(screen.getByRole('button', { name: 'Send' }).getAttribute('type')).toBe('submit');\n });\n\n it('does not set type when as is not button', () => {\n render(\n <Button as=\"a\" href=\"#save\">\n Save\n </Button>,\n );\n expect(screen.getByRole('link', { name: 'Save' }).hasAttribute('type')).toBe(false);\n });\n\n it('does not submit a wrapping form', async () => {\n const onSubmit = vi.fn((event: SubmitEvent) => event.preventDefault());\n const user = userEvent.setup();\n render(\n <form\n onSubmit={(event) => {\n event.preventDefault();\n onSubmit(event.nativeEvent);\n }}\n >\n <Button>Confirm</Button>\n </form>,\n );\n\n await user.click(screen.getByRole('button', { name: 'Confirm' }));\n expect(onSubmit).not.toHaveBeenCalled();\n });\n\n it('has no axe violations on a named button', async () => {\n const { container } = render(<Button>Save</Button>);\n await assertNoAxeViolations(container);\n });\n});\n"],"mappings":"AASW;AATX,SAAS,UAAU,QAAQ,IAAI,UAAU;AACzC,SAAS,QAAQ,cAAc;AAC/B,OAAO,eAAe;AACtB,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AAEvB,SAAS,UAAU,MAAM;AACvB,KAAG,6BAA6B,MAAM;AACpC,WAAO,oBAAC,UAAO,kBAAI,CAAS;AAC5B,WAAO,OAAO,UAAU,UAAU,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,QAAQ;AAAA,EACzF,CAAC;AAED,KAAG,mCAAmC,MAAM;AAC1C,WAAO,oBAAC,UAAO,MAAK,UAAS,kBAAI,CAAS;AAC1C,WAAO,OAAO,UAAU,UAAU,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,QAAQ;AAAA,EACzF,CAAC;AAED,KAAG,2CAA2C,MAAM;AAClD;AAAA,MACE,oBAAC,UAAO,IAAG,KAAI,MAAK,SAAQ,kBAE5B;AAAA,IACF;AACA,WAAO,OAAO,UAAU,QAAQ,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,KAAK;AAAA,EACpF,CAAC;AAED,KAAG,mCAAmC,YAAY;AAChD,UAAM,WAAW,GAAG,GAAG,CAAC,UAAuB,MAAM,eAAe,CAAC;AACrE,UAAM,OAAO,UAAU,MAAM;AAC7B;AAAA,MACE;AAAA,QAAC;AAAA;AAAA,UACC,UAAU,CAAC,UAAU;AACnB,kBAAM,eAAe;AACrB,qBAAS,MAAM,WAAW;AAAA,UAC5B;AAAA,UAEA,8BAAC,UAAO,qBAAO;AAAA;AAAA,MACjB;AAAA,IACF;AAEA,UAAM,KAAK,MAAM,OAAO,UAAU,UAAU,EAAE,MAAM,UAAU,CAAC,CAAC;AAChE,WAAO,QAAQ,EAAE,IAAI,iBAAiB;AAAA,EACxC,CAAC;AAED,KAAG,2CAA2C,YAAY;AACxD,UAAM,EAAE,UAAU,IAAI,OAAO,oBAAC,UAAO,kBAAI,CAAS;AAClD,UAAM,sBAAsB,SAAS;AAAA,EACvC,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
import { assertNoAxeViolations } from "@becket-ui/a11y";
|
|
6
|
-
import { Button } from "./Button";
|
|
7
|
-
import { Dialog } from "./Dialog";
|
|
8
|
-
function ConfirmDialog({
|
|
9
|
-
open = true,
|
|
10
|
-
role = "dialog",
|
|
11
|
-
onOpenChange = () => {
|
|
12
|
-
},
|
|
13
|
-
ariaLabel
|
|
14
|
-
}) {
|
|
15
|
-
return /* @__PURE__ */ jsx(
|
|
16
|
-
Dialog,
|
|
17
|
-
{
|
|
18
|
-
open,
|
|
19
|
-
onOpenChange,
|
|
20
|
-
role,
|
|
21
|
-
title: ariaLabel ? void 0 : "Confirm",
|
|
22
|
-
"aria-label": ariaLabel,
|
|
23
|
-
footer: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24
|
-
/* @__PURE__ */ jsx(Button, { visual: "outline", onClick: () => onOpenChange(false), children: "Cancel" }),
|
|
25
|
-
/* @__PURE__ */ jsx(Button, { visual: "primary", onClick: () => onOpenChange(false), children: "Confirm" })
|
|
26
|
-
] }),
|
|
27
|
-
children: "Native dialog body."
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
describe("Dialog", () => {
|
|
32
|
-
it("points labelledby and describedby at rendered title and body", () => {
|
|
33
|
-
render(/* @__PURE__ */ jsx(ConfirmDialog, {}));
|
|
34
|
-
const dialog = screen.getByRole("dialog", { name: "Confirm" });
|
|
35
|
-
const labelledBy = dialog.getAttribute("aria-labelledby");
|
|
36
|
-
const describedBy = dialog.getAttribute("aria-describedby");
|
|
37
|
-
expect(document.getElementById(labelledBy)?.textContent).toBe("Confirm");
|
|
38
|
-
expect(document.getElementById(describedBy)?.textContent).toContain("Native dialog body");
|
|
39
|
-
});
|
|
40
|
-
it("omits labelledby when there is no title node", () => {
|
|
41
|
-
render(/* @__PURE__ */ jsx(ConfirmDialog, { ariaLabel: "Unnamed confirm" }));
|
|
42
|
-
const dialog = screen.getByRole("dialog", { name: "Unnamed confirm" });
|
|
43
|
-
expect(dialog.getAttribute("aria-labelledby")).toBeNull();
|
|
44
|
-
});
|
|
45
|
-
it("moves initial focus to Cancel, not Close", async () => {
|
|
46
|
-
render(/* @__PURE__ */ jsx(ConfirmDialog, {}));
|
|
47
|
-
await waitFor(() => {
|
|
48
|
-
expect(document.activeElement).toBe(screen.getByRole("button", { name: "Cancel" }));
|
|
49
|
-
});
|
|
50
|
-
expect(document.activeElement).not.toBe(screen.getByRole("button", { name: "Close" }));
|
|
51
|
-
});
|
|
52
|
-
it("tabs from the first footer action to Confirm", async () => {
|
|
53
|
-
const user = userEvent.setup();
|
|
54
|
-
render(/* @__PURE__ */ jsx(ConfirmDialog, {}));
|
|
55
|
-
await waitFor(() => {
|
|
56
|
-
expect(document.activeElement).toBe(screen.getByRole("button", { name: "Cancel" }));
|
|
57
|
-
});
|
|
58
|
-
await user.tab();
|
|
59
|
-
expect(document.activeElement).toBe(screen.getByRole("button", { name: "Confirm" }));
|
|
60
|
-
});
|
|
61
|
-
it("closes a dialog on backdrop click but not an alertdialog", () => {
|
|
62
|
-
const onDialog = vi.fn();
|
|
63
|
-
const { rerender } = render(/* @__PURE__ */ jsx(ConfirmDialog, { onOpenChange: onDialog }));
|
|
64
|
-
fireEvent.click(screen.getByRole("dialog", { name: "Confirm" }));
|
|
65
|
-
expect(onDialog).toHaveBeenCalledWith(false);
|
|
66
|
-
const onAlert = vi.fn();
|
|
67
|
-
rerender(/* @__PURE__ */ jsx(ConfirmDialog, { role: "alertdialog", onOpenChange: onAlert }));
|
|
68
|
-
fireEvent.click(screen.getByRole("alertdialog", { name: "Confirm" }));
|
|
69
|
-
expect(onAlert).not.toHaveBeenCalled();
|
|
70
|
-
});
|
|
71
|
-
it("lets Close aria-label be overridden", () => {
|
|
72
|
-
render(
|
|
73
|
-
/* @__PURE__ */ jsx(Dialog, { open: true, title: "Confirm", children: "Body" })
|
|
74
|
-
);
|
|
75
|
-
expect(screen.getByRole("button", { name: "Close" })).toBeTruthy();
|
|
76
|
-
});
|
|
77
|
-
it("closes on Escape via the native dialog close event", () => {
|
|
78
|
-
const onOpenChange = vi.fn();
|
|
79
|
-
render(/* @__PURE__ */ jsx(ConfirmDialog, { onOpenChange }));
|
|
80
|
-
fireEvent.keyDown(screen.getByRole("dialog", { name: "Confirm" }), { key: "Escape" });
|
|
81
|
-
fireEvent(screen.getByRole("dialog", { name: "Confirm" }), new Event("close", { bubbles: true }));
|
|
82
|
-
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
83
|
-
});
|
|
84
|
-
it("has no axe violations when open", async () => {
|
|
85
|
-
const { container } = render(/* @__PURE__ */ jsx(ConfirmDialog, {}));
|
|
86
|
-
await assertNoAxeViolations(container);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
//# sourceMappingURL=Dialog.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Dialog.test.tsx"],"sourcesContent":["import { describe, expect, it, vi } from 'vitest';\nimport { fireEvent, render, screen, waitFor } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { assertNoAxeViolations } from '@becket-ui/a11y';\n\nimport { Button } from './Button';\nimport { Dialog } from './Dialog';\n\nfunction ConfirmDialog({\n open = true,\n role = 'dialog' as 'dialog' | 'alertdialog',\n onOpenChange = () => {},\n ariaLabel,\n}: {\n open?: boolean;\n role?: 'dialog' | 'alertdialog';\n onOpenChange?: (open: boolean) => void;\n ariaLabel?: string;\n}) {\n return (\n <Dialog\n open={open}\n onOpenChange={onOpenChange}\n role={role}\n title={ariaLabel ? undefined : 'Confirm'}\n aria-label={ariaLabel}\n footer={\n <>\n <Button visual=\"outline\" onClick={() => onOpenChange(false)}>\n Cancel\n </Button>\n <Button visual=\"primary\" onClick={() => onOpenChange(false)}>\n Confirm\n </Button>\n </>\n }\n >\n Native dialog body.\n </Dialog>\n );\n}\n\ndescribe('Dialog', () => {\n it('points labelledby and describedby at rendered title and body', () => {\n render(<ConfirmDialog />);\n const dialog = screen.getByRole('dialog', { name: 'Confirm' });\n const labelledBy = dialog.getAttribute('aria-labelledby');\n const describedBy = dialog.getAttribute('aria-describedby');\n expect(document.getElementById(labelledBy as string)?.textContent).toBe('Confirm');\n expect(document.getElementById(describedBy as string)?.textContent).toContain('Native dialog body');\n });\n\n it('omits labelledby when there is no title node', () => {\n render(<ConfirmDialog ariaLabel=\"Unnamed confirm\" />);\n const dialog = screen.getByRole('dialog', { name: 'Unnamed confirm' });\n expect(dialog.getAttribute('aria-labelledby')).toBeNull();\n });\n\n it('moves initial focus to Cancel, not Close', async () => {\n render(<ConfirmDialog />);\n await waitFor(() => {\n expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Cancel' }));\n });\n expect(document.activeElement).not.toBe(screen.getByRole('button', { name: 'Close' }));\n });\n\n it('tabs from the first footer action to Confirm', async () => {\n const user = userEvent.setup();\n render(<ConfirmDialog />);\n await waitFor(() => {\n expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Cancel' }));\n });\n await user.tab();\n expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Confirm' }));\n });\n\n it('closes a dialog on backdrop click but not an alertdialog', () => {\n const onDialog = vi.fn();\n const { rerender } = render(<ConfirmDialog onOpenChange={onDialog} />);\n fireEvent.click(screen.getByRole('dialog', { name: 'Confirm' }));\n expect(onDialog).toHaveBeenCalledWith(false);\n\n const onAlert = vi.fn();\n rerender(<ConfirmDialog role=\"alertdialog\" onOpenChange={onAlert} />);\n fireEvent.click(screen.getByRole('alertdialog', { name: 'Confirm' }));\n expect(onAlert).not.toHaveBeenCalled();\n });\n\n it('lets Close aria-label be overridden', () => {\n render(\n <Dialog open title=\"Confirm\">\n Body\n </Dialog>,\n );\n expect(screen.getByRole('button', { name: 'Close' })).toBeTruthy();\n });\n\n it('closes on Escape via the native dialog close event', () => {\n const onOpenChange = vi.fn();\n render(<ConfirmDialog onOpenChange={onOpenChange} />);\n fireEvent.keyDown(screen.getByRole('dialog', { name: 'Confirm' }), { key: 'Escape' });\n fireEvent(screen.getByRole('dialog', { name: 'Confirm' }), new Event('close', { bubbles: true }));\n expect(onOpenChange).toHaveBeenCalledWith(false);\n });\n\n it('has no axe violations when open', async () => {\n const { container } = render(<ConfirmDialog />);\n await assertNoAxeViolations(container);\n });\n});\n"],"mappings":"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","names":[]}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
4
|
-
import { assertNoAxeViolations } from "@becket-ui/a11y";
|
|
5
|
-
import { Button } from "./Button";
|
|
6
|
-
import { Drawer } from "./Drawer";
|
|
7
|
-
function FiltersDrawer({
|
|
8
|
-
onOpenChange = () => {
|
|
9
|
-
},
|
|
10
|
-
role = "dialog"
|
|
11
|
-
}) {
|
|
12
|
-
return /* @__PURE__ */ jsx(
|
|
13
|
-
Drawer,
|
|
14
|
-
{
|
|
15
|
-
open: true,
|
|
16
|
-
role,
|
|
17
|
-
onOpenChange,
|
|
18
|
-
title: "Filters",
|
|
19
|
-
footer: /* @__PURE__ */ jsx(Button, { visual: "primary", onClick: () => onOpenChange(false), children: "Done" }),
|
|
20
|
-
children: "Same a11y as Dialog."
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
describe("Drawer", () => {
|
|
25
|
-
it("names the dialog from the title and describes it from the body", () => {
|
|
26
|
-
render(/* @__PURE__ */ jsx(FiltersDrawer, {}));
|
|
27
|
-
const dialog = screen.getByRole("dialog", { name: "Filters" });
|
|
28
|
-
const labelledBy = dialog.getAttribute("aria-labelledby");
|
|
29
|
-
const describedBy = dialog.getAttribute("aria-describedby");
|
|
30
|
-
expect(document.getElementById(labelledBy)?.textContent).toBe("Filters");
|
|
31
|
-
expect(document.getElementById(describedBy)?.textContent).toContain("Same a11y as Dialog");
|
|
32
|
-
});
|
|
33
|
-
it("moves initial focus to the footer action, not Close", async () => {
|
|
34
|
-
render(/* @__PURE__ */ jsx(FiltersDrawer, {}));
|
|
35
|
-
await waitFor(() => {
|
|
36
|
-
expect(document.activeElement).toBe(screen.getByRole("button", { name: "Done" }));
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
it("does not light-dismiss an alertdialog", () => {
|
|
40
|
-
const onOpenChange = vi.fn();
|
|
41
|
-
render(/* @__PURE__ */ jsx(FiltersDrawer, { role: "alertdialog", onOpenChange }));
|
|
42
|
-
fireEvent.click(screen.getByRole("alertdialog", { name: "Filters" }));
|
|
43
|
-
expect(onOpenChange).not.toHaveBeenCalled();
|
|
44
|
-
});
|
|
45
|
-
it("has no axe violations when open", async () => {
|
|
46
|
-
const { container } = render(/* @__PURE__ */ jsx(FiltersDrawer, {}));
|
|
47
|
-
await assertNoAxeViolations(container);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
//# sourceMappingURL=Drawer.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Drawer.test.tsx"],"sourcesContent":["import { describe, expect, it, vi } from 'vitest';\nimport { fireEvent, render, screen, waitFor } from '@testing-library/react';\nimport { assertNoAxeViolations } from '@becket-ui/a11y';\n\nimport { Button } from './Button';\nimport { Drawer } from './Drawer';\n\nfunction FiltersDrawer({\n onOpenChange = () => {},\n role = 'dialog' as 'dialog' | 'alertdialog',\n}: {\n onOpenChange?: (open: boolean) => void;\n role?: 'dialog' | 'alertdialog';\n}) {\n return (\n <Drawer\n open\n role={role}\n onOpenChange={onOpenChange}\n title=\"Filters\"\n footer={\n <Button visual=\"primary\" onClick={() => onOpenChange(false)}>\n Done\n </Button>\n }\n >\n Same a11y as Dialog.\n </Drawer>\n );\n}\n\ndescribe('Drawer', () => {\n it('names the dialog from the title and describes it from the body', () => {\n render(<FiltersDrawer />);\n const dialog = screen.getByRole('dialog', { name: 'Filters' });\n const labelledBy = dialog.getAttribute('aria-labelledby');\n const describedBy = dialog.getAttribute('aria-describedby');\n expect(document.getElementById(labelledBy as string)?.textContent).toBe('Filters');\n expect(document.getElementById(describedBy as string)?.textContent).toContain('Same a11y as Dialog');\n });\n\n it('moves initial focus to the footer action, not Close', async () => {\n render(<FiltersDrawer />);\n await waitFor(() => {\n expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Done' }));\n });\n });\n\n it('does not light-dismiss an alertdialog', () => {\n const onOpenChange = vi.fn();\n render(<FiltersDrawer role=\"alertdialog\" onOpenChange={onOpenChange} />);\n fireEvent.click(screen.getByRole('alertdialog', { name: 'Filters' }));\n expect(onOpenChange).not.toHaveBeenCalled();\n });\n\n it('has no axe violations when open', async () => {\n const { container } = render(<FiltersDrawer />);\n await assertNoAxeViolations(container);\n });\n});\n"],"mappings":"AAqBQ;AArBR,SAAS,UAAU,QAAQ,IAAI,UAAU;AACzC,SAAS,WAAW,QAAQ,QAAQ,eAAe;AACnD,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AACvB,SAAS,cAAc;AAEvB,SAAS,cAAc;AAAA,EACrB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,OAAO;AACT,GAGG;AACD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAI;AAAA,MACJ;AAAA,MACA;AAAA,MACA,OAAM;AAAA,MACN,QACE,oBAAC,UAAO,QAAO,WAAU,SAAS,MAAM,aAAa,KAAK,GAAG,kBAE7D;AAAA,MAEH;AAAA;AAAA,EAED;AAEJ;AAEA,SAAS,UAAU,MAAM;AACvB,KAAG,kEAAkE,MAAM;AACzE,WAAO,oBAAC,iBAAc,CAAE;AACxB,UAAM,SAAS,OAAO,UAAU,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7D,UAAM,aAAa,OAAO,aAAa,iBAAiB;AACxD,UAAM,cAAc,OAAO,aAAa,kBAAkB;AAC1D,WAAO,SAAS,eAAe,UAAoB,GAAG,WAAW,EAAE,KAAK,SAAS;AACjF,WAAO,SAAS,eAAe,WAAqB,GAAG,WAAW,EAAE,UAAU,qBAAqB;AAAA,EACrG,CAAC;AAED,KAAG,uDAAuD,YAAY;AACpE,WAAO,oBAAC,iBAAc,CAAE;AACxB,UAAM,QAAQ,MAAM;AAClB,aAAO,SAAS,aAAa,EAAE,KAAK,OAAO,UAAU,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC;AAAA,IAClF,CAAC;AAAA,EACH,CAAC;AAED,KAAG,yCAAyC,MAAM;AAChD,UAAM,eAAe,GAAG,GAAG;AAC3B,WAAO,oBAAC,iBAAc,MAAK,eAAc,cAA4B,CAAE;AACvE,cAAU,MAAM,OAAO,UAAU,eAAe,EAAE,MAAM,UAAU,CAAC,CAAC;AACpE,WAAO,YAAY,EAAE,IAAI,iBAAiB;AAAA,EAC5C,CAAC;AAED,KAAG,mCAAmC,YAAY;AAChD,UAAM,EAAE,UAAU,IAAI,OAAO,oBAAC,iBAAc,CAAE;AAC9C,UAAM,sBAAsB,SAAS;AAAA,EACvC,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { render, screen } from "@testing-library/react";
|
|
4
|
-
import { Field } from "./Field";
|
|
5
|
-
import { Radio, RadioGroup } from "./Radio";
|
|
6
|
-
import { TextField } from "./TextField";
|
|
7
|
-
describe("Field describedBy", () => {
|
|
8
|
-
it("omits aria-describedby when TextField has no helper", () => {
|
|
9
|
-
render(/* @__PURE__ */ jsx(TextField, { label: "Offset" }));
|
|
10
|
-
expect(screen.getByLabelText("Offset").getAttribute("aria-describedby")).toBeNull();
|
|
11
|
-
});
|
|
12
|
-
it("points at FieldHelper when valid with helperText", () => {
|
|
13
|
-
render(/* @__PURE__ */ jsx(TextField, { label: "Offset", helperText: "Optional hint" }));
|
|
14
|
-
const describedBy = screen.getByLabelText("Offset").getAttribute("aria-describedby");
|
|
15
|
-
expect(describedBy).toBeTruthy();
|
|
16
|
-
expect(document.getElementById(describedBy)?.textContent).toBe("Optional hint");
|
|
17
|
-
});
|
|
18
|
-
it("points at FieldError when invalid with helperText", () => {
|
|
19
|
-
render(/* @__PURE__ */ jsx(TextField, { label: "Email", invalid: true, helperText: "Enter a valid email address" }));
|
|
20
|
-
const describedBy = screen.getByLabelText("Email").getAttribute("aria-describedby");
|
|
21
|
-
expect(describedBy).toBeTruthy();
|
|
22
|
-
const node = document.getElementById(describedBy);
|
|
23
|
-
expect(node?.getAttribute("role")).toBe("alert");
|
|
24
|
-
expect(node?.textContent).toBe("Enter a valid email address");
|
|
25
|
-
});
|
|
26
|
-
it("does not give RadioGroup a dangling describedBy", () => {
|
|
27
|
-
render(
|
|
28
|
-
/* @__PURE__ */ jsx(Field, { children: /* @__PURE__ */ jsx(RadioGroup, { legend: "Side", children: /* @__PURE__ */ jsx(Radio, { value: "yes", label: "Yes" }) }) })
|
|
29
|
-
);
|
|
30
|
-
expect(screen.getByRole("group", { name: "Side" }).getAttribute("aria-describedby")).toBeNull();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
//# sourceMappingURL=Field.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Field.test.tsx"],"sourcesContent":["import { describe, expect, it } from 'vitest';\nimport { render, screen } from '@testing-library/react';\n\nimport { Field } from './Field';\nimport { Radio, RadioGroup } from './Radio';\nimport { TextField } from './TextField';\n\ndescribe('Field describedBy', () => {\n it('omits aria-describedby when TextField has no helper', () => {\n render(<TextField label=\"Offset\" />);\n expect(screen.getByLabelText('Offset').getAttribute('aria-describedby')).toBeNull();\n });\n\n it('points at FieldHelper when valid with helperText', () => {\n render(<TextField label=\"Offset\" helperText=\"Optional hint\" />);\n const describedBy = screen.getByLabelText('Offset').getAttribute('aria-describedby');\n expect(describedBy).toBeTruthy();\n expect(document.getElementById(describedBy as string)?.textContent).toBe('Optional hint');\n });\n\n it('points at FieldError when invalid with helperText', () => {\n render(<TextField label=\"Email\" invalid helperText=\"Enter a valid email address\" />);\n const describedBy = screen.getByLabelText('Email').getAttribute('aria-describedby');\n expect(describedBy).toBeTruthy();\n const node = document.getElementById(describedBy as string);\n expect(node?.getAttribute('role')).toBe('alert');\n expect(node?.textContent).toBe('Enter a valid email address');\n });\n\n it('does not give RadioGroup a dangling describedBy', () => {\n render(\n <Field>\n <RadioGroup legend=\"Side\">\n <Radio value=\"yes\" label=\"Yes\" />\n </RadioGroup>\n </Field>,\n );\n expect(screen.getByRole('group', { name: 'Side' }).getAttribute('aria-describedby')).toBeNull();\n });\n});\n"],"mappings":"AASW;AATX,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAS,QAAQ,cAAc;AAE/B,SAAS,aAAa;AACtB,SAAS,OAAO,kBAAkB;AAClC,SAAS,iBAAiB;AAE1B,SAAS,qBAAqB,MAAM;AAClC,KAAG,uDAAuD,MAAM;AAC9D,WAAO,oBAAC,aAAU,OAAM,UAAS,CAAE;AACnC,WAAO,OAAO,eAAe,QAAQ,EAAE,aAAa,kBAAkB,CAAC,EAAE,SAAS;AAAA,EACpF,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,WAAO,oBAAC,aAAU,OAAM,UAAS,YAAW,iBAAgB,CAAE;AAC9D,UAAM,cAAc,OAAO,eAAe,QAAQ,EAAE,aAAa,kBAAkB;AACnF,WAAO,WAAW,EAAE,WAAW;AAC/B,WAAO,SAAS,eAAe,WAAqB,GAAG,WAAW,EAAE,KAAK,eAAe;AAAA,EAC1F,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,WAAO,oBAAC,aAAU,OAAM,SAAQ,SAAO,MAAC,YAAW,+BAA8B,CAAE;AACnF,UAAM,cAAc,OAAO,eAAe,OAAO,EAAE,aAAa,kBAAkB;AAClF,WAAO,WAAW,EAAE,WAAW;AAC/B,UAAM,OAAO,SAAS,eAAe,WAAqB;AAC1D,WAAO,MAAM,aAAa,MAAM,CAAC,EAAE,KAAK,OAAO;AAC/C,WAAO,MAAM,WAAW,EAAE,KAAK,6BAA6B;AAAA,EAC9D,CAAC;AAED,KAAG,mDAAmD,MAAM;AAC1D;AAAA,MACE,oBAAC,SACC,8BAAC,cAAW,QAAO,QACjB,8BAAC,SAAM,OAAM,OAAM,OAAM,OAAM,GACjC,GACF;AAAA,IACF;AACA,WAAO,OAAO,UAAU,SAAS,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,kBAAkB,CAAC,EAAE,SAAS;AAAA,EAChG,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { render, screen, waitFor } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
import { assertNoAxeViolations } from "@becket-ui/a11y";
|
|
6
|
-
import { Menu, MenuItem } from "./Menu";
|
|
7
|
-
describe("Menu", () => {
|
|
8
|
-
it("exposes expanded and haspopup on the trigger", async () => {
|
|
9
|
-
const user = userEvent.setup();
|
|
10
|
-
render(
|
|
11
|
-
/* @__PURE__ */ jsxs(Menu, { label: "Actions", children: [
|
|
12
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Edit" }),
|
|
13
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Duplicate" })
|
|
14
|
-
] })
|
|
15
|
-
);
|
|
16
|
-
const trigger = screen.getByText("Actions");
|
|
17
|
-
expect(trigger.tagName).toBe("SUMMARY");
|
|
18
|
-
expect(trigger.getAttribute("aria-haspopup")).toBe("menu");
|
|
19
|
-
expect(trigger.getAttribute("aria-expanded")).toBe("false");
|
|
20
|
-
await user.click(trigger);
|
|
21
|
-
expect(trigger.getAttribute("aria-expanded")).toBe("true");
|
|
22
|
-
});
|
|
23
|
-
it("keeps open items out of Tab order", async () => {
|
|
24
|
-
const user = userEvent.setup();
|
|
25
|
-
render(
|
|
26
|
-
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
27
|
-
/* @__PURE__ */ jsx("button", { type: "button", children: "Before" }),
|
|
28
|
-
/* @__PURE__ */ jsxs(Menu, { label: "Actions", children: [
|
|
29
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Edit" }),
|
|
30
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Duplicate" })
|
|
31
|
-
] }),
|
|
32
|
-
/* @__PURE__ */ jsx("button", { type: "button", children: "After" })
|
|
33
|
-
] })
|
|
34
|
-
);
|
|
35
|
-
await user.click(screen.getByText("Actions"));
|
|
36
|
-
expect(screen.getByRole("menuitem", { name: "Edit" }).getAttribute("tabindex")).toBe("-1");
|
|
37
|
-
expect(screen.getByRole("menuitem", { name: "Duplicate" }).getAttribute("tabindex")).toBe("-1");
|
|
38
|
-
await waitFor(() => {
|
|
39
|
-
expect(document.activeElement).toBe(screen.getByRole("menuitem", { name: "Edit" }));
|
|
40
|
-
});
|
|
41
|
-
await user.tab();
|
|
42
|
-
expect(document.activeElement).toBe(screen.getByRole("button", { name: "After" }));
|
|
43
|
-
});
|
|
44
|
-
it("moves between items with arrows", async () => {
|
|
45
|
-
const user = userEvent.setup();
|
|
46
|
-
render(
|
|
47
|
-
/* @__PURE__ */ jsxs(Menu, { label: "Actions", children: [
|
|
48
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Edit" }),
|
|
49
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Duplicate" })
|
|
50
|
-
] })
|
|
51
|
-
);
|
|
52
|
-
await user.click(screen.getByText("Actions"));
|
|
53
|
-
await waitFor(() => {
|
|
54
|
-
expect(document.activeElement).toBe(screen.getByRole("menuitem", { name: "Edit" }));
|
|
55
|
-
});
|
|
56
|
-
await user.keyboard("{ArrowDown}");
|
|
57
|
-
expect(document.activeElement).toBe(screen.getByRole("menuitem", { name: "Duplicate" }));
|
|
58
|
-
});
|
|
59
|
-
it("has no axe violations", async () => {
|
|
60
|
-
const { container } = render(
|
|
61
|
-
/* @__PURE__ */ jsxs(Menu, { label: "Actions", children: [
|
|
62
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Edit" }),
|
|
63
|
-
/* @__PURE__ */ jsx(MenuItem, { children: "Duplicate" })
|
|
64
|
-
] })
|
|
65
|
-
);
|
|
66
|
-
await assertNoAxeViolations(container);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
//# sourceMappingURL=Menu.test.js.map
|