feat(dialog): restoreFocus β a fallback focus home for the close - #53
Open
ivanbanov wants to merge 1 commit into
Open
feat(dialog): restoreFocus β a fallback focus home for the close#53ivanbanov wants to merge 1 commit into
ivanbanov wants to merge 1 commit into
Conversation
Closing restores focus to whatever held it before opening; when that holder can't meaningfully take focus back β the body (a pointer press leaves focus there), or an element since removed from the document β the restore now falls back to a consumer-designated target, typically the trigger. Before, both cases silently dropped focus. The decision lives once in openDialogLayer (restoreFocus?: () => HTMLElement | null, resolved at close); the React and Solid bindings only plumb their idioms β a ref, an element-or-accessor. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
Dialog.ContentgainsrestoreFocus, the close-side counterpart toinitialFocus. Closing still restores focus to whatever held it before the dialog opened β but only when that element can meaningfully take focus back. When focus sat on the body (a pointer press can leave it there) or on an element removed from the document since, the restore falls back to the consumer-designated target, typically the trigger. With neither, focus stays where it is.Where
@dunky.dev/dom-dialogβ the decision lives once inopenDialogLayer: a newrestoreFocus?: () => HTMLElement | nulloption, resolved at close, plus the meaningful-previous check (instanceof HTMLElement, not the body, still connected) in the disposer.@dunky.dev/react-dialogβrestoreFocus?: RefObject<HTMLElement | null>onDialog.Content, read through a ref at close time.@dunky.dev/solid-dialogβrestoreFocus?: HTMLElement | (() => HTMLElement | null | undefined)onDialog.Content, same shape asinitialFocus, resolved at close time.The bindings add no behavior β they only plumb their host idiom into the DOM option, per the one-way boundary.
Why
Both fallback cases previously dropped focus silently: restoring to the body goes nowhere, and
focus()on a disconnected element is a no-op, leaving focus stranded on the closing layer. The element focused before opening still always wins when it is meaningful β the fallback never overrides it.Coverage
Full suite green: 16 files, 281 tests. Typecheck (base + solid), oxlint, oxfmt clean.
π€ Generated with Claude Code