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

Close the dropdown when the user clicks outside of it #99179

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

merkushin
Copy link
Member

@merkushin merkushin commented Jan 31, 2025

Related to #99090

There is an alternative of using useClickAway, but it is a new dependency.

Proposed Changes

  • Handle the click outside the component and close the dropdown.

Why are these changes being made?

  • Need to click on the component to close the dropdown, which is not a convenient UX.

CleanShot 2025-01-31 at 14 12 46

Testing Instructions

  • First, let's test WordPress.com hosting/domain purchase:
    • Go to /start, choose a paid product to appear on the Checkout step.
    • Open the dropdown with payment options.
    • Make sure you can close it by clicking outside the dropdown.
  • There is also Akismet quantity dropdown, let's test it too:

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@merkushin merkushin added the [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Jan 31, 2025
@merkushin merkushin requested a review from Robertght January 31, 2025 20:18
@merkushin merkushin self-assigned this Jan 31, 2025
@matticbot matticbot added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 31, 2025
@matticbot
Copy link
Contributor

matticbot commented Jan 31, 2025

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~166 bytes added 📈 [gzipped])

name      parsed_size           gzip_size
checkout       +514 B  (+0.0%)     +166 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~166 bytes added 📈 [gzipped])

name                                             parsed_size           gzip_size
async-load-calypso-my-sites-checkout-modal            +514 B  (+0.0%)     +166 B  (+0.0%)
async-load-calypso-blocks-editor-checkout-modal       +514 B  (+0.0%)     +166 B  (+0.1%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@matticbot
Copy link
Contributor

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • notifications

To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/close-dropdown-on-click-away on your sandbox.

@merkushin merkushin marked this pull request as ready for review February 1, 2025 00:31
@merkushin merkushin requested a review from a team as a code owner February 1, 2025 00:31
@merkushin merkushin linked an issue Feb 1, 2025 that may be closed by this pull request
Copy link
Member

@sirbrillig sirbrillig left a comment

Choose a reason for hiding this comment

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

Works as described! Thanks!

@merkushin merkushin merged commit ba87db5 into trunk Feb 3, 2025
16 checks passed
@merkushin merkushin deleted the fix/close-dropdown-on-click-away branch February 3, 2025 15:32
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 3, 2025
@mirka
Copy link
Member

mirka commented Feb 12, 2025

Any reason these dropdowns were implemented with low-level components, rather than something like CustomSelectControl? There are a lot of implementational details involved in a custom dropdown like this, including click away behavior as implemented here, but also Escape key handling, Tab key handling, typeahead, etc. that are still missing. It's a lot of extra work to do these correctly from scratch/low-level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dropdown on the checkout page doesn't close when click outside
4 participants