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 #3336

Merged
merged 6 commits into from
Jul 6, 2024
Merged

Conversation

winchesHe
Copy link
Member

@winchesHe winchesHe commented Jun 26, 2024

Closes #2512

📝 Description

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

image

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

  • New Features

    • Improved selection management in dropdown and select components with enhanced onSelectionChange handling.
  • Bug Fixes

    • Updated types for various selection properties for more robust and flexible selection handling.
  • Refactor

    • Consolidated selection-related types and handlers for better maintainability and consistency across components.
  • Documentation

    • Updated documentation to reflect changes in selection properties and handlers for dropdown and select components.

Copy link

changeset-bot bot commented Jun 26, 2024

🦋 Changeset detected

Latest commit: 92f8703

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/code Patch
@nextui-org/divider Patch
@nextui-org/kbd 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/calendar Patch
@nextui-org/date-picker 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-utils 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 Jun 26, 2024

Walkthrough

This change primarily updates the typing for selection-related properties in dropdown, select, and menu components to be more accurate and flexible, shifting from React.Key[] to Iterable<React.Key>. It also modifies the signature of the onSelectionChange callback functions to include additional key properties.

Changes

Files/Components Change Summary
docs/components/dropdown.mdx, docs/components/select.mdx Change types of selectedKeys, disabledKeys, defaultSelectedKeys to Iterable<React.Key>. Update onSelectionChange callback signature.
packages/components/menu/src/use-menu.ts, packages/components/select/src/use-select.ts Introduce SharedSelection type and update Props interfaces to include onSelectionChange handler accepting SharedSelection.
packages/core/system-rsc/src/index.ts, packages/core/system-rsc/src/types.ts, packages/core/system/src/index.ts Add and export SharedSelection type, extending Selection from @react-types/shared with anchorKey and currentKey.

Sequence Diagram(s)

(No significant new feature or control flow changes warranting a sequence diagram.)

Assessment against linked issues

Objective (Issue #2512) Addressed Explanation
Correct typing for onSelectionChange in DropdownMenu component
Ensure selectedKeys adheres to updated typing

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

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 Jun 26, 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 Jul 6, 2024 2:49pm
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 6, 2024 2:49pm

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.

ShardSelection

Wondering if you mean SharedSelection?

@wingkwong wingkwong added this to the v2.4.3 milestone Jun 27, 2024
@winchesHe winchesHe closed this Jun 28, 2024
@winchesHe winchesHe reopened this Jun 28, 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

Outside diff range and nitpick comments (1)
packages/core/system-rsc/src/types.ts (1)

Line range hint 32-33: Replace generic object types with explicit definitions.

The use of {} as a type is discouraged as it allows any non-nullish value. Prefer defining explicit shapes for better type safety.

- type RightJoinProps<SourceProps extends object = {}, OverrideProps extends object = {}> = ...
+ type RightJoinProps<SourceProps extends Record<string, any> = {}, OverrideProps extends Record<string, any> = {}> = ...

Also applies to: 33-34, 39-40, 47-48

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 78d4216 and 40f93f0.

Files selected for processing (8)
  • .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 (3 hunks)
  • packages/core/system-rsc/src/index.ts (1 hunks)
  • packages/core/system-rsc/src/types.ts (2 hunks)
  • packages/core/system/src/index.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/core/system-rsc/src/index.ts
  • packages/core/system/src/index.ts
Additional context used
Biome
packages/core/system-rsc/src/types.ts

[error] 32-33: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 33-34: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 39-40: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 47-48: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

LanguageTool
apps/docs/content/docs/components/select.mdx

[grammar] ~9-~9: The plural noun “displays” cannot be used with the article “A”. Did you mean “A select display” or “select displays”?
Context: .../content/components/select"; # Select A select displays a collapsible list of options and allow...

(A_NNS)


[uncategorized] ~122-~122: Did you mean: “By default,”?
Context: ...tContent} /> ### Custom Selector Icon By default the select uses a chevron-down icon a...

(BY_DEFAULT_COMMA)


