fix(table): Add an isKeyboardNavigationDisabled prop to disable the navigation
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
https://github.com/user-attachments/assets/61ae353d-cdca-4cbf-b12d-1146da371704
🚀 New behavior
- The PR adds an
isKeyboardNavigationDisabledprop to disable the navigation through keyboard.
https://github.com/user-attachments/assets/c05c084a-8caf-4959-aee8-102818220a0a
💣 Is this a breaking change (Yes/No): No
Additional info
- updated the docs
Summary by CodeRabbit
-
New Features
- Introduced
isKeyboardNavigationDisabledprop for the Table component, allowing users to disable keyboard navigation when interacting with components that require arrow key inputs.
- Introduced
-
Documentation
- Updated Table component documentation to include details about the new
isKeyboardNavigationDisabledprop.
- Updated Table component documentation to include details about the new
-
Tests
- Added a test case to verify the functionality of the
isKeyboardNavigationDisabledprop, ensuring keyboard navigation is disabled when the prop is set to true.
- Added a test case to verify the functionality of the
🦋 Changeset detected
Latest commit: 40a6706964d26ad56051cb4428ced832ad8a817f
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
Someone is attempting to deploy a commit to the NextUI Inc Team on Vercel.
A member of the Team first needs to authorize it.
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, ensuring that developers are informed about the new functionality.
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. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Allow inline editing without navigation to the next cell (Issue #3681) | ✅ |
Possibly related PRs
- #3020: This PR addresses keyboard behavior in input/textarea elements within a table, which is directly related to the new
isKeyboardNavigationDisabledproperty introduced in the main PR, as both involve keyboard navigation handling in table components. - #2097: This PR improves RTL support for the table component, which may relate to the keyboard navigation changes in the main PR, as keyboard navigation behavior can be affected by layout direction.
- #3419: This PR allows cursor navigation within text in an Input component inside an Accordion, which is relevant as it also deals with keyboard navigation and user input behavior in components similar to the changes made in the main PR.
Suggested labels
👀 Status: In Review
Suggested reviewers
- wingkwong
- ryo-manba
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?
🪧 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>, please review it.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
@coderabbitaiin 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
@coderabbitaiin 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere 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.
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.
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 Is it not merge yet? I need this option :(
@wingkwong can I please get in some review here?
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
cellinstead ofchild. - Whenever there is
Enterkeypress 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 + leftarrowkeyandshift + rightarrowkeyfor 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.
- If cell does have some focusable children:
Esc/Tabkeypress 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.
@macci001 Thank you for your detailed insights. I'll discuss it with the team and see how we can proceed.
Hey @macci001 please fix the conflicts