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 DropdownItem onPress #2746

Merged
merged 4 commits into from
Apr 18, 2024
Merged

Fix DropdownItem onPress #2746

merged 4 commits into from
Apr 18, 2024

Conversation

jrgarciadev
Copy link
Member

@jrgarciadev jrgarciadev commented Apr 16, 2024

📝 Description

For some reason the react-aria pressUp event is breaking the onClick / onPress callback, to fix this we had to implement our own use-menu-item hook and control the pressUp event, in addition, we passed down the properties to control the press events directly.

⛳️ Current behavior (updates)

Press / onClick events are not working on menu based components like Listbox / Dropdown / Menu / Etc

🚀 New behavior

Press events fixed

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

📝 Additional Information

Summary by CodeRabbit

  • New Features

    • Enhanced dropdown menus with closeOnSelect and onClose options for better user control.
    • Introduced new package @nextui-org/use-aria-menu for improved menu accessibility and behavior.
  • Bug Fixes

    • Addressed issues with dropdown and menu handling through internal updates.
  • Documentation

    • Added README for @nextui-org/use-aria-menu detailing internal utility components.
  • Tests

    • Implemented new tests for event handling in menu components ensuring robust interaction capabilities.
  • Refactor

    • Updated event handling in menu items for enhanced responsiveness and user experience.
    • Reorganized imports and dependencies across menu components for streamlined functionality.

Copy link

changeset-bot bot commented Apr 16, 2024

🦋 Changeset detected

Latest commit: 70bd1b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@nextui-org/dropdown Patch
@nextui-org/menu Patch
@nextui-org/use-aria-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 Apr 16, 2024

Walkthrough

This set of changes primarily enhances the handling of press events in dropdown and menu components within the NextUI framework. It introduces new hooks for better ARIA compliance and revises existing components to improve interaction handling. The updates address specific bugs related to event handling in dropdown items, ensuring that press events are effectively managed and that components close correctly upon selection.

Changes

File Path Change Summary
.../dropdown/src/use-dropdown.ts Added closeOnSelect and onClose to props, enhancing control over menu actions and closing behavior.
.../dropdown/stories/dropdown.stories.tsx Removed onAction prop from DropdownMenu, altering action handling within the menu.
.../menu/__tests__/menu.test.tsx Added tests for event handling in Menu items, using Jest and React Testing Library.
.../menu/package.json Included new dependencies for better menu handling.
.../menu/src/use-menu-item.ts Updated event handling and imports, integrating useAriaMenuItem.
.../menu/src/use-menu.ts Reorganized imports and adjusted menu functionality imports.
.../use-aria-menu/... Multiple files added or updated to support ARIA-compliant menu behaviors and interactions, including the introduction of new hooks and utilities.

Assessment against linked issues

