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

fix(menu)/dropdown menu selection #3710

Open
wants to merge 5 commits into
base: canary
Choose a base branch
from

Conversation

sohan01fw
Copy link
Contributor

@sohan01fw sohan01fw commented Sep 4, 2024

Closes #1560

📝 Description

This PR addresses the issue where the dropdown selection functionality is not working on mobile devices as well as in web.

⛳️ Current behavior (updates)

As you can see the figure below the bug is the selection stay at the same place when cursor move out of the menu.

04.09.2024_15.24.15_REC.mp4

🚀 New behavior

As Video below the bug get solved by applying some condition in code

fix.mp4

💣 Is this a breaking change (Yes/No):No

📝 Additional Information

Summary by CodeRabbit

  • New Features

    • Enhanced focus and selection management for menu items, improving user interaction and visual feedback.
    • Improved interactivity by refining conditions for item selection based on hover state.
  • Bug Fixes

    • Resolved issues with item selection, ensuring items can be selected when hovered over, particularly enhancing dropdown functionality on mobile devices.

Copy link

changeset-bot bot commented Sep 4, 2024

🦋 Changeset detected

Latest commit: 22b4c34

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/menu Patch
@nextui-org/dropdown 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

Copy link

vercel bot commented Sep 4, 2024

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

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes in the useMenuItem function enhance focus and selection management within the dropdown component. The logic for determining the selectable state has been refined to depend on both isHovered and isSelectable, ensuring that user interactions are more accurately represented. The itemProps object has been updated to reflect these changes, improving the handling of focus and selection states.

Changes

Files Change Summary
packages/components/menu/src/use-menu-item.ts Modified data-selectable attribute to depend on isHovered and isSelectable; improved readability by removing a blank line.

Assessment against linked issues

Objective Addressed Explanation
Dropdown selection examples are not working in mobile (#1560)

Possibly related PRs

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9b8440d and 22b4c34.

Files selected for processing (1)
  • .changeset/silly-cooks-divide.md (1 hunks)
Additional comments not posted (1)
.changeset/silly-cooks-divide.md (1)

1-5: LGTM!

The changeset message provides a clear and concise explanation of the problem and the solution. The addition of the isHovered condition to the data-selectable attribute should indeed fix the issue where the dropdown selection remains unchanged when the cursor moves out of the menu. This change will improve the user experience on mobile devices by ensuring that the dropdown selection works as expected.


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@sohan01fw sohan01fw changed the title Fix/dropdown menu selection Fix(menu)/dropdown menu selection Sep 4, 2024
@sohan01fw sohan01fw changed the title Fix(menu)/dropdown menu selection fix(menu)/dropdown menu selection Sep 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 87336c7 and 2718d21.

Files selected for processing (1)
  • packages/components/menu/src/use-menu-item.ts (3 hunks)
Additional comments not posted (3)
packages/components/menu/src/use-menu-item.ts (3)

108-108: LGTM!

The new isFocusActive variable enhances the focus management logic by combining the isHovered state with either isFocused or isFocusVisible. This change can potentially improve the user experience by providing clearer visual feedback on item focus.


136-137: LGTM!

The changes to the "data-focus" and "data-selectable" attributes are consistent with the previous enhancement to the focus management logic and can potentially improve the user experience by providing more accurate visual feedback on item focus and selectability.


142-142: LGTM!

Using isFocusActive for the "data-focus-visible" attribute is consistent with the previous changes to the focus management logic and ensures that the focus visible state reflects the more comprehensive condition.

@wingkwong wingkwong self-assigned this Sep 5, 2024
@wingkwong wingkwong added this to the v2.4.7 milestone Sep 5, 2024
Copy link

vercel bot commented Sep 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 1:03pm

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

Try the following steps:

  • use tab key to focus Trigger button
  • press enter to open the dropdown
  • the first item by default will be focused

and it will look below (you can try on production storybook)

image

however, in your PR, with same steps, it looks like this so that users won't know the first item is focused even it does.

image

@sohan01fw
Copy link
Contributor Author

so it only have to show that blue border not gray background?

@wingkwong
Copy link
Member

That's called focus ring. It shows when the item is being focused, regardless of being hovered or not.

@sohan01fw
Copy link
Contributor Author

asktocheck.mp4

@wingkwong is this alright?

@wingkwong
Copy link
Member

I think not. When you open it, the focus ring should be already there. From the video it looks you it shows only when you press the arrow down key. You can compare it with the production storybook https://storybook.nextui.org/?path=/story/components-dropdown--default&globals=locale:bg-BG.

@sohan01fw
Copy link
Contributor Author

wait! i already got that solution before lol

@sohan01fw
Copy link
Contributor Author

thisisfine.mp4

this is ok i guess

@wingkwong
Copy link
Member

The one in video is fine. However, I tested in your PR storybook - https://nextui-storybook-v2-git-fork-sohan01fw-fix-dr-77bf93-nextui-org.vercel.app/?path=%2Fstory%2Fcomponents-dropdown--default. It doesn't match. Have you pushed all the changes?

@sohan01fw
Copy link
Contributor Author

yeah i just pushed one now

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2718d21 and db0b3ef.

Files selected for processing (1)
  • packages/components/menu/src/use-menu-item.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/components/menu/src/use-menu-item.ts

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

line of changes should be just one. please don't add new lines or delete some lines

@sohan01fw
Copy link
Contributor Author

oh iam sorry i didn't saw that i will fix it

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between db0b3ef and 9b8440d.

Files selected for processing (1)
  • packages/components/menu/src/use-menu-item.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/components/menu/src/use-menu-item.ts

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

  1. please add a changeset
  2. what is the reason to add isHovered in L137 but not to isSelectable ?

@sohan01fw
Copy link
Contributor Author

sohan01fw commented Sep 13, 2024

what is the reason to add isHovered in L137 but not to isSelectable ?

isHovered is utilized to provide immediate visual feedback regarding the item's hover state, enhancing user interaction. In contrast, isSelectable denotes the inherent capability of the item to be selected based on the menu's configuration. These two states serve distinct functions: isHovered pertains to the current interaction state, while isSelectable reflects the broader selection criteria defined by the menu's logic.And if isSelectable used it didn't solve the bug. It will still get presist.

@wingkwong
Copy link
Member

I mean the value of data-selectable should be based on isSelectable. However, in your PR, it breaks this statement because you included isHovered as well in L137.

@sohan01fw
Copy link
Contributor Author

sohan01fw commented Sep 13, 2024

oh there i just checked if there is isHovered present or not and it get solved.That is just a checking statement. previously i had written in optional chaining but i think this is concise so.

@wingkwong wingkwong removed this from the v2.4.7 milestone Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Dropdown selection examples are not working in mobile
2 participants