[uncategorized] ~131-~131: You might be missing the article “the” here.
Context: ...f the icon. ### Without Scroll Shadow Select component uses the [ScrollShadow](/docs...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~176-~176: Did you mean: “By default,”?
Context: ...stomItems} /> ### Custom Render Value By default the select will render the selected ite...

(BY_DEFAULT_COMMA)


[grammar] ~186-~186: The name of this game or TV show is spelled with an accent.
Context: ...e are using a custom hook to fetch the Pokemon API...

(POKEMON)


[typographical] ~248-~248: It appears that a comma is missing.
Context: ...ing the renderValue property. In this example we are using the [Chip](/docs/component...

(DURING_THAT_TIME_COMMA)


[uncategorized] ~260-~260: You might be missing the article “the” here.
Context: ...ect by using the classNames property. Select component also provides the [popoverPro...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[style] ~339-~339: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...pport for selecting multiple options. - Support for disabled options. - Support for sec...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~340-~340: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ions. - Support for disabled options. - Support for sections. - Labeling support for ac...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[typographical] ~359-~359: Consider adding a comma after ‘Usually’ for more clarity.
Context: ... | The children to render. Usually a list of SelectItem and `SelectSecti...

(RB_LY_COMMA)


[grammar] ~374-~374: In this case, the usual preposition with “side” is “on”, not “in”. Did you mean “on the left side”?
Context: ... | Element to be rendered in the left side of the select. ...

(IN_ON_THE_RIGHT_HAND_SIDE)


[grammar] ~375-~375: In this case, the usual preposition with “side” is “on”, not “in”. Did you mean “on the right side”?
Context: ... | Element to be rendered in the right side of the select. ...

(IN_ON_THE_RIGHT_HAND_SIDE)

apps/docs/content/docs/components/dropdown.mdx

[uncategorized] ~50-~50: Loose punctuation mark.
Context: ...ropdownItem } from "@nextui-org/react";, individual: import { Dropdown, ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~57-~57: Loose punctuation mark.
Context: ...downItem } from "@nextui-org/dropdown";`, }} /> ## Usage <CodeDemo title="Usa...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~66-~66: Possible missing article found.
Context: ...wnContent.usage} /> ### Dynamic items Dropdown follows the [Collection Components API]...

(AI_HYDRA_LEO_MISSING_A)


[typographical] ~80-~80: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...important to have a unique key for each item, otherwise the disabled keys will not work. ### A...

(THUS_SENTENCE)


[uncategorized] ~165-~165: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...m>` component works with frameworks and client side routers like [Next.js](https://nextjs.o...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[misspelling] ~246-~246: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...starts with the typed character if such an menu item exists. | <Spacer y={4...

(EN_A_VS_AN)


[style] ~274-~274: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ection. - Support for disabled items. - Support for sections. - Complex item labeling s...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[typographical] ~290-~290: Consider adding a comma after ‘Usually’ for more clarity.
Context: ... | The children to render. Usually a DropdownTrigger and DropdownMenu ...

(RB_LY_COMMA)


[style] ~303-~303: This phrase is redundant. Consider using “outside”.
Context: ...ser interacts with the argument element outside of the dropdown ref, return true if `onC...

(OUTSIDE_OF)


[typographical] ~355-~355: Consider adding a comma after ‘Usually’ for more clarity.
Context: ...| The contents of the dropdown section. Usually a list of DropdownItem components. (s...

(RB_LY_COMMA)

Additional comments not posted (13)
.changeset/chilled-worms-develop.md (2)

2-5: Patch updates listed correctly.

The changeset correctly identifies the affected packages and specifies the type of change as a patch, which is appropriate given the nature of the changes (type fixes and enhancements).


8-8: Clear summary of changes.

The summary "Fix onSelectionChange type incorrect" concisely captures the essence of the changes made in this PR.

packages/core/system-rsc/src/types.ts (2)

5-5: Import of AriaSharedSelection is appropriate.

The import from @react-types/shared is necessary for extending the SharedSelection type, which aligns with the PR's objectives to correct the type definitions.


85-88: Definition of SharedSelection type.

The SharedSelection type correctly extends AriaSharedSelection with optional anchorKey and currentKey, which matches the new requirements for the onSelectionChange callback across various components.

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

92-92: Addition of onSelectionChange handler is appropriate.

The introduction of the onSelectionChange handler with the type SharedSelection in the Props interface correctly aligns with the PR's objectives to standardize the type definitions across components.


97-97: Correct omission of onSelectionChange from AriaMenuProps.

Omitting onSelectionChange from AriaMenuProps while including it in the custom UseMenuProps ensures that the custom handler is used, which supports the new SharedSelection type.

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

135-135: Addition of onSelectionChange handler is appropriate.

The introduction of the onSelectionChange handler with the type SharedSelection in the Props interface correctly aligns with the PR's objectives to standardize the type definitions across components.

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

362-364: Documentation update for selectedKeys, disabledKeys, and defaultSelectedKeys.

The documentation correctly updates the types for selectedKeys, disabledKeys, and defaultSelectedKeys to Iterable<React.Key>, reflecting the changes made in the PR.


403-403: Updated onSelectionChange documentation.

The updated documentation for onSelectionChange accurately reflects the new callback signature, including anchorKey and currentKey, aligning with the changes made in the related components.

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

325-325: Type change for selectedKeys prop enhances flexibility.

The update from React.Key[] to Iterable<React.Key> allows for more versatile collections of keys, supporting not just arrays but also other iterable types like Set or Map keys. This change is beneficial for developers looking to use different data structures.


326-326: Consistent type enhancement for disabledKeys prop.

Changing the type from React.Key[] to Iterable<React.Key> aligns this prop with the updated selectedKeys prop, ensuring consistency across the component API. This change facilitates the use of various iterable types, enhancing flexibility.


327-327: Uniform type update for defaultSelectedKeys prop.

Updating the type from React.Key[] to Iterable<React.Key> aligns this prop with the selectedKeys and disabledKeys props, maintaining consistency and flexibility in the component's API. This uniform approach is beneficial for developers.


346-346: Enhanced functionality in onSelectionChange callback.

The updated type (keys: "all" | Set<React.Key> & {anchorKey?: string; currentKey?: string}) for the onSelectionChange callback reflects the actual behavior of the component, providing developers with more detailed information about the selection context. This change improves the API's accuracy and usability.

@winchesHe
Copy link
Member Author

ShardSelection

Wondering if you mean SharedSelection?

Fixed 🫰

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.

A few more comments

.changeset/chilled-worms-develop.md Outdated Show resolved Hide resolved
packages/components/menu/src/use-menu.ts Outdated Show resolved Hide resolved
packages/components/menu/src/use-menu.ts Outdated Show resolved Hide resolved
@winchesHe
Copy link
Member Author

fixed

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 40f93f0 and 8f263da.

Files selected for processing (3)
  • .changeset/chilled-worms-develop.md (1 hunks)
  • packages/components/menu/src/use-menu.ts (2 hunks)
  • packages/components/select/src/use-select.ts (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • .changeset/chilled-worms-develop.md
  • packages/components/menu/src/use-menu.ts
  • packages/components/select/src/use-select.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 8f263da and 92f8703.

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

9-9: Import statement for SharedSelection looks good.

The import statement for SharedSelection from @nextui-org/system is correctly added.


132-135: Addition of onSelectionChange property to Props interface looks good.

The onSelectionChange property is correctly defined as an optional function with the type (keys: SharedSelection) => void.


147-151: Update to UseSelectProps type looks good.

The UseSelectProps type correctly omits onSelectionChange from MultiSelectProps and includes the new Props interface.


153-153: Changes to useSelect function look good.

The useSelect function correctly handles the onSelectionChange callback with the SharedSelection type.

@jrgarciadev jrgarciadev merged commit 0cdfdb4 into canary Jul 6, 2024
8 checks passed
@jrgarciadev jrgarciadev deleted the bugfix-selection-type branch July 6, 2024 18:01
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