nextui icon indicating copy to clipboard operation
nextui copied to clipboard

fix(select): nullify quick clicks on select

Open macci001 opened this issue 1 year ago • 3 comments

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 the triggerProps returned. Alternative of this could be making the change in use-select by modifying onPressStart there. 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.

macci001 avatar Aug 28 '24 11:08 macci001

🦋 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

changeset-bot[bot] avatar Aug 28 '24 11:08 changeset-bot[bot]

@macci001 is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Aug 28 '24 11:08 vercel[bot]

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?

Share
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 @coderabbitai in 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 @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to 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.

coderabbitai[bot] avatar Aug 28 '24 11:08 coderabbitai[bot]

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?

macci001 avatar Aug 29 '24 09:08 macci001

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 avatar Aug 29 '24 11:08 wingkwong

@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 avatar Sep 04 '24 13:09 chirokas

@chirokas can you sync your PR with latest canary once? I think I'll move your PR to v2.4.7.

wingkwong avatar Sep 04 '24 13:09 wingkwong

Closing this one - will be handled in chirokas' PR.

wingkwong avatar Sep 05 '24 13:09 wingkwong