Skip to content
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

Fix useClickOutside when the target element is removed #1072

Merged
merged 1 commit into from
Jul 29, 2021

Conversation

connor-baer
Copy link
Member

Purpose

When an element is clicked inside the container element and removed right after the click, useClickOutside would trigger because, at the time when the hook checks whether the container contains the clicked element, the element has already been detached from the DOM.

Thanks @hris27 for the report and suggested fix! 🙌🏻

Approach and changes

  • Check if the container contains the clicked element on the mousedown event. The callback is still triggered on the click event because it can be intercepted, unlike the mousedown event.

Definition of done

  • Development completed
  • Reviewers assigned
  • Unit and integration tests
  • Meets minimum browser support
  • Meets accessibility requirements

Co-authored-by: Hristiyan Dimitrov <hristiyan.dimitrov@sumup.com>
@connor-baer connor-baer added the 🐞 bug Something isn't working as it should label Jul 28, 2021
@connor-baer connor-baer requested a review from a team as a code owner July 28, 2021 13:34
@connor-baer connor-baer requested review from amelako and removed request for a team July 28, 2021 13:34
@vercel
Copy link

vercel bot commented Jul 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/sumup/oss-circuit-ui/4hfx2iLoCwxtFFAipGxioYpT1dnN
✅ Preview: https://oss-circuit-ui-git-bugfix-outside-click-sumup.vercel.app

@changeset-bot
Copy link

changeset-bot bot commented Jul 28, 2021

🦋 Changeset detected

Latest commit: 98158ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sumup/circuit-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Jul 28, 2021

Codecov Report

Merging #1072 (98158ee) into next (94fee80) will decrease coverage by 0.01%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #1072      +/-   ##
==========================================
- Coverage   92.36%   92.35%   -0.02%     
==========================================
  Files         165      165              
  Lines        2804     2811       +7     
  Branches      791      794       +3     
==========================================
+ Hits         2590     2596       +6     
- Misses        201      202       +1     
  Partials       13       13              
Impacted Files Coverage Δ
...ircuit-ui/hooks/useClickOutside/useClickOutside.ts 88.88% <87.50%> (-2.03%) ⬇️

Copy link
Contributor

@robinmetral robinmetral left a comment

Choose a reason for hiding this comment

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

🚀

@connor-baer connor-baer merged commit 35a6048 into next Jul 29, 2021
@connor-baer connor-baer deleted the bugfix/outside-click branch July 29, 2021 14:41
This was referenced Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working as it should 🗂 circuit-ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants