Skip to content

[FocusScope] Dialog resets focus when leaving & returning to browser tab/window  #499

Closed
@tigranpetrossian

Description

@tigranpetrossian

Bug report

Current Behavior

Dialog resets focus to first focusable element when browser tab is blurred.

Gif with reproduction

Expected behavior

Focus should be retained when leaving browser window/tab and returning to it.

Reproducible example

CodeSandbox

Suggested solution

This might be because of trapFocus re-initializing on document focus, but I'm not 100% sure:
https://github.com/radix-ui/primitives/blob/main/packages/react/focus-scope/src/createFocusScope.tsx#L30

Your environment

Software Name(s) Version
Radix Package(s) Dialog 0.06
React 17.0.1
Browser Chrome 88.0
Assistive tech n/a
Node n/a
npm/yarn n/a
Operating System MacOs 10.15.6

Reproducible pretty much everywhere except Safari (13.1.2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions