fix(select): nullify quick clicks on select
Closes #3619
📝 Description
Multiple quick clicks on select trigger was not waiting for animation to complete and starts to process the actions by subsequent clicks to open/close the popover. The PR makes the fix which blocks the actions triggered by the click until a specific threshold time.
⛳️ Current behavior (updates)
As shown in the video below, on multiple quick click, the subsequent clicks action is triggered which closes/opens the pop-over without waiting for the animation to get completed.
https://github.com/user-attachments/assets/ab3af3dd-e189-49f7-90fc-456675c8b410
🚀 New behavior
PR adds an a delay of threshold only after which the click will trigger action.
https://github.com/user-attachments/assets/9f15ea7d-1dbb-4a59-8b5e-db29ff207040
💣 Is this a breaking change (Yes/No): No
📝 Questions to the reviewers:
- The threshold selected is based on trial and error as I was unable to get the information about timing in which the framer motion animation will get over. Current threshold works good but is there an better way in thresholding here?
- The code makes changes in
use-multiselect, by modifying thetriggerPropsreturned. Alternative of this could be making the change inuse-selectby modifyingonPressStartthere. But the current way is implemented in order to support re-usability.
Summary by CodeRabbit
-
Bug Fixes
- Resolved an issue with the multi-select component that caused unintended actions during rapid clicks, enhancing user experience.
-
New Features
- Introduced a functionality to manage press event timing, preventing rapid consecutive triggers for improved interaction with the multi-select component.
🦋 Changeset detected
Latest commit: 4bf8eabcba84c5a5f74f6de689e7bdde4d2bad78
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 3 packages
| Name | Type |
|---|---|
| @nextui-org/use-aria-multiselect | Patch |
| @nextui-org/select | Patch |
| @nextui-org/react | 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
@macci001 is attempting to deploy a commit to the NextUI Inc Team on Vercel.
A member of the Team first needs to authorize it.
Walkthrough
This update implements a fix for the multi-select component in the @nextui-org/use-aria-multiselect package. It addresses an issue where rapid clicks could trigger actions before the animation for opening or closing the popover completed. A new function, useAvoidQuickPress, is introduced to manage press event timing, preventing unintended interactions during animations.
Changes
| Files | Change Summary |
|---|---|
src/use-multiselect.ts |
Added useAvoidQuickPress function; modified useMultiSelect to integrate it. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Ensure actions wait for ongoing animations to complete (3619) | ✅ |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai generate interesting stats about this repository and render them as a table.@coderabbitai show all the console.log statements in this repository.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (invoked as PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
I tried to figure out the discrepant behaviour but was unable to find out what exact issue is behind this.
One thing I noted was that on docs is: While closing the select popover, the onPressStart and onPress events are not triggered (the respective events do get triggered on opening the select)
But on the story book page the onPressStart and onPress events are triggered both on opening and closing the select popover.
Edit: I have checked that the issue of quick clicks occurs in story-book, sandbox provided on docs, individual project as well, just not sure why does this not happen on the preview in docs.
@wingkwong maybe you can help in a bit here?
Previously I also had a quick check but got no clue. Better identify the discrepancy to see if the fix is correct or not.
@wingkwong The issue may be caused by domRef, which does not occur in PR#3467. Additionally, the NextUI doc is outdated (When Select A is open, clicking Select B does not open Select B).
@chirokas can you sync your PR with latest canary once? I think I'll move your PR to v2.4.7.
Closing this one - will be handled in chirokas' PR.