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(select): disabled select shouldn't get update by keyboard #2649

Merged
merged 3 commits into from
Apr 14, 2024

Conversation

wingkwong
Copy link
Member

@wingkwong wingkwong commented Apr 5, 2024

Closes #2345

📝 Description

  • set all keys to disabled mode so that users cannot update a value in a disabled select

⛳️ Current behavior (updates)

Currently if you go to [disabled select storybook], click the background, then press tab, then press 'w', the value changes to Whale.

🚀 New behavior

The value shouldn't get updated if it is disabled

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

No

📝 Additional Information

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where disabled select components could still be changed using blur and keyboard shortcuts.
  • Tests
    • Added a test to verify that disabled select elements do not update via keyboard input.
  • Refactor
    • Modified state variable initialization in the select component for enhanced flexibility and reliability.

Copy link

changeset-bot bot commented Apr 5, 2024

🦋 Changeset detected

Latest commit: c4558a7

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

This PR includes changesets to release 2 packages
Name Type
@nextui-org/select 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 5, 2024

Walkthrough

The changes address a bug in the @nextui-org/select component where a disabled select element could still be updated using keyboard shortcuts or by blurring the element. The patch involves modifying the component's internal state management to respect the disabled state and prevent updates via keyboard inputs. A test case has also been added to ensure the fix's effectiveness, ensuring that disabled select elements remain immutable to user interactions that previously led to unintended behavior.

Changes

File Path Change Summary
.changeset/nervous-geckos-visit.md Introduces a patch fixing the disabled select update issue.
.../select/__tests__/select.test.tsx Adds a test case for the disabled select element.
.../select/src/use-select.ts Modifies state initialization and augmentation in useSelect.

Assessment against linked issues

Objective Addressed Explanation
Prevent disabled Select from changing value using blur + keyboard [#2345]

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/coderabbit-overrides.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 5, 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 6, 2024 7:55am

Copy link

vercel bot commented Apr 5, 2024

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

A member of the Team first needs to authorize it.

@wingkwong wingkwong changed the title fix(select): disable all keys for isDisabled case fix(select): Disabled Select Allows Changes Using Blur + Keyboard Apr 5, 2024
@wingkwong wingkwong changed the title fix(select): Disabled Select Allows Changes Using Blur + Keyboard fix(select): disabled select shouldn't get update by keyboard Apr 5, 2024
@wingkwong wingkwong marked this pull request as ready for review April 5, 2024 13:17
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 Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 6da144f and 032d306.
Files selected for processing (3)
  • .changeset/nervous-geckos-visit.md (1 hunks)
  • packages/components/select/tests/select.test.tsx (1 hunks)
  • packages/components/select/src/use-select.ts (2 hunks)
Additional comments not posted (3)
.changeset/nervous-geckos-visit.md (1)

1-5: LGTM! The changeset correctly specifies a patch version update and provides a clear description of the fix.

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

365-398: The new test case correctly ensures that a disabled select element does not update via keyboard input, adhering to best testing practices.

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

235-247: > 📝 NOTE

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

The modifications to the state variable initialization and its subsequent augmentation based on the disabled state of the select component are correctly implemented to address the issue described in the PR.

Copy link
Contributor

@ShrinidhiUpadhyaya ShrinidhiUpadhyaya left a comment

Choose a reason for hiding this comment

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

This disabledKeys: new Set([...state.collection.getKeys()].map((k) => k)), could be changed to disabledKeys: new Set([...state.collection.getKeys()]),. This map((k) => k) is redundant.

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 Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 032d306 and c4558a7.
Files selected for processing (1)
  • packages/components/select/src/use-select.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/components/select/src/use-select.ts

@wingkwong wingkwong added this to the v2.3.0 milestone Apr 7, 2024
@jrgarciadev jrgarciadev merged commit e458432 into nextui-org:main Apr 14, 2024
7 of 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] - Disabled Select Allows Changes Using Blur + Keyboard
3 participants