Repository navigation
Commit ea6de74
fix(ui): a dialog's focus trap no longer pulls Tab back when a tooltip closes on blur (#34091)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Sy653R4fA2ArwDP1QvFqq9)_
Fixes #33980
Clause-②: no
Metadata-protocol: none
Claim by `domain:ui#1`, card-thread session
`session_01ADHkmPwoJquHrWGDjT1P4r`.
## 维护者速读
- 改了什么:给弹窗焦点陷阱(Radix
`FocusScope`)的补丁加一段:只有「上一个获得焦点的元素」真的不在弹窗里了,才把焦点拉回弹窗本身。导入向导里 #33960
加的局部绕法(把 tooltip 挪出弹窗)随之撤掉。
- 为什么改:弹窗里一个带内联 tooltip 的按钮,按 Tab 离开时 tooltip
被卸载,陷阱误判为「焦点元素被删」,把焦点拉回弹窗,键盘用户出不去。除导入向导外,实测「管理视图」对话框也中招:Tab 过不了第一行的 Pin
按钮,其余视图、Done、Close 都到不了。修在陷阱上,所有弹窗一次修好。
- 风险与回滚:只改补丁里一个判断条件,焦点元素真被删除时仍拉回弹窗(单测对照钉住)。改动面是所有 Dialog / Sheet /
AlertDialog 的焦点处理;回滚即 revert(会同时带回导入向导的问题,因为局部绕法已撤)。
- 先看:`patches/@radix-ui__react-focus-scope.patch`(新增的 handleMutations
两行),`ui/packages/components/src/__tests__/dialog-popover-focus-scope.test.tsx`(新
describe),`ui/e2e/manage-views-keyboard-tab-order.spec.ts`。
- 两分钟验证:`pnpm --dir ui exec playwright test
e2e/manage-views-keyboard-tab-order.spec.ts
e2e/import-wizard-keyboard-tab-order.spec.ts --project=chromium`,预期 6
passed。
- 需要你做的:无,席位落地。
## What changes
- **`patches/@radix-ui__react-focus-scope.patch`** (the file
`pnpm-workspace.yaml`'s `patchedDependencies` applies) gains a second
hunk in `dist/index.js` and `dist/index.mjs`: the trapped scope's
`MutationObserver` callback returns early when the last focused element
is still inside the container. Stock radix focuses the container
whenever a node under it is removed while focus sits on `body`; between
the blur and the focus of a native Tab focus does sit on `body`, so a
node that a blur unmounts (an inline tooltip closing under its trigger)
pulled focus back to the container. The callback now acts only on the
case it exists for: the focused element, or an ancestor of it, was
itself removed. The earlier stack-race hunk is unchanged.
- **`ui/patches/@radix-ui__react-focus-scope.patch`** gets the same
bytes. It is an unreferenced copy (nothing reads it;
`pnpm-workspace.yaml` names the root file), kept identical rather than
left to drift; deleting it is not this card. **`ui/patches/README.md`**:
the entry now describes both halves, its Tracking/Upstream rows name the
second, and Remove-when requires every regression case green with the
patch removed.
- **`pnpm-lock.yaml`**: the patch hash for
`@radix-ui/react-focus-scope@1.1.16` (7 lines, from `pnpm install`).
- **`ui/packages/plugin-grid/src/ImportWizard.tsx`**: #33960's local
`createPortal` of the Save-current reason tooltip is removed (`git apply
-R` of that hunk); the tooltip mounts inline again, and Tab still leaves
it (spec below).
- **Changesets**: new `.changeset/33980-focus-trap-blur-unmount.md`
(`@object-ui/console`, `@objectstack/console`, `@object-ui/plugin-grid`:
patch). **DELIBERATE CORRECTION** of the pending
`.changeset/33862-import-wizard-save-reason-tab-trap.md`: its last
sentence said "The tooltip now renders outside the dialog, so Tab and
Shift+Tab walk every control in order…", which this PR makes false; it
now reads "The dialog's focus trap no longer reads that removal as focus
lost, so Tab and Shift+Tab walk every control in order and the reason is
still read out when the wrapper is focused." `check-empty-changeset` is
red on that file by design.
### Why A (the focus-scope patch) and not B (portal `TooltipContent`)
Measured first, on `origin/main` `fb79d47c`: which inline-tooltip
triggers sit inside a modal dialog. Statically, 35 non-test files under
`ui/packages` name `TooltipContent`; six of them also render a Dialog /
Sheet / AlertDialog (ImportWizard, ManageViewsDialog,
MarketplacePackagePage, MarketplaceRowActions, StudioDesignSurface, the
Shadcn sidebar). Measured in Chromium with real Tab presses (Vite bundle
from `src/`, no stylesheet):
| Site | Before (fb79d47) | After |
|---|---|---|
| Import wizard, Save-current reason (with #33960's portal removed) |
trapped (the #33960 spec's ablation leg, and below) | all 8 stops |
| Manage Views dialog, each row's Pin / Set-as-default button
(`ObjectView` wires both) | trapped: search, drag, `All`, Pin,
**dialog**, search… | all 12 stops |
| A generic Dialog with a focusable tooltip trigger between two buttons
| trapped: a, b, **dialog**, a… | a, b, c, Close |
Not measured: `StudioDesignSurface` (a tooltip in an inspector its
selection Sheet may hold), tooltips in views a record drawer may host,
and `DisabledReasonTrigger` when metadata places a disabled action
inside a modal. A covers them whatever they turn out to be.
Why "no stylesheet" is the production case: the Console's `index.css`
leaves `@plugin 'tailwindcss-animate'` commented out, so
`data-[state=closed]:animate-out` has no rule and a closing tooltip
unmounts at once, inside the blur→focus gap. With an exit animation the
unmount waits for `animationend` and nothing traps (measured on the
generic probe: a, b, c, Close) — which is why this hides in some setups.
- **A** fixes the trap's heuristic, so every blur-driven unmount under a
modal is covered, not only tooltips, in every dialog at once; the repo
already patches this exact package and version for another focus race,
with a README entry and a removal condition.
- **B was not taken**: it closes only the tooltip half (any other node a
blur removes still traps); `ui/packages/components/src/ui/tooltip.tsx`
is a Shadcn-synced file (ui/AGENTS.md #7), tracked from shadcn's
`default` style, which does not portal, so B is a local divergence to
declare in `ui/scripts/shadcn-local-patches.mjs`; and it moves every
tooltip in the app out of its subtree into `body`, a DOM change for
every tooltip to fix a defect that only exists under a focus trap.
## Tests
- **Unit,
`ui/packages/components/src/__tests__/dialog-popover-focus-scope.test.tsx`**
(the shared harness of the existing patch; new top-level `describe`): a
trapped scope whose trigger drops a sibling node on blur — after
`blur()` focus is not on the container (red on stock); CONTROL —
removing the focused element itself still focuses the container (green
either way). A scripted `blur()` puts focus on `body` before the
observer callback runs, so this unit case can go red in happy-dom,
unlike a `user-event` Tab walk.
- **New e2e, `ui/e2e/manage-views-keyboard-tab-order.spec.ts`** (Build &
E2E UI, chromium; the harness of #33960's spec): the real
`ManageViewsDialog` bundled from source, native Tab and Shift+Tab over
two editable views (12 stops, past both Pins and Set-as-default) and a
CONTROL of two read-only views (no tooltip trigger, 7 stops).
- **`ui/e2e/import-wizard-keyboard-tab-order.spec.ts`**: green with the
local portal removed. Forced test edit: its header sentence "The reason
tooltip is now portalled out of the dialog…" became false and now names
the trap patch; no assertion changed.
- **Ablation** (fix committed first): the patch's guard line deleted
from the installed `dist/index.mjs` (marker `/* ablated */`, guard count
1 → 0, blob `4dfa11db5c8c` → `a97219dd468f`).
- unit: the new case red, the control and the 3 existing cases green;
- e2e: Manage Views editable case red (`…, manage-views-pin-all, dialog,
manage-views-search, …`), import wizard nothing-mapped and tooltip cases
red (`…, reason:import-template-save-btn, dialog, …`), the 3 controls
green.
- Restore proven both times: blob back to `4dfa11db5c8c`, which is the
post-image blob the patch itself names for `dist/index.mjs`; guard count
1. (`scripts/ablation-replace.mjs` refused to certify the restore of a
path git does not track, so the restore was done by hand and proven by
hash.)
<details><summary>Local runs (head 279bded)</summary>
```
playwright e2e/manage-views-keyboard-tab-order.spec.ts e2e/import-wizard-keyboard-tab-order.spec.ts --project=chromium
head 279bded: 6 passed
ablation (guard deleted): 3 failed (manage-views editable; import-wizard nothing-mapped; import-wizard tooltip), 3 passed (controls)
vitest packages/components/src/__tests__/dialog-popover-focus-scope.test.tsx
head: 5 passed
ablation: 1 failed (a node a blur unmounts...), 4 passed
vitest packages/components/ packages/plugin-grid/ packages/plugin-view/ (lock VERDICT command-exit 0)
Test Files 827 passed | 1 skipped (828); Tests 7755 passed | 24 skipped (7779)
type-check:e2e, @object-ui/components type-check, @object-ui/plugin-grid type-check (lock VERDICT command-exit 0)
Chromium probes on origin/main fb79d47 (before the patch; Vite bundle from src, no stylesheet):
generic Dialog + tooltip trigger: a, b, dialog, a, b
same, with an exit-animation rule: a, b, c, Close, a
ManageViewsDialog (2 views): search, drag-all, All, pin-all, dialog, search, ...
after the patch:
generic: a, b, c, Close, a
ManageViewsDialog: search, drag-all, All, pin-all, actions-all, drag-mine, Mine, pin-mine, default-mine, actions-mine, done, Close, search
```
</details>
## Acceptance notes
- `ui/patches/README.md`'s header still says patches are "declared in
the root `package.json`"; they are declared in `pnpm-workspace.yaml`.
Doc drift, outside this card's file surface; noted, not fixed.
- No upstream radix issue is known for the mutation-handler half; the
README says so rather than citing one.
## Verification
Local, on head `279bded8` (merge base `fb79d47c`; `origin/main`
`63db7240`, none of its 10 commits touches these files): `node
scripts/pm/dispatch-gates.mjs --commands` derived 52; `--ran` with the
exit codes: 52 derived, 51 run, 1 NOT-MEASURED, 0 UNRUN.
- `check-empty-changeset --base origin/main` exits 1 **by design**: the
DELIBERATE CORRECTION of
`.changeset/33862-import-wizard-save-reason-tab-trap.md` above, for the
seat's record.
- `check:dual-build-cjs-loads`: NOT MEASURED locally (exit 3,
PREREQUISITE NOT MET: it reads every package's `dist/`, and only the
closures these tests need were built). It is derived from the lockfile
line only; CI's Lint & Repo Gates runs it on a full build.
- Also run: `ui` `check:new-line-citations` (0 new);
`check-governed-merges --branch HEAD`: NOT governed, 0 of 10 paths, 477
changed lines.
<details><summary>Derived gates, each exit code</summary>
```
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-dts-emitted.mjs --self-test :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 1
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-osv-exemptions.mjs :: exit 0
node scripts/check-osv-exemptions.mjs --self-test :: exit 0
node scripts/check-sdui-manifest.mjs :: exit 0
node scripts/check-sdui-manifest.mjs --self-test :: exit 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/osv-base-relative.mjs --self-test :: exit 0
node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --dir ui exec vitest run scripts/ :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0
pnpm check:changeset-fixed :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:dts-closure :: exit 0
pnpm check:dual-build-cjs-loads :: exit 3
pnpm check:engine-double-contract :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:lean-entry-closure :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:override-consistency :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:skill-identifier-liveness :: exit 0
pnpm check:sourcemap-no-sources-content :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:vendor-export-contract-resolve :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
```
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmPwoJquHrWGDjT1P4r)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent b4eea88 commit ea6de74
10 files changed
Lines changed: 438 additions & 39 deletions
File tree
- .changeset
- patches
- ui
- e2e
- packages
- components/src/__tests__
- plugin-grid/src
- patches
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
6 | 15 | | |
7 | 16 | | |
8 | 17 | | |
| |||
13 | 22 | | |
14 | 23 | | |
15 | 24 | | |
16 | | - | |
| 25 | + | |
17 | 26 | | |
18 | 27 | | |
19 | 28 | | |
| |||
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
27 | | - | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
30 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
31 | 49 | | |
32 | 50 | | |
33 | 51 | | |
| |||
38 | 56 | | |
39 | 57 | | |
40 | 58 | | |
41 | | - | |
| 59 | + | |
42 | 60 | | |
43 | 61 | | |
44 | 62 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
0 commit comments