Skip to content

feat: allow onClickOutside to prevent calendar from closing#6179

Merged
martijnrusschen merged 1 commit intomainfrom
fix/prevent-close-on-click-outside
Dec 18, 2025
Merged

feat: allow onClickOutside to prevent calendar from closing#6179
martijnrusschen merged 1 commit intomainfrom
fix/prevent-close-on-click-outside

Conversation

@martijnrusschen
Copy link
Copy Markdown
Member

Summary

  • Allow onClickOutside callback to prevent the calendar from closing by calling event.preventDefault()
  • The callback is now called before the calendar closes, giving users control over the close behavior

Problem

When using custom portal-based dropdowns in the calendar header (e.g., custom month/year selectors), clicking on the portal menu triggers onClickOutside and closes the calendar, even though the click was on a valid UI element.

Previously, the close happened before onClickOutside was called, so users couldn't prevent it.

Solution

Call onClickOutside first, then check event.defaultPrevented before closing:

<DatePicker
  onClickOutside={(event) => {
    // Check if click was inside your portal
    if (myPortalRef.current?.contains(event.target)) {
      event.preventDefault(); // Keeps calendar open
    }
  }}
/>

Test plan

  • Added test: "should not close date picker when onClickOutside calls preventDefault"
  • All 1472 tests pass
  • Lint passes
  • Type-check passes

Fixes #5666

🤖 Generated with Claude Code

Call the onClickOutside callback before closing the calendar, allowing
users to call event.preventDefault() to keep the calendar open. This is
useful when using custom portal-based dropdowns in the calendar header
that would otherwise trigger the click outside handler.

Fixes #5666

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.31%. Comparing base (0231bbd) to head (3700259).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6179   +/-   ##
=======================================
  Coverage   99.31%   99.31%           
=======================================
  Files          30       30           
  Lines        3801     3801           
  Branches     1652     1652           
=======================================
  Hits         3775     3775           
  Misses         25       25           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martijnrusschen martijnrusschen merged commit 668468a into main Dec 18, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow controlling displayed calendar month or preventing onClickOutside from resetting it

1 participant