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

Remove usages of deprecated useElementShouldClose #6464

Closed
wants to merge 1 commit into from

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Jul 18, 2024

Replace usages of the deprecated useElementShouldClose hook from frontend-shared with useKeyPress(['Escape']), useFocusAway and useClickAway, which is the recommended migration path.

Some tests needed to be adjusted, as the internal implementation of useFocusAway has been changed after it was extracted from useElementShouldClose, and it currently differs from it.

@acelaya acelaya requested a review from robertknight July 18, 2024 09:00
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.43%. Comparing base (1aec784) to head (6bc7e50).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6464   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files         270      270           
  Lines       10214    10219    +5     
  Branches     2416     2416           
=======================================
+ Hits        10156    10161    +5     
  Misses         58       58           

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

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.

I understand the rationale for decomposing useElementShouldClose originally, but perhaps it would be worth having a simple wrapper that encapsulates the "standard" set of actions that can close popover-like controls. In future perhaps we could make these components actually be a native popover, but that's a more substantial refactoring.

// Interactions outside the component when it is open should close it
useClickAway(shareRef, closePanel, { enabled: isOpen });
useFocusAway(shareRef, closePanel, { enabled: isOpen });
useKeyPress(['Escape'], closePanel, { enabled: isOpen });
Copy link
Member

Choose a reason for hiding this comment

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

hypothesis/frontend-shared#900 documented the rationale for decomposing the useElementShouldClose hook into separate hooks, but I think it would be useful to have a combined hook that captured the set of actions that close popover-type controls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, maybe you are right. Perhaps what we should do is keep useElementShouldClose, un-deprecate it, and just make it a wrapper of the other three hooks.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I think I would add a new usePopoverShouldClose hook that wraps the existing hooks and is more specific about the kind of widget it works with. The problem with useElementShouldClose was that we used it for popover-type controls but also different controls that needed different close behaviors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect. I'll close this one for now

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