Skip to content

Integrate CloseWatcher to dialog patterns #3308

@artalar

Description

@artalar

Mobile users, especially on Android, are accustomed to closing modal dialogs using the native back button—a common pattern in modern mobile UX. It would be beneficial to include notes explaining why handling the back button with history manipulation is considered bad practice, and to mention the new CloseWatcher API as a better alternative.

Why navigation history isn't a viable option

Let's examine the different implementation approaches:

- Opening a modal dialog
  - `pushState` implementation
    - 👍 "back" button handled perfectly
    - 👎 if the page reloads for any reason (user switches to another app and the OS kills the process), there's no way to restore the state, and the back button appears to do nothing on the first press which is very misleading
  - Query parameters implementation
    - 👍 "back" button handled perfectly
    - 👍 page reload handled perfectly
    - 👎 extraneous data in the URL could lead to unexpected UI states if the link is shared and opened by a different user
  - Hash implementation
    - 👎 same issues as query parameters, but also cannot handle nested dialogs

As demonstrated above, there's no way to implement perfect back button handling with the native history API without significant drawbacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Example PageRelated to a page containing an example implementation of a patternP3Task force has identified as low priority at this time compared to other prioritized issuesenhancementAny addition or improvement that doesn't fix a code bug or prose inaccuracy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions