`@effect/ui-kit` (Effect-TS/ui): `Popover`: a generated trigger id changes on each render of its Dialog, so the popup loses its anchor

Đang mở Phù hợp với người mới
#11,088 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
accessibility, frontend

Hướng nghiên cứu

Đọc packages/ui-kit/src/Popover.ts, đặc biệt là phần tạo ID của trigger gần dòng 1071 và 1272, cùng selector của trigger đang hoạt động gần dòng 1060–1062. Tái hiện bằng cách bật hoặc tắt một control bên trong popover đang mở, sau đó đóng rồi mở lại popover. Giữ ID trigger được tạo ổn định qua các lần render dialog; hoàn thành khi popup vẫn được neo và trigger giữ aria-expanded="true" mỗi lần mở.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

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, reproduced on main at dec1ca9
effect 4.1.7
What steps can reproduce the bug?
  1. A Popover whose trigger has no id of the consumer's (so the kit generates one), and whose popup holds a control that re-renders the popover's inner Dialog on its own, e.g. a Switch that changes the popup's content.
  2. Open the popover and toggle the switch. Close it, and open it again.
What is the expected behavior?

The popup stays anchored to its trigger on every open, and the trigger keeps aria-expanded="true" while it's open.

What do you see instead?

After the first re-render the popup is placed at the viewport's top-left (--anchor-width: 0px), and the trigger has no aria-expanded. It happens again on every reopen.

Additional information

The trigger's generated id comes from a counter declared in the Popover's parts (Popover.ts#L1071) but incremented inside the child Dialog's parts (Popover.ts#L1272):

const key = idOf(options.element) ?? p.id("trigger", triggers++)

The dialog's parts run on every render of the dialog, also when the popover's own parts don't run (a transition frame, or a re-render the popup's content causes). So the count carries over between runs and the trigger becomes …-trigger-1, then -2. The popover still positions against the id from the open (triggerSelector = idSelector(active), Popover.ts#L1060-L1062), which no element has any more.

A fix that works for us (a local patch): count per run of the dialog's parts, by moving let triggers = 0 from the popover's parts to the start of parts: (dialog) => { … }. Ids stay stable across re-renders as long as triggers are drawn in the same order, which is how Dialog and Menu count theirs. A sturdier form for triggers drawn conditionally or reordered would key the id on the element's .key() when it has one.

Menu, PreviewCard, Dialog and Drawer count their triggers within their own parts and have no child whose parts rerun alone, so they aren't affected.

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Effect-TS/effect

Tất cả issue của Effect-TS/effect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.