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
Overlays: dismiss causes and focus_on_open on owned chains #326
A popover can't be dismissed on "outside press and Escape" only.DismissOn offers Default (which includes focus leaving and window blur), EscOnly and Never, and on_dismiss isn't told why it fired. A popover opened on a screenshot run's first frame closes at once. Proposal: DismissOn::Outside (outside press + Escape), or on_dismiss_with(|app, cause|).
No code yet. This is written against main 584e09e. The places in core:
src/overlay.rs: DismissOn and its outside/esc/focus_out predicates;
src/dismiss.rs: dismissals, which finds each dismissal with a crate-internal Cause;
src/overlay_input.rs: judge, which runs the on_dismiss handlers, and opening_focus;
src/overlay_chain.rs: dismiss_on and on_dismiss;
src/builder.rs: NodeHandle::focus_on_open;
src/pipeline.rs: OpenFocus.
1. Dismiss causes
Today:DismissOn has three variants:
Default: a press outside, Esc, focus leaving, and the window losing focus;
EscOnly;
Never.
The library already knows why it dismisses. dismiss::Cause is Outside | Esc | Cancel | FocusOut | WindowBlur | Exclusive | AnchorGone, but it's crate-internal, and judge drops it before calling the handler.
Probable root cause of the consumer's report. A screenshot run's window often starts without OS focus, so egui-winit sends WindowFocused(false) early. The WindowBlur rule then dismisses any popover already drawn: "a popover opened on the first frame closes at once". I still need to confirm this with a test. If it holds, it's a bug worth fixing whatever the API: a window that never had focus while the overlay was open hasn't lost it. The fix is for WindowBlur to dismiss only an overlay that was drawn while the window had focus. It's small, in dismissals plus one per-overlay flag kept on the overlay stack.
API: both proposals, since they answer different needs.
pubenumDismissOn{#[default]Default,// outside press, Esc, focus out, window blurOutside,// NEW: outside press and Esc onlyEscOnly,Never,}#[non_exhaustive]pubenumDismissed{// public: the crate-internal Cause, less CancelOutside,Esc,FocusOut,WindowBlur,Exclusive,// another overlay that takes the screen openedAnchorGone,// the overlay's anchor isn't in the frame}implOverlayChain{pubfnon_dismiss(self,then:implFnOnce(&mutA) + 'static) -> Self;// unchangedpubfnon_dismiss_with(self,then:implFnOnce(&mutA,Dismissed) + 'static) -> Self;// NEW}
DismissOn::Outside is a policy: what may dismiss at all. It belongs in the declaration, so an app doesn't have to re-open an overlay it didn't want closed (which would also flash its motion and move focus).
on_dismiss_with is information: an app that closes on every cause but logs or animates differently, or one that wants Escape to revert edits and outside presses to keep them. Only one of the two handlers is kept, the last one set.
Cancel isn't public. When Escape is answered by the overlay's cancel button, the button's handler runs instead of on_dismiss, as today.
Exclusive stays only for Default. The rule in exclusive() that a menu closes when another overlay opens keeps its dismiss_on == DismissOn::Default guard.
Changes in core:
the predicates in overlay.rs gain Outside: outside() and esc() true, focus_out() false;
blur's dismisses_on_focus_loss follows focus_out;
DismissFn<A> becomes Box<dyn FnOnce(&mut A, Dismissed)>, with on_dismiss wrapping its handler to ignore the cause. That keeps one handler type, so mounts' lift and the owned chains' plumbing change in one place;
judge passes found.cause through, as does nav::navigate's dismissal, which closes a menu from its navigation keys (a new Dismissed::Keys; that's a question below).
Owned chains that wrap an overlay (select, dropdown menu, popover, dialog, combobox) gain dismiss_on and on_dismiss_with where they already expose on_dismiss or an open/close handler. Exactly which chains is listed in the PR.
Tests, through the real draw path:
each cause reaches on_dismiss_with;
Outside ignores focus leaving and a window blur, and still closes on an outside press and on Escape;
a popover open on the first frame of a window without focus stays open (the blur fix).
2. .focus_on_open() on the owned chains
Today:
NodeHandle::focus_on_open marks a node (OpenFocus::Here).
When its overlay first enters focus, opening_focus picks the first marked node, if it registered a focusable widget, and otherwise the overlay's first focusable. Two marked nodes report FocusOnOpenTwice.
The menu item chain has its own focus_on_open.
The other owned chains have none, because the focusable widget is an inner node the caller can't reach: a stepper's field leaf, a slider's thumb, a text field's leaf.
Why focus_on_appear doesn't stand in for it: inside an overlay, a control's focus_on_appear requests focus during the draw. But judge runs at the end of the same draw and requests the overlay's opening focus, and the later request wins. So today an owned control inside an overlay can't take focus as the overlay opens. That's the consumer's gap.
API: one method with the same name and meaning as NodeHandle's, on every owned chain whose control takes focus:
Each chain marks the node that holds its focusable widget: the button's own node, the stepper's field leaf, the slider's thumb, the text field's leaf, the select's trigger, and so on. That node is the one each chain's Autofocus already targets, so the mapping is known per control, and it's encoded once per control.
Stage 2 (the shared Options and its traits) is the breaking tag, and it has eight open questions for you. Waiting would tie this small, concrete gap to that larger decision.
One crate-internal piece, FocusRequest { autofocus: Autofocus, on_open: bool } (or an enum, if you rule out "both"; see below), with a single apply(handle) that marks the node and runs the autofocus. Each chain holds one field of it.
Which chains get it first is a question below. All of them now is about twelve one-liners; the controls the consumer named is fewer.
Mutually exclusive?focus_on_open and focus_on_appear on one control are both meaningful only if the control can appear without its overlay opening, which happens when a control is added to an already-open overlay. A single enum, Autofocus::{Never, OnAppear(Select), OnChange(..), OnOverlayOpen}, makes "both" unrepresentable, per the engineering rules on mutually exclusive modes. I recommend the enum.focus_on_open sets OnOverlayOpen.
Tests:
a popover holding a button and then a stepper marked focus_on_open: as the popover opens from the keyboard, the stepper's field has focus, not the button;
a menu opened with the pointer still focuses nothing, as Radix does;
two marked controls report FocusOnOpenTwice.
Questions for the user, with my recommendations
The blur fix: should a window blur dismiss only an overlay that was shown while the window had focus? This would fix the first-frame close whatever else is chosen. Recommend yes, as its own commit, with a test first.
Both DismissOn::Outside and on_dismiss_with, or one?Recommend both: one is policy, the other information.
The cause type's name:Dismissed or DismissCause? Recommend Dismissed (|app, why: Dismissed|).
A menu its navigation keys close (nav::navigate returns overlays to dismiss; the PR will list exactly which keys): its own cause, Dismissed::Keys, or folded into Esc? Recommend its own cause, so an app can tell keyboard navigation out of a menu from a cancel.
Dismissal: both DismissOn::Outside (an outside press or Escape only) and on_dismiss_with(|app, why|), with a public #[non_exhaustive] Dismissed { Outside, Esc, FocusOut, WindowBlur, Exclusive, AnchorGone, Keys }. on_dismiss wraps it and ignores the cause.
Coordination note from the #372/#21 dialog work (core C1), so the two dismissal changes meet cleanly:
C1 adds ButtonChain::dismisses(): after its own handler, the button dismisses its overlay through on_dismiss. In dismiss.rs this is a new crate-internal Cause::Closed, found in dismissals like the others (a per-Layer flag set from the buttons pressed this pass), so the dismissal path stays single. judge treats it like any non-Cancel cause.
For Dismissed: that cause needs a public variant when on_dismiss_with lands. I suggest Dismissed::Closed ("a button marked dismisses() was pressed: the dialog's × or a Cancel with no handler"). Dismissed is #[non_exhaustive], so whichever PR lands second adds the variant and the mapping; it's one match arm.
focus_on_open on owned chains:alert_dialog wants first focus on Cancel. Until ButtonChain::focus_on_open() lands from this issue, the dialog relies on build order (Cancel is the first focusable of a field-less alert dialog, and the × is never built in one). When yours lands I'll switch the footer's Cancel to it in a one-line follow-up; I'm not adding a focus_on_open to ButtonChain myself, so nothing collides.
Activity
samitbasu commentedon Nov 18, 2026
Design note: overlays (two items)
No code yet. This is written against main 584e09e. The places in core:
src/overlay.rs:DismissOnand itsoutside/esc/focus_outpredicates;src/dismiss.rs:dismissals, which finds each dismissal with a crate-internalCause;src/overlay_input.rs:judge, which runs theon_dismisshandlers, andopening_focus;src/overlay_chain.rs:dismiss_onandon_dismiss;src/builder.rs:NodeHandle::focus_on_open;src/pipeline.rs:OpenFocus.1. Dismiss causes
Today:
DismissOnhas three variants:Default: a press outside, Esc, focus leaving, and the window losing focus;EscOnly;Never.The library already knows why it dismisses.
dismiss::CauseisOutside | Esc | Cancel | FocusOut | WindowBlur | Exclusive | AnchorGone, but it's crate-internal, andjudgedrops it before calling the handler.Probable root cause of the consumer's report. A screenshot run's window often starts without OS focus, so egui-winit sends
WindowFocused(false)early. TheWindowBlurrule then dismisses any popover already drawn: "a popover opened on the first frame closes at once". I still need to confirm this with a test. If it holds, it's a bug worth fixing whatever the API: a window that never had focus while the overlay was open hasn't lost it. The fix is forWindowBlurto dismiss only an overlay that was drawn while the window had focus. It's small, indismissalsplus one per-overlay flag kept on the overlay stack.API: both proposals, since they answer different needs.
DismissOn::Outsideis a policy: what may dismiss at all. It belongs in the declaration, so an app doesn't have to re-open an overlay it didn't want closed (which would also flash its motion and move focus).on_dismiss_withis information: an app that closes on every cause but logs or animates differently, or one that wants Escape to revert edits and outside presses to keep them. Only one of the two handlers is kept, the last one set.Cancelisn't public. When Escape is answered by the overlay's cancel button, the button's handler runs instead ofon_dismiss, as today.Exclusivestays only forDefault. The rule inexclusive()that a menu closes when another overlay opens keeps itsdismiss_on == DismissOn::Defaultguard.overlay.rsgainOutside:outside()andesc()true,focus_out()false;dismisses_on_focus_lossfollowsfocus_out;DismissFn<A>becomesBox<dyn FnOnce(&mut A, Dismissed)>, withon_dismisswrapping its handler to ignore the cause. That keeps one handler type, so mounts'liftand the owned chains' plumbing change in one place;judgepassesfound.causethrough, as doesnav::navigate's dismissal, which closes a menu from its navigation keys (a newDismissed::Keys; that's a question below).dismiss_onandon_dismiss_withwhere they already exposeon_dismissor an open/close handler. Exactly which chains is listed in the PR.on_dismiss_with;Outsideignores focus leaving and a window blur, and still closes on an outside press and on Escape;2.
.focus_on_open()on the owned chainsToday:
NodeHandle::focus_on_openmarks a node (OpenFocus::Here).opening_focuspicks the first marked node, if it registered a focusable widget, and otherwise the overlay's first focusable. Two marked nodes reportFocusOnOpenTwice.focus_on_open.Why
focus_on_appeardoesn't stand in for it: inside an overlay, a control'sfocus_on_appearrequests focus during the draw. Butjudgeruns at the end of the same draw and requests the overlay's opening focus, and the later request wins. So today an owned control inside an overlay can't take focus as the overlay opens. That's the consumer's gap.API: one method with the same name and meaning as
NodeHandle's, on every owned chain whose control takes focus:Each chain marks the node that holds its focusable widget: the button's own node, the stepper's field leaf, the slider's thumb, the text field's leaf, the select's trigger, and so on. That node is the one each chain's
Autofocusalready targets, so the mapping is known per control, and it's encoded once per control.How it fits #315, and whether to wait:
Focustrait for the owned chains, with provided methods over a sharedOptionsvalue.focus_on_openandfocus_on_appear(_selecting)are exactly its methods.Optionsand its traits) is the breaking tag, and it has eight open questions for you. Waiting would tie this small, concrete gap to that larger decision.FocusRequest { autofocus: Autofocus, on_open: bool }(or an enum, if you rule out "both"; see below), with a singleapply(handle)that marks the node and runs the autofocus. Each chain holds one field of it.NodeHandle::focus_on_open. When One options layer for owned controls: Options, Configure/Interactive traits, refused(reason), when/when_some #315'sFocustrait lands, the methods move into the trait's provided methods, with no behaviour change and every test unchanged.focus_on_openandfocus_on_appearon one control are both meaningful only if the control can appear without its overlay opening, which happens when a control is added to an already-open overlay. A single enum,Autofocus::{Never, OnAppear(Select), OnChange(..), OnOverlayOpen}, makes "both" unrepresentable, per the engineering rules on mutually exclusive modes. I recommend the enum.focus_on_opensetsOnOverlayOpen.focus_on_open: as the popover opens from the keyboard, the stepper's field has focus, not the button;FocusOnOpenTwice.Questions for the user, with my recommendations
DismissOn::Outsideandon_dismiss_with, or one? Recommend both: one is policy, the other information.DismissedorDismissCause? RecommendDismissed(|app, why: Dismissed|).nav::navigatereturns overlays to dismiss; the PR will list exactly which keys): its own cause,Dismissed::Keys, or folded intoEsc? Recommend its own cause, so an app can tell keyboard navigation out of a menu from a cancel.focus_on_opennow, or after One options layer for owned controls: Options, Configure/Interactive traits, refused(reason), when/when_some #315? Recommend now, built so One options layer for owned controls: Options, Configure/Interactive traits, refused(reason), when/when_some #315 only moves it.Autofocus::OnOverlayOpen) instead of a separate flag? Recommend the enum.Suggested PRs
DismissOn::OutsideplusDismissed/on_dismiss_with.focus_on_openon the owned chains.Merge pull request #365 from samitbasu/blur-326
samitbasu commentedon Nov 18, 2026
Decisions (user, 2026-11-18):
DismissOn::Outside(an outside press or Escape only) andon_dismiss_with(|app, why|), with a public#[non_exhaustive] Dismissed { Outside, Esc, FocusOut, WindowBlur, Exclusive, AnchorGone, Keys }.on_dismisswraps it and ignores the cause..focus_on_open()on every focusable owned chain NOW, asAutofocus::OnOverlayOpen(so it can't be combined with focus_on_appear); One options layer for owned controls: Options, Configure/Interactive traits, refused(reason), when/when_some #315's Focus trait absorbs it later.Dismissed, with its ownKeyscause.The blur fix already merged (#365).
samitbasu commentedon Nov 19, 2026
Coordination note from the #372/#21 dialog work (core C1), so the two dismissal changes meet cleanly:
ButtonChain::dismisses(): after its own handler, the button dismisses its overlay throughon_dismiss. Indismiss.rsthis is a new crate-internalCause::Closed, found indismissalslike the others (a per-Layerflag set from the buttons pressed this pass), so the dismissal path stays single.judgetreats it like any non-Cancelcause.Dismissed: that cause needs a public variant whenon_dismiss_withlands. I suggestDismissed::Closed("a button markeddismisses()was pressed: the dialog's × or a Cancel with no handler").Dismissedis#[non_exhaustive], so whichever PR lands second adds the variant and the mapping; it's one match arm.focus_on_openon owned chains:alert_dialogwants first focus on Cancel. UntilButtonChain::focus_on_open()lands from this issue, the dialog relies on build order (Cancel is the first focusable of a field-less alert dialog, and the × is never built in one). When yours lands I'll switch the footer's Cancel to it in a one-line follow-up; I'm not adding afocus_on_opentoButtonChainmyself, so nothing collides.The PR will be linked here when it's up.
samitbasu commentedon Nov 19, 2026
The C1 PR is up: #409 (
ButtonChain::dismisses, crate-internalCause::Closedindismissals). WhenDismissedlands, it needs aClosedvariant for it.Merge pull request #420 from samitbasu/focus-326