Define focus restoration for controlled dialogs
維護者通常 1 天內回覆
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 35/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
研究方向
首先檢查 16 個受控的 Dialog 根,包括 NPM 基準套件選擇器、管理員角色移除對話框以及 design-system 範例。將它們的 opener 配置與共用的基於 Radix 的 Dialog 進行比較,並在待決定策解決後定義 contract。完成的標準是:已實作選定的焦點還原行為,且瀏覽器層級的回歸測試驗證在 Escape 和透過關閉按鈕關閉後焦點會返回。
由索引模型根據 Issue 內容生成。
描述
Evidence
Merged PR #1205 moved shipping overlays onto the shared Radix-backed Dialog, but the controlled-dialog call sites do not register an opener with DialogTrigger.
Current source has 16 controlled Dialog roots and no shipping DialogTrigger usage. Radix stores the trigger in context.triggerRef, then its modal onCloseAutoFocus handler prevents the browser default and calls context.triggerRef.current?.focus(). Without a registered trigger, that ref is null, so keyboard focus is not restored to the control that opened the dialog.
This is straightforward for colocated single openers, such as the NPM baseline package picker. It is not one mechanical change for every caller:
- Some dialogs are controlled by an opener in a parent component.
- The admin role removal dialog has one dynamic opener per table row.
- Some design-system examples currently keep their opener outside the
Dialogroot.
Repeated title, body, keyword, and open-PR searches found no existing owner. Issue #775 tracks unrelated empty-name, label, landmark, and skip-navigation findings.
Expected impact
Closing a dialog should return keyboard and assistive-technology users to the control that opened it. Falling back to the document body loses their place and makes repeated actions harder.
Proposed direction
Adopt one explicit controlled-dialog focus contract:
- Require
DialogTrigger asChildfor dialogs with one colocated opener. - Add a typed shared API for external or dynamic openers, such as an explicit restore-focus ref or a narrowly exposed Radix close-auto-focus callback.
- Add a browser-level regression test that opens a dialog, closes it with Escape and the close button, and verifies focus returns to the actual opener.
Alternatives and tradeoffs
- Requiring
DialogTriggereverywhere keeps the shared API smallest, but dynamic table-row openers would need dialog state and content moved per row or another structural change. - Restoring the previously active element automatically inside
DialogContentreduces call-site work, but it changes every dialog and can restore focus to a stale or unrelated node when opening is indirect. - Exposing only
onCloseAutoFocusmatches Radix directly, but every caller must repeat the same focus logic and the shared primitive cannot enforce consistency.
Decision needed
@tannerlinsley, should the shared controlled-dialog contract support both DialogTrigger for colocated openers and an explicit restore-focus ref for external or dynamic openers, or should every dialog be restructured so one DialogTrigger always owns the opener?
Source: #1205
- 主要語言
- TypeScript
- 星號
- 1.1k
- 分支
- 405
- 平均合併
- 5 小時 36 分鐘
- 30 天內合併 PR
- 56
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/tanstack.com 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
TanStack/tanstack.com#1362 ·
維護者通常 1 天內回覆
-
Checkbox in dropdown doesn't scroll with items可能已有人在做 @6TELOIV 於 13 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 92/100
TanStack/tanstack.com#1304 ·
維護者通常 1 天內回覆
-
"bundle report" link navigates to 404 on Markdown docs可能已有人在做 @lukonik 於 43 天前認領。 未關閉source-audit
難度 1/5 1 小時以內 新手友好度 84/100
TanStack/tanstack.com#1195 ·
維護者通常 1 天內回覆
-
source-audit
難度 2/5 1-3 小時 新手友好度 68/100
TanStack/tanstack.com#1194 · 2 則留言 ·
維護者通常 1 天內回覆
-
source-audit
難度 2/5 1-3 小時 新手友好度 72/100
TanStack/tanstack.com#1177 · 1 則留言 ·
維護者通常 1 天內回覆
查看 TanStack/tanstack.com 的全部 Issue
相似的 Issue
-
status: needs-triage
難度 2/5 1-3 小時 新手友好度 83/100
a2ui-project/a2ui#3158 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
hemilabs/ui-monorepo#2475 ·
維護者通常 1 天內回覆
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難度 1/5 1 小時以內 新手友好度 82/100
lingdojo/kana-dojo#32279 · 1 則留言 · 5 個 reaction ·
維護者通常 1 天內回覆
-
code-quality refactoring
難度 2/5 1-3 小時 新手友好度 77/100
github/gh-aw-firewall#9879 ·
維護者通常 1 天內回覆
-
[Bug]: Arrow-key cursor movement in combined diff view doesn't scroll to keep the cursor visible未關閉os:macos
難度 2/5 1-3 小時 新手友好度 64/100
維護者通常 1 天內回覆