Skip to content

fix(useOutsideClickEffect): restrict event type to MouseEvent in handleDocumentClick #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wo-o29
Copy link
Contributor

@wo-o29 wo-o29 commented Jun 22, 2025

Overview

This PR resolves a type mismatch in useOutsideClickEffect where the event handler incorrectly expected TouchEvent while only listening to click events. The changes ensure type consistency between event listeners and handlers.

Reason for Change

  1. Type Safety
    The hook was listening exclusively to click events (which fire MouseEvent), but the handler accepted MouseEvent | TouchEvent. This caused:
    • TypeScript type errors
    • Potential runtime inconsistencies

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc?

@Copilot Copilot AI review requested due to automatic review settings June 22, 2025 03:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR resolves a type mismatch in the useOutsideClickEffect hook by restricting the event type in the handleDocumentClick callback to MouseEvent, aligning the expected type with the actual events being listened to.

  • The callback's parameter type was changed from MouseEvent | TouchEvent to MouseEvent.
  • This change ensures type consistency and avoids potential type errors.
Comments suppressed due to low confidence (1)

src/hooks/useOutsideClickEffect/useOutsideClickEffect.ts:33

  • Since the event handler now accepts only MouseEvent, please update any related inline comments or documentation to reflect that touch events are no longer handled.
  const handleDocumentClick = usePreservedCallback(({ target }: MouseEvent) => {

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5bdb4ff) to head (4f62c8e).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #258   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         1093      1093           
  Branches       324       324           
=========================================
  Hits          1093      1093           
🚀 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.

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.

2 participants