You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Owner focus set in onOpenChange(false) is lost in controlled dialogs and on a popover outside click #442
An owner who moves focus inside onOpenChange(false) loses that focus move in two cases. These were found while fixing the same problem for CCommandPalette's onAction (#420), and each case now has a strict-xfail e2e test.
Controlled CDialog, CAlertDialog and CDrawer. Close the popup with Escape, the close button, or (for CAlertDialog) the cancel or action button. Focus then ends on the trigger, not on the element the owner focused. This happens whether the owner focuses before or after setting open = false in the same callback.
In controlled mode the component calls onOpenChange(false) before it closes (requestOpen in cdialog/cdialog.py notifies and returns). The owner's focus() therefore runs while the modal still makes the rest of the page inert, so the browser ignores it. When the owner's open = false is applied, the shared dialog controller returns focus to the trigger.
Uncontrolled mode closes first and then notifies, and there the owner's focus is kept.
CPopover outside click, controlled and uncontrolled. Focus ends on body. The popover closes on pointerdown (_anchored_layer.py), so onOpenChange(false) runs before the browser's own mousedown focus step, which then moves focus to body. With Escape, the owner's focus is kept.
CContextMenu keeps the owner's focus in all six cases tested.
Options
Controlled dialogs. After a controlled close applies, run any focus the owner asked for. Or skip the return focus to the trigger when focus already moved outside the dialog. Since the browser ignores focus() on an inert element, the owner cannot move focus inside the callback today, so the fix probably needs a documented way to name the element that should get focus on close.
CPopover outside click. Leave focus where the pointer put it. Then document that an owner who wants to move focus on an outside click does it after the pointer event, for example in a requestAnimationFrame. Or delay the notification until after the mousedown default action.
Done when
The strict-xfail tests named test_owner_focus_move_in_on_open_change_survives_* in the cdialog, calert_dialog, cdrawer and cpopover e2e suites pass, and their xfail marks are removed.
Each component's api.md says when onOpenChange(false) runs relative to the close and to focus return.
Parked for after 0.7.0. The proposed design (a finalFocus(reason) prop shared by CDialog, CAlertDialog, CDrawer, CPopover and the palette's onOpenChange) is approved. When this is picked up, the strict xfail tests that define "done" may be rewritten to test finalFocus instead of a plain focus() inside the callback.
Activity
JuroOravec commentedon Oct 27, 2026
Parked for after 0.7.0. The proposed design (a
finalFocus(reason)prop shared by CDialog, CAlertDialog, CDrawer, CPopover and the palette'sonOpenChange) is approved. When this is picked up, the strict xfail tests that define "done" may be rewritten to testfinalFocusinstead of a plainfocus()inside the callback.fix(ui): run a closing palette command's onAction after the close (#420)