Skip to content

[Bug] Dialog shows the focus ring on its opening and returning focus after a tap in WebKit #7306

Open

Description

@vjeux

Description

When a pointer opens a Dialog, it moves focus to the [data-autofocus] target right after showModal() (AlertDialog's Cancel), and on close it returns focus to the control that opened it. Both are programmatic focus moves that follow pointer input. architecture:interaction-modality INV1 says such focus does not show the shared focus indicator.

Chromium honours that on its own: :focus-visible is false for a script focus that follows a click, so no ring paints. WebKit does not: a tap or click on a button does not focus the button there, and the script focus that follows matches :focus-visible. On an iPhone the confirmation opens with a ring around Cancel, and after the dialog closes, the control it returns to wears a ring again.

component:Dialog keeps both focus moves (FR2, FR4) and leaves "focus-ring appearance and modality detection" to the interaction authority, so the fix sits at that boundary: keep the moves and hide the indicator after pointer input, as DropdownMenu already does for the trigger it refocuses (useFocusReturnVisibility). INV6 keeps the modality tracker internal, so a host cannot do this itself.

Reproduction

  1. In Safari on iOS or macOS, tap or click a button that opens an AlertDialog.
  2. Cancel opens with a focus ring.
  3. Tap Cancel: the button that opened the dialog shows a focus ring.

With the keyboard (Enter on the button, Escape to close) both rings are expected. In Chromium neither pointer ring paints.

Astryx Version

@astryxdesign/[email protected]; Dialog.tsx on main is unchanged.

Environment

Safari on iOS (seen on an iPhone) and Safari on macOS. Not reproducible in Chromium, whose focus-visible heuristic already hides these.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions