Repository navigation
Conversation
An overlay listening to `onCancel` in the root view kept the Escape binding and the back listener while a dialog was shown above it, so the dialog never heard its close and stayed open. While a dialog is shown, only the overlays the top dialog hosts take Escape and back; with none listening there, the key reaches the dialog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
💡 The fix is correct and matches the Web top-layer rule, but it changes A shown Dialog now takes Escape and back before overlays in the roots below it (like a modal
Reviewed head 917b9a1 (diff review); CI still running. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A page can keep an
Overlaylistening toonCancelin its root view, for example a non-modal side drawer that closes on Escape. While it is mounted, aDialog(nsh/base) opened above it never hears Escape: the core binds Escape for the root overlay (ESCAPE_BINDING,When::Always) and hands it to that overlay'sonCancel, so the dialog's own close (onRequestClose→onOpenChangewith reasoncancel) never runs and the dialog stays open. Akeymap.bind('escape', …, { when: 'always' })made while the dialog is open is not reached either, because the overlay's binding comes last and wins. Android back takes the same path (BackPresscallsoverlay_cancel()first).Press
open, then Escape: before, the log showsoverlay canceland the dialog stays open. After, the dialog hearscanceland closes; a second Escape givesoverlay cancel.The cause is in
crates/nsh-core/src/core/overlay.rs: whether Escape is bound (overlay_state.cancel, computed insync_overlay_listeners), the top candidate inoverlay_cancel()and the onefocus_takes_escape()checks were all chosen across every root view, ignoring a dialog shown above the overlay's root view.Now the newest layer wins, as on the Web, where a modal
<dialog>above an open popover takes Escape first:Core::cancel_hostfinds the top shown dialog: a created, displayedKind::Modalthat is not one of the app's own windows, the one opened last, or a dialog opened inside it.OverlayState::host) can take Escape and back. With none listening inside it, no Escape binding is made and the root does not take back, so the key reaches the dialog natively. With no dialog shown, behavior is unchanged.overlay_cancel()andfocus_takes_escape()share the newtop_cancel_overlay(). The binding is recomputed when a dialog opens or closes, since inserting, removing and making views already mark the overlays dirty.The platforms only consume the root keymap and the root's back listener, so they need no change.
Docs: the
onCancelevent and prop docs (ops.rs,js/host.rs,Overlay::on_cancel),docs/dev/elements.mdand the English and zh-CNOverlaypages now say that a dialog above the overlay takes the key first.Public API
No new or changed signatures. Behavior of
OverlayonCancel(nsh) /Overlay::on_cancel(nsh_core::element): while aDialogis shown above the overlay's root view, the dialog takes Escape and back first. The overlay hears them once no dialog is above it.How to Test
cargo test -p nsh-core: all pass, including the newcore::tests::a_dialog_above_takes_escape_and_back_from_the_overlays_under_it. It covers the binding going away while a dialog opens, back reaching no overlay under it, an overlay inside the dialog taking Escape and back, a nested dialog, and the root overlay getting Escape again once the dialogs close. It fails onmain.cargo test -p nsh-base: all pass, including the new headlessdialog::escape_closes_a_dialog_before_the_overlay_under_it(the TSX case above in Rust). It fails onmain(dialog cancelnever shown).nsh testfile (open, Escape →dialog canceland the dialog gone, Escape →overlay cancel) passes headless asios,android,macosandweb. Onmainit shows["Open", "overlay cancel", "Dialog"].cargo clippy -p nsh-core -p nsh-base --all-targets,cargo +nightly fmt,./target/debug/nsh test examples/counter/App.tsx --trace(no overlays: unchanged).Checklist
cargo test -p nsh-core -p nsh-base,cargo +nightly fmtand clippy for the changed crates.cargo xtask compat).🤖 Generated with Claude Code