Skip to content

feat: Add option to close modal on mobile via overlay - #4031

Open
GFKuks wants to merge 2 commits into
Workday:supportfrom
GFKuks:feature/mobile-opt-in-overlay-close
Open

feat: Add option to close modal on mobile via overlay#4031
GFKuks wants to merge 2 commits into
Workday:supportfrom
GFKuks:feature/mobile-opt-in-overlay-close

Conversation

@GFKuks

@GFKuks GFKuks commented Jul 1, 2026

Copy link
Copy Markdown

This PR introduces an optional configuration option for modal that allows users to close modal by clicking on background overlay. By default, this behaviour is disabled for modality === 'touch'

Summary

Resolves issue #3108

For Mobile Inventory Modernization project - but also seemingly other use cases - there are cases when we have informational modals that do not critically require an explicit user selection via buttons, so dismissing modal via overlay click makes sense from a UX point of view.

Release Category

Components


Checklist

Reviewers

@josh-bagwell
@RayRedGoose

Where Should the Reviewer Start?

modules/react/modal/lib/hooks/useCloseOnOverlayClick.ts

Areas for Feedback? (optional)

  • Code
  • Documentation
  • Testing
  • Codemods

Testing Manually

Screenshots or GIFs (if applicable)

Thank You Gif (optional)

Summary by CodeRabbit

  • New Features
    • Added an opt-in setting to allow modals to close when users tap the overlay on touch/mobile devices.
    • Included a new example demonstrating the mobile overlay-close behavior.
  • Bug Fixes
    • Updated overlay-close behavior so touch devices follow the enabled setting.
  • Tests
    • Added a component test covering touch interaction to verify the license dialog closes as expected.

@GFKuks
GFKuks requested a review from a team as a code owner July 1, 2026 09:07
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an enableMobileCloseOnOverlayClick config/state option to usePopupModel, extends useCloseOnOverlayClick to permit closing on touch modality when this flag is enabled, adds a new WithMobileOverlayCloseEnabled modal story example, and adds a Cypress test validating the mobile overlay-close behavior.

Changes

Mobile Overlay Close Feature

Layer / File(s) Summary
Popup model config and state
modules/react/popup/lib/hooks/usePopupModel.ts
Adds enableMobileCloseOnOverlayClick boolean to defaultConfig (default false) and exposes it in model state.
Overlay click hook touch gating
modules/react/modal/lib/hooks/useCloseOnOverlayClick.ts
Extends the hide condition so touch-modality overlay clicks close the modal only when enableMobileCloseOnOverlayClick is true; updates useCallback dependencies.
Story example and test verification
modules/react/modal/stories/examples/WithMobileOverlayCloseEnabled.tsx, cypress/component/Modal.spec.tsx
Adds a new modal story enabling mobile overlay-close and a Cypress test that simulates a touch interaction on an iphone-x viewport, verifying clicking outside closes the modal.

Estimated code review effort: 2 (Simple) | ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding an option to dismiss the modal via overlay on mobile.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cypress/component/Modal.spec.tsx (1)

175-184: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant duplicate mount.

The outer beforeEach (line 177) mounts <WithMobileOverlayCloseEnabled />, and the inner beforeEach (line 184) mounts it again before every test in the nested context. Only the inner mount is needed since it's the one immediately preceding the test actions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cypress/component/Modal.spec.tsx` around lines 175 - 184, The nested test
setup in Modal.spec.tsx mounts WithMobileOverlayCloseEnabled twice, once in the
outer beforeEach and again in the inner beforeEach, which is redundant. Remove
the outer mount and keep the mount inside the nested context so the
WithMobileOverlayCloseEnabled fixture is only initialized where the mobile
overlay click test runs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cypress/component/Modal.spec.tsx`:
- Around line 175-194: The WithMobileOverlayCloseEnabled test is asserting the
modal is closed without ever opening it first, so it never exercises the
overlay-close behavior. Update the setup in this context to open the dialog via
the modal trigger before the mobile overlay tap, using the
WithMobileOverlayCloseEnabled example and its Modal.Target/“Open License”
interaction, then keep the existing not.exist assertion to verify
enableMobileCloseOnOverlayClick actually closes an opened modal.

---

Nitpick comments:
In `@cypress/component/Modal.spec.tsx`:
- Around line 175-184: The nested test setup in Modal.spec.tsx mounts
WithMobileOverlayCloseEnabled twice, once in the outer beforeEach and again in
the inner beforeEach, which is redundant. Remove the outer mount and keep the
mount inside the nested context so the WithMobileOverlayCloseEnabled fixture is
only initialized where the mobile overlay click test runs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9692abbe-529e-4ec9-93dc-875c751ac542

📥 Commits

Reviewing files that changed from the base of the PR and between c652dd2 and b09cd21.

📒 Files selected for processing (4)
  • cypress/component/Modal.spec.tsx
  • modules/react/modal/lib/hooks/useCloseOnOverlayClick.ts
  • modules/react/modal/stories/examples/WithMobileOverlayCloseEnabled.tsx
  • modules/react/popup/lib/hooks/usePopupModel.ts

Comment thread cypress/component/Modal.spec.tsx Outdated
@RayRedGoose RayRedGoose added the ready for review Code is ready for review label Jul 2, 2026
@cypress

cypress Bot commented Jul 2, 2026

Copy link
Copy Markdown

Workday/canvas-kit    Run #11167

Run Properties:  status check passed Passed #11167  •  git commit 8d5af324b5 ℹ️: Merge 975c189149d4f88aee869e9545758e6f293ba391 into c652dd29eae3dbe44a9226c7ef07...
Project Workday/canvas-kit
Branch Review feature/mobile-opt-in-overlay-close
Run status status check passed Passed #11167
Run duration 02m 29s
Commit git commit 8d5af324b5 ℹ️: Merge 975c189149d4f88aee869e9545758e6f293ba391 into c652dd29eae3dbe44a9226c7ef07...
Committer GFKuks
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 86
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 864
View all changes introduced in this branch ↗︎
UI Coverage  19.6%
  Untested elements 1536  
  Tested elements 372  
Accessibility  99.33%
  Failed rules  6 critical   5 serious   0 moderate   2 minor
  Failed elements 78  

@RayRedGoose RayRedGoose changed the title feat(usePopupModel): Add option to close modal on mobile via overlay feat: Add option to close modal on mobile via overlay Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Code is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants