Skip to content

Dialogs hijack focus on 'escape' press when they aren't open #3686

Description

@jdrush89

Description

If a dialog component is being rendered, but is closed, and the escape key is pressed, focus will get set to the dialog's target. This seems to be due to the logic that tries to set focus back to the last focused element when a dialog closes, but the logic should not be executing if the dialog was never opened.

Steps to reproduce

  1. Go to https://primer.style/react/Dialog
  2. Press the 'Escape' key
  3. See that focus goes to one of the 'open' buttons

Version

v35.28.0

Browser

Chrome

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions