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: onSelectionChange type incorrect #2567

Closed
wants to merge 1 commit into from

Conversation

winchesHe
Copy link
Member

@winchesHe winchesHe commented Mar 22, 2024

Closes #2512

📝 Description

  1. Complete the Selection type add addtional key like as shown in the picture below
image
  1. Optimize official docs description

Add a brief description

⛳️ 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

  • Documentation
    • Updated documentation for dropdown and select components to reflect new type usage for keys and updated onSelectionChange handler specifications.
  • New Features
    • Enhanced selection handling in menu and select components with more specific type signatures and extended Selection type to include anchorKey and currentKey.

@winchesHe winchesHe requested a review from jrgarciadev as a code owner March 22, 2024 04:02
Copy link

changeset-bot bot commented Mar 22, 2024

🦋 Changeset detected

Latest commit: af5788d

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

This PR includes changesets to release 27 packages
Name Type
@nextui-org/dropdown Patch
@nextui-org/menu Patch
@nextui-org/select Patch
@nextui-org/system-rsc Patch
@nextui-org/navbar Patch
@nextui-org/react Patch
@nextui-org/badge Patch
@nextui-org/code Patch
@nextui-org/divider Patch
@nextui-org/kbd Patch
@nextui-org/skeleton Patch
@nextui-org/spacer Patch
@nextui-org/spinner Patch
@nextui-org/system Patch
@nextui-org/accordion Patch
@nextui-org/listbox Patch
@nextui-org/table Patch
@nextui-org/autocomplete Patch
@nextui-org/button Patch
@nextui-org/modal Patch
@nextui-org/popover Patch
@nextui-org/slider Patch
@nextui-org/snippet Patch
@nextui-org/tabs Patch
@nextui-org/tooltip Patch
@nextui-org/aria-utils Patch
@nextui-org/framer-transitions 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 Mar 22, 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 Apr 15, 2024 1:48pm

Copy link

vercel bot commented Mar 22, 2024

@winchesHe 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 Mar 22, 2024

Walkthrough

The updates aim to enhance selection management in dropdowns, selects, and menus by transitioning to Iterable<React.Key> for selection keys, refining onSelectionChange handlers, and extending the Selection type with new properties. These changes improve specificity and flexibility in handling selections within the components.

Changes

Files Change Summary
.../docs/components/dropdown.mdx, .../docs/components/select.mdx Updated components to use Iterable<React.Key> for selectedKeys, disabledKeys, and defaultSelectedKeys, and refined onSelectionChange handlers.
.../components/menu/src/use-menu.ts Added onSelectionChange handler to Props interface for handling selection changes.
.../components/select/src/use-select.ts Updated selection handling with the import of Selection, added onSelectionChange to Props, and modified UseSelectProps to exclude onSelectionChange from MultiSelectProps.
.../core/system-rsc/src/types.ts Extended the Selection type with anchorKey and currentKey properties for enhanced selection management.

Assessment against linked issues

Objective Addressed Explanation
DropdownMenu component onSelectionChange type corrected (Issue #2512) The changes ensure the onSelectionChange handler in the DropdownMenu component now aligns with the correct type for keys as per the issue description.

Recent Review Details

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between abf532b and af5788d.
Files selected for processing (6)
  • .changeset/chilled-worms-develop.md (1 hunks)
  • apps/docs/content/docs/components/dropdown.mdx (2 hunks)
  • apps/docs/content/docs/components/select.mdx (2 hunks)
  • packages/components/menu/src/use-menu.ts (2 hunks)
  • packages/components/select/src/use-select.ts (2 hunks)
  • packages/core/system-rsc/src/types.ts (2 hunks)
Additional comments not posted (9)
packages/core/system-rsc/src/types.ts (2)

5-5: Ensure that the import path is correct and that the module @react-types/shared exports a Selection type.


85-88: The new type ShardSelection is well-defined and correctly extends AriaSharedSelection. Consider adding a brief comment describing the purpose of anchorKey and currentKey properties for better maintainability.

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

87-87: Ensure that the type ShardSelection is correctly used here. Verify that it meets the requirements for the onSelectionChange handler in this context.

Verification successful

The verification process has confirmed that the type ShardSelection is used consistently within the packages/components directory. It is utilized in both the use-select.ts and use-menu.ts files, specifically in the context of an onSelectionChange handler, which suggests that its usage is appropriate and meets the requirements for this handler in the context of the components where it is implemented.

Conclusion: The use of ShardSelection in the onSelectionChange handler within use-menu.ts is consistent with its usage in other parts of the project.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the usage of ShardSelection in other parts of the project to ensure consistency
rg --type typescript $'ShardSelection' -- packages/components

Length of output: 95



Script:

#!/bin/bash
# Correcting the file type and re-verifying the usage of ShardSelection in other parts of the project to ensure consistency
rg 'ShardSelection' --type ts -- packages/components

Length of output: 433

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

131-131: Ensure that the type ShardSelection is correctly used here. Verify that it meets the requirements for the onSelectionChange handler in this context.

Verification successful

The attempt to verify the usage of ShardSelection in the project using rg failed due to an unrecognized file type error. This indicates a need to correct the script to properly search TypeScript files. Let's correct this and re-run the script to ensure that ShardSelection is used consistently across the project.


The corrected script has successfully identified the usage of ShardSelection in the project. It is used in both use-select.ts and use-menu.ts within the packages/components directory. In both files, ShardSelection is used as a type for the parameter keys in the onSelectionChange handler. This confirms that the type ShardSelection is consistently used across different components for similar functionalities.

Based on this information, the usage of ShardSelection in the onSelectionChange handler in use-select.ts is verified as correct and consistent with other parts of the project.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the usage of ShardSelection in other parts of the project to ensure consistency
rg --type typescript $'ShardSelection' -- packages/components

Length of output: 95



Script:

#!/bin/bash
# Correcting the file type issue and re-verifying the usage of ShardSelection in the project
rg 'ShardSelection' --type ts -- packages/components

Length of output: 433

apps/docs/content/docs/components/select.mdx (4)

341-341: Change of type for selectedKeys from React.Key[] to Iterable<React.Key> enhances flexibility in handling keys.


342-342: Change of type for disabledKeys from React.Key[] to Iterable<React.Key> supports better flexibility in specifying disabled items.


343-343: Change of type for defaultSelectedKeys from React.Key[] to Iterable<React.Key> improves consistency and flexibility in initial selection handling.


382-382: Updated onSelectionChange callback signature to include anchorKey and currentKey enhances the handling of selection changes, aligning with the PR's focus on improving selection management.

apps/docs/content/docs/components/dropdown.mdx (1)

308-316: > 📝 NOTE

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

Update the onSelectionChange event handler to include the new properties anchorKey and currentKey as optional.

The updated type signature for onSelectionChange now includes anchorKey and currentKey properties, enhancing the detail and functionality of selection handling.


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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between fb06254 and 964d12b.
Files selected for processing (5)
  • apps/docs/content/docs/components/dropdown.mdx (2 hunks)
  • apps/docs/content/docs/components/select.mdx (2 hunks)
  • packages/components/menu/src/use-menu.ts (2 hunks)
  • packages/components/select/src/use-select.ts (2 hunks)
  • packages/core/system-rsc/src/types.ts (2 hunks)
Additional comments: 11
packages/core/system-rsc/src/types.ts (2)
  • 5-5: The import statement for Selection from @react-types/shared is correctly added.
  • 85-88: Extending the Selection type with anchorKey and currentKey properties is a good enhancement for representing selection states more accurately.
packages/components/menu/src/use-menu.ts (2)
  • 84-87: Adding the onSelectionChange handler to the Props interface with the Selection type as its parameter is a good enhancement for handling selection changes.
  • 92-92: Correctly omitting the onSelectionChange property from AriaMenuProps<T> in the UseMenuProps type aligns with the PR objectives for handling selection changes more effectively.
packages/components/select/src/use-select.ts (3)
  • 4-9: The import statement correctly imports Selection among other types from @nextui-org/system, which is necessary for the changes made in this file.
  • 128-131: Adding the onSelectionChange handler to the Props interface with the Selection type as its parameter is a good enhancement for handling selection changes in the select component.
  • 134-138: Correctly modifying the UseSelectProps type to exclude onSelectionChange from MultiSelectProps aligns with the PR objectives for handling selection changes more effectively in the select component.
apps/docs/content/docs/components/select.mdx (2)
  • 341-343: The type definitions for selectedKeys, disabledKeys, and defaultSelectedKeys have been updated to use Iterable<React.Key> instead of React.Key[]. This change aligns with the PR objectives to improve type safety and flexibility in handling selections. Ensure that all related components and functions that interact with these properties are updated accordingly to handle the Iterable type.
  • 382-382: The onSelectionChange event handler's type signature has been updated to expect a more detailed parameter type, including anchorKey and currentKey. This enhancement is crucial for providing a more accurate representation of selection states and aligns with the PR objectives. Ensure that the implementation of this handler across the library correctly handles the new type structure.
apps/docs/content/docs/components/dropdown.mdx (2)
  • 311-313: The type definitions for selectedKeys, disabledKeys, and defaultSelectedKeys have been updated to use Iterable<React.Key> instead of React.Key[]. This change enhances flexibility in handling selections by allowing any iterable object, not just arrays, to represent selected or disabled keys. This is a positive change that aligns with the PR objectives to improve type safety and flexibility.
  • 332-332: The onSelectionChange handler's type signature has been updated to expect a more specific type, including anchorKey and currentKey properties. This change is in line with the PR objectives to correct and enhance type definitions, providing a more detailed and functional representation of selection states. It's a significant improvement for developers managing selections with greater precision.

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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 964d12b and a91b10e.
Files selected for processing (1)
  • .changeset/chilled-worms-develop.md (1 hunks)

.changeset/chilled-worms-develop.md Outdated Show resolved Hide resolved
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.

Error: @nextui-org/react:build: src/index.ts(28,1): error TS2308: Module "@nextui-org/system" has already exported a member named 'Selection'. Consider explicitly re-exporting to resolve the ambiguity.

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

Actionable comments outside the diff hunks (1)
apps/docs/content/docs/components/dropdown.mdx (1)

Line range hint 5-5: Ensure the sentence starts with an uppercase letter for consistency.

- Displays a list of actions or options that a user can choose.
+ Displays a list of actions or options that a user can choose.

.changeset/chilled-worms-develop.md Show resolved Hide resolved
@winchesHe winchesHe closed this Apr 15, 2024
@winchesHe winchesHe reopened this Apr 15, 2024
@winchesHe winchesHe marked this pull request as draft April 15, 2024 14:30
@jrgarciadev jrgarciadev removed this from the v2.3.0 milestone Apr 16, 2024
@wingkwong wingkwong changed the base branch from main to canary April 28, 2024 14:52
@winchesHe winchesHe closed this Jun 26, 2024
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] - DropdownMenu component onSelectionChange type not correct.
3 participants