fix(select): prevent select from closing instantly when clicking on label of select
Closes #3558 Closes #3683
📝 Description
Fixed select component unexpectedly close while click on label of select component
⛳️ Current behavior (updates)
Below recording shows the current behavior of component.
https://github.com/user-attachments/assets/7bc1411b-e456-41d3-92d7-1032ca0c6e45
🚀 New behavior
Below recording shows the fix behavior of component
https://github.com/user-attachments/assets/73bb0136-5905-4536-8fb0-d40a2f84bb92
💣 Is this a breaking change (Yes/No):No
📝 Additional Information
Summary by CodeRabbit
-
New Features
- Improved user interaction by preventing default actions on label clicks within the select component.
- Simplified interaction model for the select component by adjusting class assignments based on its filled state.
-
Bug Fixes
- Resolved a toggle issue in the select component that caused unexpected behavior when clicking on the label, enhancing the user experience.
@sohan01fw is attempting to deploy a commit to the NextUI Inc Team on Vercel.
A member of the Team first needs to authorize it.
🦋 Changeset detected
Latest commit: 66f7d8621e1ecfa70e61d71c30ded7a42eba8141
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 2 packages
| Name | Type |
|---|---|
| @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
[!WARNING]
Rate limit exceeded
@wingkwong has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 44 seconds before requesting another review.
How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the
@coderabbitai reviewcommand as a PR comment. Alternatively, push new commits to this PR.We recommend that you space out your commits to avoid hitting the rate limit.
How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.
Commits
Files that changed from the base of the PR and between e92ee47ff88f46c04165b2023eddeaf0a6aaf53c and 66f7d8621e1ecfa70e61d71c30ded7a42eba8141.
Walkthrough
The recent updates to the useSelect function and the select component improve user interaction by adding an onClick event handler that prevents default behavior when clicking on the label. This effectively resolves the issue of the select component opening and immediately closing, enhancing overall usability.
Changes
| File | Change Summary |
|---|---|
packages/components/select/src/use-select.ts |
Introduced onClick event handler to prevent default behavior on label clicks. |
packages/core/theme/src/components/select.ts |
Removed conditional class assignment based on filled property, simplifying interaction model. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Select opens and closes instantly when clicking on the label (#3558) | ✅ |
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.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
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.
lol, ya i thought that this simple couldn't be the solution. Ok, i will go with other solution as u mention
@wingkwong I have tried changing the domRef to triggerRef, but it leads to another problem that on clicking the select the popover opens but it doesn't closes on clicking again, which should happen
The the button is itself being passed on as an element and trigger both on clicking the label, that is why the state is getting closed.
@sohan01fw I believe you MUST mind your language and take these things professionally. Perhaps it's not the place to do things randomly
@abhinandan-verma bro it worked with that simple code so i think let's raise pr and iam also getting error during build time in my local so to fix and check both i did raise pr. Now it makes clear tho to solve it by figuring out the further things in deep.
@wingkwong i tried to solve it but it throws test error in select component but when i click and see the select component work fine.
I remember this issue. After opening and clicking selector button, the select is not closed.
should i push this changes or?
this would break the selector button closing behavior. need a solution to cover both case.
@wingkwong when i make changes in test code it work perfectly but is it a right approach ? I add the delay promises to match the test equal to real enviroment
Nope. It shouldn't be like that. What's the new solution btw?
nah same solution i just try to make changes in test cases to fix out the error
@wingkwong I think this is the only way . I tried everything from my side nothing works.
I don't know why you keep making changes on the test while the solution is not expected
no not this one i reset the above test changes on this . You can see file changes. And i didn't able to figure out other solution rather then this . what u say?
I mean adding onClick is not the correct solution, even though all tests are passed and it looks working fine.
@wingkwong what u say on this ? i did change the label: ["group-data-[filled=true]:pointer-events-auto"] to label: ["group-data-[filled=false]:pointer-events-auto"] and it work
- push the code so that i could test on the build.
- explain why changing that works
Changing the data-filled attribute from true to false stops the flickering because it disables the CSS styles associated with the group-data-[filled=true]:pointer-events-auto class.
When the data-filled attribute is set to true, the group-data-[filled=true]:pointer-events-auto class is applied to the label element, which enables pointer events and allows the label to respond to user interactions.
However, when the data-filled attribute is set to false, the group-data-[filled=true]:pointer-events-auto class is removed from the label element, which disables pointer events and prevents the label from responding to user interactions.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| nextui-docs-v2 | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Aug 25, 2024 1:26am |
| nextui-storybook-v2 | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Aug 25, 2024 1:26am |
what about just removing the whole block (L538 - L544)?
yeah i think it's ok to do that cause it's not a link tho
wait i will push code
ok