Objective Addressed Explanation
DropdownItem onPress not working [#2743]
onPress, onPressStart, onPressEnd, onPressChange, onPressUp not working in DropdownItem [#2751]
Proper handling of closeOnSelect behavior [#2743]
Integration of ARIA standards in menu components [#2743, #2751]
Ensure dropdown closes correctly after selection [#2743]

The changes effectively address the issues reported in #2743 and #2751, focusing on improving event handling and ARIA compliance in dropdown and menu components. The updates ensure that press events are managed correctly and that components behave as expected upon user interactions.


Recent Review Details

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 4ca6e2c and 70bd1b9.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (13)
  • .changeset/healthy-parents-brake.md (1 hunks)
  • packages/components/dropdown/src/use-dropdown.ts (1 hunks)
  • packages/components/dropdown/stories/dropdown.stories.tsx (1 hunks)
  • packages/components/menu/tests/menu.test.tsx (2 hunks)
  • packages/components/menu/package.json (2 hunks)
  • packages/components/menu/src/use-menu-item.ts (6 hunks)
  • packages/components/menu/src/use-menu.ts (1 hunks)
  • packages/hooks/use-aria-menu/README.md (1 hunks)
  • packages/hooks/use-aria-menu/package.json (1 hunks)
  • packages/hooks/use-aria-menu/src/index.ts (1 hunks)
  • packages/hooks/use-aria-menu/src/use-menu-item.ts (1 hunks)
  • packages/hooks/use-aria-menu/src/use-menu.ts (1 hunks)
  • packages/hooks/use-aria-menu/tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/hooks/use-aria-menu/src/index.ts
  • packages/hooks/use-aria-menu/tsconfig.json
Additional Context Used
LanguageTool (3)
.changeset/healthy-parents-brake.md (1)

Near line 7: Possible spelling mistake found.
Context: ...s down the press events and control the pressUp one

packages/hooks/use-aria-menu/README.md (2)

Near line 3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/use-aria-menu-item A Quick description of the component > This is...


Near line 17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...aria-menu-item ``` ## Contribution Yes please! See the [contributing guidelines](http...

Additional comments not posted (15)
packages/hooks/use-aria-menu/README.md (1)

3-3: Consider using "Brief description of the component" for clarity and conciseness.

packages/components/menu/package.json (1)

48-48: Ensure the version specification for @nextui-org/use-aria-menu matches the expected version range.

packages/hooks/use-aria-menu/src/use-menu.ts (1)

45-47: Ensure accessibility labels are provided. Consider throwing an error or providing a default label if none is provided.

packages/components/dropdown/src/use-dropdown.ts (1)

142-146: Ensure that the onMenuAction function correctly handles the menuCloseOnSelect parameter and respects the closeOnSelect property.

packages/components/menu/src/use-menu-item.ts (1)

82-93: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [72-90]

Verify the new press-related event handlers (onPressStart, onPressUp, onPressEnd, onPressChange) are correctly implemented and triggered in the appropriate scenarios.

packages/hooks/use-aria-menu/src/use-menu-item.ts (6)

54-54: Deprecation notice for isDisabled property.

The isDisabled property is marked as deprecated. Ensure that all references in the codebase are updated to use the new recommended approach.


60-60: Deprecation notice for isSelected property.

The isSelected property is marked as deprecated. Ensure that all references in the codebase are updated to use the new recommended approach.


72-72: Deprecation notice for onClose handler.

The onClose handler is marked as deprecated. Ensure that all references in the codebase are updated to use the new recommended approach.


87-87: Deprecation notice for onAction handler.

The onAction handler is marked as deprecated. Ensure that all references in the codebase are updated to use the new recommended approach.


144-144: Conditional assignment of onAction might lead to unexpected behavior.

The onAction is conditionally set to an empty function if isTrigger is true, which might lead to unexpected behavior where no action is performed even if an action handler is provided. Verify this logic to ensure it aligns with intended behavior.


312-340: Return structure of useMenuItem hook.

The return structure of the useMenuItem hook is well-organized and provides a clear interface for the menu item properties.

packages/components/menu/__tests__/menu.test.tsx (3)

278-299: Ensure onAction event is dispatched correctly.

The test verifies that the onAction event is dispatched correctly when a menu item is clicked. This is crucial for ensuring that the event handling logic is functioning as expected.


301-324: Check for non-dispatch of onAction when item is disabled.

The test correctly checks that the onAction event is not dispatched when the menu item is disabled. This is important for ensuring that disabled items do not trigger actions.


326-353: Test for multiple event dispatches on menu item interaction.

The test ensures that onPress, onAction, and onClick events are all dispatched correctly when a menu item is interacted with. This comprehensive testing is essential for verifying complex interactions.

packages/components/dropdown/stories/dropdown.stories.tsx (1)

140-140: Removal of onAction prop from DropdownMenu.

The onAction prop has been removed from the DropdownMenu component. This change aligns with the new event handling strategy mentioned in the PR description. Ensure that this change is reflected across all relevant parts of the application.


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

vercel bot commented Apr 16, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 🛑 Canceled (Inspect) Apr 18, 2024 2:24am
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2024 2:24am

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: 5

} = props;

let isTrigger = !!hasPopup;
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Usage of @ts-ignore to bypass TypeScript checks.

Avoid using @ts-ignore as it bypasses TypeScript's static type checking. If there are type issues, consider fixing them or using more specific TypeScript utilities like type assertions or conditional types.

let isSelected = props.isSelected ?? state.selectionManager.isSelected(key);
let data = menuData.get(state);
// @ts-ignore
let onClose = props.onClose || data.onClose;
Copy link
Contributor

Choose a reason for hiding this comment

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

Usage of @ts-ignore to bypass TypeScript checks.

Repeated use of @ts-ignore can lead to potential bugs going unnoticed. Review the necessity of this and consider alternatives.

Comment on lines +207 to +223
setTimeout(() => {
performAction(e);
});
// // Pressing a menu item should close by default in single selection mode but not multiple
// // selection mode, except if overridden by the closeOnSelect prop.
if (
!isTrigger &&
onClose &&
(closeOnSelect ??
(state.selectionManager.selectionMode !== "multiple" ||
// @ts-ignore
state.selectionManager.isLink(key)))
) {
setTimeout(() => {
onClose?.();
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Delay in action performance and menu closure.

Using setTimeout to delay the execution of performAction and onClose might lead to a less responsive user experience. Consider alternatives that do not involve arbitrary delays.

"@nextui-org/use-aria-menu": patch
---

Fix #2743 #2751 internal react-aria use-menu hooks implemented to pass down the press events and control the pressUp one
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the spelling mistake in "pressUp".

- control the pressUp one
+ control the `pressUp` one

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Fix #2743 #2751 internal react-aria use-menu hooks implemented to pass down the press events and control the pressUp one
Fix #2743 #2751 internal react-aria use-menu hooks implemented to pass down the press events and control the `pressUp` one


## Contribution

Yes please! See the
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comma after "Yes" for grammatical correctness.

- Yes please! See the
+ Yes, please! See the

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Yes please! See the
Yes, please! See the

@jrgarciadev jrgarciadev merged commit 6b56e43 into main Apr 18, 2024
8 checks passed
@jrgarciadev jrgarciadev deleted the fix/2743 branch April 18, 2024 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant