`@effect/ui-kit` (Effect-TS/ui): `Dialog`: focus moved inside right after opening jumps to the first field a frame later
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Written with Claude Code for @magoz, from an app we're building on Effect UI.
What version of Effect is running?
| Package | Version |
|---|---|
@effect/ui-kit, @effect/ui (Effect-TS/ui) |
0.0.0 snapshot at 87a704b where we hit it; reproduced on main at dec1ca9 |
effect |
4.1.6 |
Refiled from Effect-TS/ui#551, as Effect-TS/ui#593 asks while the code moves here. Dialog.ts is unchanged on main since we filed it.
What steps can reproduce the bug?
A frame after a Dialog opens, opening runs focusFirst(from) (Dialog.ts#L869-L878). focusFirst returns early only when from, the element focused when the dialog opened, is inside the popup (Dialog.ts#L671-L692). Focus that moved inside during that frame isn't checked, so the dialog moves it to the first tabbable element anyway. The docs say "Focus already inside the popup stays".
We hit it as a flaky Playwright test in a sheet (a Drawer) with three fields: fill focuses a field and then inserts the text over CDP. When the opening frame landed between the two (a cold dev server, a busy main thread), focus jumped to the first field and the second field's text went into it. A quick user clicking a later field right after opening loses focus the same way.
In Effect-TS/ui's packages/ui-kit/test/DialogDocument.test.ts, with its Page, config, container, popovers, byId and tick helpers, holding frames back as a busy page does:
it.effect("focus moved inside after the dialog shows, before its opening frame, stays where it went", () =>
Effect.gen(function*() {
yield* popovers
const app = yield* container
const held: Array<FrameRequestCallback> = []
const requestFrame = window.requestAnimationFrame
yield* Effect.acquireRelease(
Effect.sync(() => {
window.requestAnimationFrame = (callback) => held.push(callback)
}),
() => Effect.sync(() => (window.requestAnimationFrame = requestFrame))
)
yield* BrowserHost.mountEffect(Page, config({}), app)
yield* tick
byId("second").focus()
window.requestAnimationFrame = requestFrame
for (const callback of held.splice(0)) callback(performance.now())
yield* tick
assert.strictEqual(document.activeElement?.id, "second")
}))
What is the expected behavior?
Focus moved inside the popup after it showed and before its opening frame stays where it went, as focus already inside does.
What do you see instead?
On dec1ca9, with the test from the branch below:
AssertionError: expected 'first' to equal 'second'
Additional information
The fix we tried: the dialog notes a focusin inside the popup that isn't the kit's own handOff (a new handingOff() in internal/layers.ts), reset when opening runs, so the browser's own focusing on show still counts as not moved; focusFirst then keeps focus that moved in. initialFocus: false, touch opens and marked initial focus behave as before.
The fix, based on 22128c6 with the regression test as the first commit (fails before, passes after), the doc line and a changeset, is on magoz/ui@dialog-focus-moved-inside (diff). Issues are preferred over pull requests during the move, so we're linking it instead. On that base pnpm check and the ui-kit suite (588 tests) pass; pnpm lint reports only a format difference in packages/ui-native/test/NativeHost.test.ts that was already there. Our app waits for the sheet's first-field focus in that test.
- Ngôn ngữ chính
- TypeScript
- Star
- 16.7k
- Fork
- 808
- Merge trung bình
- 21 giờ 22 phút
- Pull request đã merge (30 ngày)
- 486
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Effect-TS/effect
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`@effect/ui-native` (Effect-TS/ui): `kit/VirtualList` `list` part widens `R` to `any`, poisoning enclosing componentsCó thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#11097 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`@effect/ui-native` (Effect-TS/ui): Controlled `input` rejected-edit restore never calls `host.commit()`Có thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#11096 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Effect-TS/effect
Issue tương tự
-
check:failed streams:edit
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
iptv-org/iptv#60585 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Critical path skips a child span that ends exactly when the next one startsCó thể đã có người làm @Piyush4801 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jaegertracing/jaeger-ui#4865 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
anthropics/claude-code#112972 ·
-
Type: Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày