feat: close modals with browser back button on mobile (#257)

* feat: close modals with browser back button on mobile

Create reusable useModalHistory hook that pushes history state when a
modal opens and listens for popstate to close it. Apply to ReportModal,
ClearMissedConfirm, ExportModal, ImportConfirm, and all modals using
ConfirmModal/ShareDialog/Auth/ExportModal base components. Escape key
handling was already in place for desktop.

Closes #253

* fix: update tests for renamed button labels and missing useModalHistory mock
This commit is contained in:
Daniel Volz
2026-02-21 18:00:12 +01:00
committed by GitHub
parent 94bd8bd6e8
commit 943148fb49
15 changed files with 88 additions and 11 deletions
@@ -70,12 +70,12 @@ describe("ExportModal", () => {
it("renders cancel button", () => {
render(<ExportModal {...defaultProps} />);
expect(screen.getByText(/exportImport\.cancelButton/i)).toBeInTheDocument();
expect(screen.getByText(/common\.close/i)).toBeInTheDocument();
});
it("calls onClose when cancel button is clicked", () => {
render(<ExportModal {...defaultProps} />);
fireEvent.click(screen.getByText(/exportImport\.cancelButton/i));
fireEvent.click(screen.getByText(/common\.close/i));
expect(defaultProps.onClose).toHaveBeenCalled();
});