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(dropdown): focus behaviour on press / enter keydown #2970

Merged
merged 10 commits into from May 19, 2024
Merged

Conversation

wingkwong
Copy link
Member

@wingkwong wingkwong commented May 9, 2024

Closes #2863

📝 Description

As the doc stated, when keydown (press /enter) on the trigger, the first menu item should be focused. This PR is to cover this missing behaviour.

⛳️ Current behavior (updates)

Please describe the current behavior that you are modifying

🚀 New behavior

Please describe the behavior or changes this PR adds

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

📝 Additional Information

Summary by CodeRabbit

  • New Features
    • Improved keyboard accessibility in dropdown menus: now focuses on the first item when opened with Space or Enter keys.
    • Added @nextui-org/test-utils as a dependency for the dropdown component.

Copy link

vercel bot commented May 9, 2024

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 May 19, 2024 2:12pm
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2024 2:12pm

Copy link

changeset-bot bot commented May 9, 2024

🦋 Changeset detected

Latest commit: 6549a0b

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

coderabbitai bot commented May 9, 2024

Walkthrough

The recent changes aim to improve the behavior of the @nextui-org/dropdown package by ensuring that the first item in the dropdown receives focus automatically when opened using the Space or Enter keys. These enhancements are designed to enhance accessibility and improve user interaction with keyboard inputs.

Changes

File Path Change Summary
.changeset/heavy-kangaroos-stare.md Introduces a patch to focus on the first dropdown item when the Space or Enter key is pressed.
packages/components/dropdown/__tests__/dropdown.test.tsx Adds test cases for keyboard interactions focusing on the first dropdown item using Enter and Space keys.
packages/components/dropdown/package.json Adds @nextui-org/test-utils as a dependency in the package.json file for the dropdown component.
packages/components/dropdown/src/use-dropdown.ts Adds autoFocus: "first" property to MenuProps in the useDropdown function for auto-focusing.
packages/components/menu/src/use-menu.ts Updates the usage of props in the useMenu function to include userMenuProps alongside otherProps.

Assessment against linked issues

Objective Addressed Explanation
DropdownItem not getting focused properly when Dropdown opens with Space or Enter (Issue #2863)
'Enter' or 'Space' not selecting the item after focusing on DropdownItem (Issue #2863) The changes address the focus issue, but it's unclear if the selection functionality is explicitly added.

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

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 633f9d2 and 9c70e92.
Files selected for processing (3)
  • .changeset/heavy-kangaroos-stare.md (1 hunks)
  • packages/components/dropdown/tests/dropdown.test.tsx (1 hunks)
  • packages/components/dropdown/src/use-dropdown.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • .changeset/heavy-kangaroos-stare.md
Additional comments not posted (2)
packages/components/dropdown/src/use-dropdown.ts (1)

147-147: Ensure the autoFocus property is correctly implemented and tested.

This change correctly implements the autoFocus: "first" property to enhance keyboard accessibility by focusing the first item when the dropdown is activated. It's crucial to ensure that this behavior is covered by unit tests to prevent regressions in future updates.

packages/components/dropdown/__tests__/dropdown.test.tsx (1)

542-622: New test cases for keyboard interactions are comprehensive and well-structured.

The new test cases effectively simulate user interactions with the keyboard (Enter and Space keys) and verify that the first item is focused as expected. This aligns well with the changes made in the use-dropdown.ts file and ensures that the new functionality behaves as intended.

@wingkwong wingkwong added this to the v2.3.7 milestone May 14, 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 9c70e92 and 2de66ad.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (3)
  • packages/components/dropdown/tests/dropdown.test.tsx (2 hunks)
  • packages/components/dropdown/package.json (1 hunks)
  • packages/components/dropdown/src/use-dropdown.ts (2 hunks)
Files skipped from review due to trivial changes (2)
  • packages/components/dropdown/tests/dropdown.test.tsx
  • packages/components/dropdown/package.json
Files skipped from review as they are similar to previous changes (1)
  • packages/components/dropdown/src/use-dropdown.ts

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 2de66ad and 6549a0b.
Files selected for processing (3)
  • .changeset/heavy-kangaroos-stare.md (1 hunks)
  • packages/components/dropdown/src/use-dropdown.ts (1 hunks)
  • packages/components/menu/src/use-menu.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • packages/components/dropdown/src/use-dropdown.ts
Files skipped from review as they are similar to previous changes (1)
  • .changeset/heavy-kangaroos-stare.md
Additional comments not posted (2)
packages/components/menu/src/use-menu.ts (2)

122-122: Ensure proper merging of userMenuProps with otherProps.

The integration of userMenuProps into the state generation through useTreeState is correctly implemented. This change should allow for more flexible configuration of the menu component, aligning with the PR's objectives to enhance keyboard interaction.


126-126: Validate the extended use of userMenuProps in ARIA menu props.

The extension of userMenuProps into the ARIA menu props generation via useAriaMenu is correctly done. This ensures that any user-defined properties are considered in the ARIA attributes, which is crucial for accessibility and custom behavior.

Copy link
Member

@jrgarciadev jrgarciadev left a comment

Choose a reason for hiding this comment

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

🚀

@jrgarciadev jrgarciadev merged commit 7df2c71 into canary May 19, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - DropdownItem not getting focused properly and 'Enter' | 'Space' not selecting the item.
2 participants