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

Add new usePopoverShouldClose hook #1629

Merged
merged 1 commit into from
Jul 23, 2024
Merged

Add new usePopoverShouldClose hook #1629

merged 1 commit into from
Jul 23, 2024

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Jul 22, 2024

This PR adds a convenient usePopoverShouldClose hook which is similar to the deprecated useElementShouldClose, but internally combines useClickAway, useFocusAway and useKeyPress to make sure there's no implementation differences.

It also provides a more contextual name that makes it clear in which cases is supposed to be used, as opposed to the cases in which some of the other three individual hooks should be used instead.

Relates to hypothesis/client#6464

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.90%. Comparing base (ca682e1) to head (4c92369).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1629   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files          61       62    +1     
  Lines        1066     1071    +5     
  Branches      408      409    +1     
=======================================
+ Hits         1065     1070    +5     
  Misses          1        1           

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

@acelaya acelaya force-pushed the use-popover-should-close branch 2 times, most recently from 37398db to 1f232eb Compare July 22, 2024 14:42
@acelaya acelaya marked this pull request as ready for review July 22, 2024 14:42
@acelaya acelaya force-pushed the use-popover-should-close branch from 1f232eb to 4c92369 Compare July 22, 2024 14:54
Comment on lines +53 to +70
assert.calledWith(
fakeUseClickAway,
sinon.match.any,
closeHandler,
options ?? {},
);
assert.calledWith(
fakeUseFocusAway,
sinon.match.any,
closeHandler,
options ?? {},
);
assert.calledWith(
fakeUseKeyPress,
['Escape'],
closeHandler,
options ?? {},
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just mocking the other hooks and verifying they are called, as those hooks have their own tests.

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

LGTM, but don't forget to export this along with the other hook exports.

@robertknight
Copy link
Member

The missing line of coverage is being reported against SelectMain, unrelated to this PR. Looks like more fun with default arguments:

Missing coverage

@acelaya
Copy link
Contributor Author

acelaya commented Jul 22, 2024

LGTM, but don't forget to export this along with the other hook exports.

Oh, good catch! I was about to test these changes in client, I guess I would have realized it was not exported then 😅

@acelaya
Copy link
Contributor Author

acelaya commented Jul 22, 2024

The missing line of coverage is being reported against SelectMain, unrelated to this PR. Looks like more fun with default arguments:

Missing coverage

Yeah, that is now always hardcoded as true or false when called through Select or MultiSelect. Once we remove SelectNext that can become a non-optional prop which will solve this.

@robertknight
Copy link
Member

Once we remove SelectNext that can become a non-optional prop which will solve this.

Sounds good. Let's move forward and do that soon.

@acelaya acelaya merged commit 6eb4d9b into main Jul 23, 2024
3 of 4 checks passed
@acelaya acelaya deleted the use-popover-should-close branch July 23, 2024 06:24
@acelaya
Copy link
Contributor Author

acelaya commented Jul 23, 2024

I thought I was merging something else 🤦🏼

Now I need to create another PR to export the symbol 😅

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