nextui icon indicating copy to clipboard operation
nextui copied to clipboard

fix(table): Add an isKeyboardNavigationDisabled prop to disable the navigation

Open macci001 opened this issue 1 year ago • 9 comments

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 isKeyboardNavigationDisabled prop 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 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.

macci001 avatar Sep 10 '24 11:09 macci001

🦋 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

changeset-bot[bot] avatar Sep 10 '24 11:09 changeset-bot[bot]

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 10 '24 11:09 vercel[bot]

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 isKeyboardNavigationDisabled property 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?

❤️ 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>, 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 @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 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 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.

coderabbitai[bot] avatar Sep 10 '24 11:09 coderabbitai[bot]

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.

AnYiEE avatar Sep 10 '24 11:09 AnYiEE

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 avatar Sep 10 '24 13:09 macci001

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

soyeon9211 avatar Oct 07 '24 07:10 soyeon9211

@wingkwong can I please get in some review here?

macci001 avatar Oct 07 '24 08:10 macci001

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.

macci001 avatar Oct 09 '24 11:10 macci001

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

ryo-manba avatar Oct 13 '24 13:10 ryo-manba

Hey @macci001 please fix the conflicts

jrgarciadev avatar Nov 04 '24 21:11 jrgarciadev