Skip to content

Commit 29926c7

Browse files
zernoniaclaude
andauthored
fix: regressions found in the 2.11.0 release review (#2991)
* fix(DismissableLayer): render on a server without a document The Escape listener's target getter read `ownerDocument.value.defaultView`, which throws when there is no `document`. Any layer rendered on the server outside a portal (open, force-mounted, or kept mounted) failed to render. Adds an SSR test that runs in the `node` environment, since the jsdom-based SSR tests always have a document. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Toast): keep attrs on title and description, and keyboard close on action A template comment above the root of `ToastTitle` / `ToastDescription` made the root a fragment, so `class`, `id` and other attrs were dropped in production builds. `ToastAction` no longer passed the click event to `onClose`, so activating it by keyboard did not move focus to the viewport or reset the pause flag. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Calendar): keep the date type and time when clamping to min/max PageUp / PageDown / Home / End replaced the target with a copy of `minValue` / `maxValue`. With a bound of another type or time, no cell matched it, so focus was lost and the placeholder lost its time. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Menu): stop rendering graceDuration as an attribute on sub triggers Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(RovingFocus): rebind keydown when an asChild item replaces its element Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(TagsInput): keep focus in the input when Tab adds a tag Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(Drawer): add generated meta for DrawerVirtualKeyboardProvider Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test: add Vitest browser mode for real-browser tests (#2992) jsdom cannot represent trusted key events, native focus order, form submission or layout, so some regressions only show in a real browser. `*.browser.test.ts` files now run in headless Chromium through Playwright with their own config, so the jsdom suite and its commands are unchanged. Covers TagsInput (Enter / Tab in a form), Toast (keyboard activation), Calendar (PageUp / PageDown), Dialog (focus trap, outside pointer events) and Popover (positioning, dismissal). CI runs them in a new job. Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 1156c2e commit 29926c7

31 files changed

Lines changed: 750 additions & 27 deletions

‎.github/workflows/build.yaml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ jobs:
5757
path: packages/core/coverage
5858
retention-days: 7
5959

60+
test-browser:
61+
needs: build
62+
runs-on: ubuntu-latest
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@v7
67+
68+
- name: Setup (Install node & pnpm)
69+
uses: ./.github/actions/setup
70+
71+
- name: Install Chromium
72+
run: pnpm --filter reka-ui exec playwright install --with-deps chromium
73+
74+
- name: Test (browser)
75+
run: pnpm --filter reka-ui test:browser
76+
6077
size:
6178
needs: build
6279
runs-on: ubuntu-latest

‎CLAUDE.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Vue 3 headless component library. pnpm monorepo. Node ≥ 22, pnpm 10.
55
## Commands (from repo root)
66
- Install: `pnpm i`
77
- Test (one-shot): `pnpm --filter reka-ui exec vitest run [path]` (`pnpm test` = watch mode — avoid in automation)
8+
- Browser tests (real Chromium, `*.browser.test.ts`): `pnpm test:browser` (first run: `pnpm --filter reka-ui exec playwright install chromium`)
89
- Coverage: `pnpm --filter reka-ui test:coverage`
910
- Type-check: `pnpm --filter reka-ui type-check`
1011
- Lint: `pnpm lint` (fix: `pnpm lint:fix`)
@@ -22,6 +23,7 @@ Vue 3 headless component library. pnpm monorepo. Node ≥ 22, pnpm 10.
2223
## Conventions
2324
- Context: `createContext('<Component>')` → `[inject, provide]`; `*Root.vue` provides, descendants inject.
2425
- Rendering: `Primitive` with `as` / `asChild`; expose refs via `useForwardExpose()`.
26+
- Browser tests: colocated `*.browser.test.ts`, vitest browser mode + Playwright; use `userEvent` from `vitest/browser` (trusted events). For behaviour jsdom can't represent: native focus order, form submission, key defaults, layout/positioning.
2527
- Tests: colocated `*.test.ts`, vitest + jsdom + `@testing-library/vue` + `vitest-axe` (axe check expected for new components); jsdom quirks handled in `packages/core/vitest.setup.ts`.
2628
- Commits: Conventional Commits, scope = component family (`fix(Dialog): …`); commitlint enforces; lint-staged runs `eslint --fix` (lints JSON/MD/YAML too — intentional).
2729

‎CONTRIBUTING.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ All commands run from the repo root.
6767
| Tests (watch) | `pnpm test` |
6868
| Tests (one-shot) | `pnpm --filter reka-ui exec vitest run [path]` |
6969
| Test coverage | `pnpm --filter reka-ui test:coverage` |
70+
| Browser tests | `pnpm test:browser` |
7071
| Lint / auto-fix | `pnpm lint` / `pnpm lint:fix` |
7172
| Stories | `pnpm story:dev` |
7273
| Docs dev | `pnpm --filter reka-ui build && pnpm docs:install && pnpm docs:dev` |
@@ -116,6 +117,13 @@ complete example to read alongside this section.
116117
don't need to repeat that per test.
117118
- New components and composables should ship with colocated tests, including an
118119
axe check for anything that renders.
120+
- **Browser tests** (`<Name>.browser.test.ts`, also colocated) run in headless
121+
Chromium through Vitest browser mode and Playwright. Use them for behaviour
122+
jsdom cannot represent: native focus order (`Tab`), form submission, the
123+
default action of a key press, and layout or positioning. Drive them with
124+
`userEvent` from `vitest/browser`, which sends trusted events. Run
125+
`pnpm test:browser`; the first time, install the browser with
126+
`pnpm --filter reka-ui exec playwright install chromium`.
119127

120128
## Documentation
121129

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- This file was automatically generated. Do not edit it manually -->
2+

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"docs:sponsors": "pnpm --filter docs docs:sponsors",
2222
"prepare": "pnpm simple-git-hooks",
2323
"test:run": "pnpm --filter reka-ui test:run",
24+
"test:browser": "pnpm --filter reka-ui test:browser",
2425
"test": "pnpm --filter reka-ui test",
2526
"test-update": "pnpm --filter reka-ui test-update",
2627
"lint": "eslint .",

‎packages/core/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"test:run": "vitest run",
8282
"test": "vitest",
8383
"test:coverage": "vitest run --coverage",
84+
"test:browser": "vitest run --config vitest.browser.config.ts",
8485
"test-update": "vitest -u",
8586
"pub:release": "npm publish --access public --provenance",
8687
"size": "size-limit"
@@ -113,11 +114,13 @@
113114
"@types/jsdom": "^30.0.0",
114115
"@types/node": "^24.0.13",
115116
"@vitejs/plugin-vue": "^6.0.9",
117+
"@vitest/browser-playwright": "^5.0.3",
116118
"@vitest/coverage-istanbul": "^5.0.3",
117119
"@vue/server-renderer": "^3.5.43",
118120
"@vue/test-utils": "^2.5.1",
119121
"@vue/tsconfig": "^0.9.1",
120122
"jsdom": "^30.1.1",
123+
"playwright": "^1.63.0",
121124
"size-limit": "^12.0.1",
122125
"tsdown": "^0.12.9",
123126
"vite": "^8.3.1",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { CalendarDate, CalendarDateTime } from '@internationalized/date'
2+
import { mount } from '@vue/test-utils'
3+
import { describe, expect, it } from 'vitest'
4+
import { userEvent } from 'vitest/browser'
5+
import Calendar from './story/_Calendar.vue'
6+
7+
function activeTestId() {
8+
return document.activeElement?.getAttribute('data-testid')
9+
}
10+
11+
describe('given a Calendar, in a real browser', () => {
12+
it('moves focus by a month with PageUp / PageDown and by a week with arrow keys', async () => {
13+
mount(Calendar, {
14+
attachTo: document.body,
15+
props: { calendarProps: { placeholder: new CalendarDate(2024, 3, 20) } },
16+
})
17+
document.querySelector<HTMLElement>('[data-testid="date-3-20"]')!.focus()
18+
19+
await userEvent.keyboard('{PageUp}')
20+
await expect.poll(activeTestId).toBe('date-2-20')
21+
22+
await userEvent.keyboard('{PageDown}{ArrowDown}')
23+
await expect.poll(activeTestId).toBe('date-3-27')
24+
})
25+
26+
it('keeps focus on the min day when PageUp is clamped and minValue has no time', async () => {
27+
mount(Calendar, {
28+
attachTo: document.body,
29+
props: {
30+
calendarProps: {
31+
placeholder: new CalendarDateTime(2024, 3, 20, 10, 30),
32+
minValue: new CalendarDate(2024, 2, 25),
33+
},
34+
},
35+
})
36+
document.querySelector<HTMLElement>('[data-testid="date-3-20"]')!.focus()
37+
38+
await userEvent.keyboard('{PageUp}')
39+
40+
await expect.poll(activeTestId).toBe('date-2-25')
41+
expect(document.activeElement?.getAttribute('data-value')).toBe('2024-02-25T10:30:00')
42+
})
43+
})

‎packages/core/src/Calendar/Calendar.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,25 @@ describe('calendar', async () => {
997997
expect(getByTestId('date-1-5')).toHaveFocus()
998998
})
999999

1000+
it.each([
1001+
['has no time', new CalendarDate(2024, 2, 25)],
1002+
['has a different time', new CalendarDateTime(2024, 2, 25, 0, 0)],
1003+
])('page up keeps focus and the time when minValue %s', async (_, minValue) => {
1004+
const { getByTestId, user } = setup({
1005+
calendarProps: {
1006+
placeholder: new CalendarDateTime(2024, 3, 20, 10, 30),
1007+
minValue,
1008+
},
1009+
})
1010+
1011+
getByTestId('date-3-20').focus()
1012+
await user.keyboard(kbd.PAGE_UP)
1013+
1014+
expect(getByTestId('heading')).toHaveTextContent('February 2024')
1015+
expect(getByTestId('date-2-25')).toHaveFocus()
1016+
expect(getByTestId('date-2-25')).toHaveAttribute('data-value', '2024-02-25T10:30:00')
1017+
})
1018+
10001019
it('page down respects maxValue boundary', async () => {
10011020
const { getByTestId, user } = setup({
10021021
calendarProps: {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { mount } from '@vue/test-utils'
2+
import { describe, expect, it, vi } from 'vitest'
3+
import { userEvent } from 'vitest/browser'
4+
import { defineComponent, h } from 'vue'
5+
import { DialogClose, DialogContent, DialogOverlay, DialogPortal, DialogRoot, DialogTitle, DialogTrigger } from '.'
6+
7+
function mountDialog() {
8+
const onOutsideClick = vi.fn()
9+
const Fixture = defineComponent({
10+
setup() {
11+
return () => h('div', [
12+
h('button', { 'data-testid': 'outside', 'onClick': onOutsideClick }, 'Outside'),
13+
h(DialogRoot, null, () => [
14+
h(DialogTrigger, { 'data-testid': 'trigger' }, () => 'Open'),
15+
h(DialogPortal, null, () => [
16+
h(DialogOverlay, { style: 'position: fixed; inset: 0;' }),
17+
h(DialogContent, {
18+
'aria-describedby': undefined,
19+
'data-testid': 'content',
20+
'style': 'position: fixed; top: 100px; left: 100px; width: 200px; background: white;',
21+
}, () => [
22+
h(DialogTitle, null, () => 'Title'),
23+
h('input', { 'data-testid': 'first' }),
24+
h(DialogClose, { 'data-testid': 'close' }, () => 'Close'),
25+
]),
26+
]),
27+
]),
28+
])
29+
},
30+
})
31+
mount(Fixture, { attachTo: document.body })
32+
const get = (id: string) => document.querySelector<HTMLElement>(`[data-testid="${id}"]`)
33+
return { get, onOutsideClick }
34+
}
35+
36+
describe('given a modal Dialog, in a real browser', () => {
37+
it('traps Tab focus, closes on Escape and returns focus to the trigger', async () => {
38+
const { get } = mountDialog()
39+
40+
await userEvent.click(get('trigger')!)
41+
await expect.poll(() => document.activeElement).toBe(get('first'))
42+
43+
await userEvent.keyboard('{Tab}')
44+
expect(document.activeElement).toBe(get('close'))
45+
// Tab from the last element wraps to the first instead of leaving the dialog.
46+
await userEvent.keyboard('{Tab}')
47+
expect(document.activeElement).toBe(get('first'))
48+
await userEvent.keyboard('{Shift>}{Tab}{/Shift}')
49+
expect(document.activeElement).toBe(get('close'))
50+
51+
await userEvent.keyboard('{Escape}')
52+
await expect.poll(() => get('content')).toBeNull()
53+
expect(document.activeElement).toBe(get('trigger'))
54+
})
55+
56+
it('blocks pointer interaction outside, and restores it after closing', async () => {
57+
const { get, onOutsideClick } = mountDialog()
58+
59+
await userEvent.click(get('trigger')!)
60+
await expect.poll(() => get('content')).not.toBeNull()
61+
expect(getComputedStyle(document.body).pointerEvents).toBe('none')
62+
// Hit testing is real here: the point over the outside button resolves to the overlay.
63+
const rect = get('outside')!.getBoundingClientRect()
64+
const hit = document.elementFromPoint(rect.left + 2, rect.top + 2)
65+
expect(get('outside')!.contains(hit)).toBe(false)
66+
67+
await userEvent.keyboard('{Escape}')
68+
await expect.poll(() => get('content')).toBeNull()
69+
expect(getComputedStyle(document.body).pointerEvents).not.toBe('none')
70+
71+
await userEvent.click(get('outside')!)
72+
expect(onOutsideClick).toHaveBeenCalledTimes(1)
73+
})
74+
})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// @vitest-environment node
2+
import { renderToString } from '@vue/server-renderer'
3+
import { describe, expect, it } from 'vitest'
4+
import { createSSRApp, h } from 'vue'
5+
import { DialogContent, DialogRoot, DialogTitle } from '@/Dialog'
6+
import { PopoverContent, PopoverRoot, PopoverTrigger } from '@/Popover'
7+
8+
// Runs without jsdom: on a real server there is no `document` or `window`, which
9+
// the jsdom-based SSR tests cannot show.
10+
describe('given a DismissableLayer rendered on the server', () => {
11+
it('has no DOM globals', () => {
12+
expect(typeof document).toBe('undefined')
13+
expect(typeof window).toBe('undefined')
14+
})
15+
16+
it('renders an open Dialog outside a portal', async () => {
17+
const html = await renderToString(createSSRApp({
18+
render: () => h(DialogRoot, { defaultOpen: true }, () =>
19+
h(DialogContent, { 'aria-describedby': undefined }, () => h(DialogTitle, () => 'Title'))),
20+
}))
21+
22+
expect(html).toContain('role="dialog"')
23+
})
24+
25+
it('renders a closed Dialog with force-mounted content', async () => {
26+
const html = await renderToString(createSSRApp({
27+
render: () => h(DialogRoot, () =>
28+
h(DialogContent, { 'forceMount': true, 'aria-describedby': undefined }, () => h(DialogTitle, () => 'Title'))),
29+
}))
30+
31+
expect(html).toContain('role="dialog"')
32+
})
33+
34+
it('renders an open Popover', async () => {
35+
const html = await renderToString(createSSRApp({
36+
render: () => h(PopoverRoot, { defaultOpen: true }, () => [
37+
h(PopoverTrigger, () => 'Open'),
38+
h(PopoverContent, () => 'Content'),
39+
]),
40+
}))
41+
42+
expect(html).toContain('Content')
43+
})
44+
})

0 commit comments

Comments
 (0)