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(table): Add an isKeyboardNavigationDisabled prop to disable the navigation #3735

Open
wants to merge 5 commits into
base: canary
Choose a base branch
from

Conversation

macci001
Copy link
Contributor

@macci001 macci001 commented Sep 10, 2024

Closes #3681

📝 Description

PR adds isKeyboardNavigationDisabled prop to disable navigation on keypress

⛳️ Current behavior (updates)

  • Currently, whenever any arrow-key keypress is triggered it navigates the focus to other cell/row.
  • This maybe an issue when the table cell contains a component which requires this keys for specific purpose.
  • Example for above scenario could be: table cell contains input component, it might need arrow keys for editing. But it is not possible because whenever the keypress triggers navigation
Screen.Recording.2024-09-10.at.4.11.24.PM.mov

🚀 New behavior

  • The PR adds an isKeyboardNavigationDisabled prop to disable the navigation through keyboard.
Screen.Recording.2024-09-10.at.4.26.36.PM.mov

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

Additional info

  • updated the docs
Screenshot 2024-09-10 at 4 34 44 PM

Summary by CodeRabbit

  • New Features

    • Introduced isKeyboardNavigationDisabled prop for the Table component, allowing users to disable keyboard navigation when interacting with components that require arrow key inputs.
  • Documentation

    • Updated Table component documentation to include details about the new isKeyboardNavigationDisabled prop.
  • Tests

    • Added a test case to verify the functionality of the isKeyboardNavigationDisabled prop, ensuring keyboard navigation is disabled when the prop is set to true.

Copy link

changeset-bot bot commented Sep 10, 2024

🦋 Changeset detected

Latest commit: 87335e4

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/table 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

vercel bot commented Sep 10, 2024

Someone 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 Sep 10, 2024

Walkthrough

This update introduces a new prop, isKeyboardNavigationDisabled, to the Table component in the @nextui-org/table package. This prop allows developers to disable keyboard navigation within table cells, particularly beneficial for inputs or text areas that require arrow key usage. The change includes updates to the documentation, implementation in the useTable function, and additional test cases to ensure the new functionality works as intended.

Changes

Files Change Summary
.changeset/fluffy-icons-refuse.md, apps/docs/content/docs/components/table.mdx Added isKeyboardNavigationDisabled prop to the Table component and updated documentation.
packages/components/table/src/use-table.ts Introduced isKeyboardNavigationDisabled in Props interface and modified useTable function.
packages/components/table/tests/table.test.tsx Added test case to verify keyboard navigation is disabled when isKeyboardNavigationDisabled is true.

Assessment against linked issues

Objective Addressed Explanation
Allow inline editing without navigation to the next cell (Issue #3681)

Tip

Announcements
  • The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
  • We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c2c3534 and 87335e4.

Files selected for processing (4)
  • .changeset/fluffy-icons-refuse.md (1 hunks)
  • apps/docs/content/docs/components/table.mdx (1 hunks)
  • packages/components/table/tests/table.test.tsx (2 hunks)
  • packages/components/table/src/use-table.ts (3 hunks)
Additional comments not posted (5)
.changeset/fluffy-icons-refuse.md (1)

1-5: LGTM!

The changeset file accurately describes the changes made in the PR.

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

99-133: LGTM!

The new test case is well-written and covers the expected behavior of disabling keyboard navigation when isKeyboardNavigationDisabled prop is set to true.

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

93-97: LGTM!

The new prop isKeyboardNavigationDisabled is correctly added to the Props interface.


167-167: LGTM!

The useTable function correctly updates the state to disable keyboard navigation when the isKeyboardNavigationDisabled prop is set to true.

Also applies to: 195-197

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

460-460: Documentation looks good!

The isKeyboardNavigationDisabled prop is clearly documented with the correct type, description, and default value.


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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@AnYiEE
Copy link
Contributor

AnYiEE commented Sep 10, 2024

I think a better solution is to automatically disable keyboard navigation temporarily when the focus is on the input, so that can move the cursor with the keyboard and use the Tab key to navigate to other elements of the table after leaving the input.

@macci001
Copy link
Contributor Author

Thanks for the suggestion @AnYiEE. But I do not think it would be a great idea to write in a logic that checks if component is input component then stop the keyboard navigation.
One work-around which I thought could be helpful is rather than adding a prop isKeyboardNavigationDisabled to the table, we can add this prop to any of the cell. If any cell with isKeyboardNavigationDisabled as true, keyboard navigation will be stopped when then cell is in focus.

any thoughts here @wingkwong, should we go forward with adding the prop to the Table or it would be helpful to add the functionality to the TableCell instead.

@macci001 macci001 changed the title Add an isKeyboardNavigationDisabled prop to disable the navigation fix(table): Add an isKeyboardNavigationDisabled prop to disable the navigation Sep 11, 2024
@soyeon9211
Copy link

@macci001 Is it not merge yet? I need this option :(

@macci001
Copy link
Contributor Author

macci001 commented Oct 7, 2024

@wingkwong can I please get in some review here?

Copy link
Member

@ryo-manba ryo-manba left a comment

Choose a reason for hiding this comment

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

Ideally, I think it would be best to add an edit mode to the table. Since the React Spectrum team is working on this, we can either wait for them to fix it or implement it ourselves.

@macci001
Copy link
Contributor Author

macci001 commented Oct 9, 2024

Reflecting on your comment @ryo-manba
I can think of following design for the edit mode:

  • In any of the cases, one when the cell has focusable children and other when cell do not have focusable children, always entire cell is focused. That is, focusMode set to cell instead of child.
  • Whenever there is Enter keypress on a focused cell:
    • If cell does have some focusable children:
      • Set the focus on the first/last focusable children (based on RTL)
      • Add the keyboard navigation on shift + leftarrowkey and shift + rightarrowkey for navigating to prev/next focusable children of the cell.
    • If cell does not have any focusable children -> do nothing i.e. edit mode is not relevant in this case.
  • Esc/Tab keypress to exit the edit mode.

Note 1: For navigation between focusable children of the cell, getFocusableTreeWalker will be used.

Note 2: For now, the useTableCell internally uses useGridCell's default value for focusMode i.e. child. This means, that whenever the cell will be in focus, the focus will shift to the focusableChild if it exist, else entire cell would be in focus. In order to implement the edit mode, we would need the react-aria team to add a prop by which we can set the focusMode to cell.

@ryo-manba
Copy link
Member

@macci001
Thank you for your detailed insights. I'll discuss it with the team and see how we can proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot perform inline editing of input/textarea if in table cell
5 participants