Skip to content

Ignore row clicks that select text in <DataTable> and <Datagrid> - #11482

Open
mshd wants to merge 1 commit into
marmelab:nextfrom
mshd:row-click-ignores-text-selection
Open

mshd wants to merge 1 commit into
marmelab:nextfrom
mshd:row-click-ignores-text-selection

Conversation

@mshd

@mshd mshd commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Problem

When a <DataTable> or <Datagrid> row is clickable, users can't select text in a cell to copy it: releasing the mouse after dragging across a value fires a click on the row, which redirects to the record (or expands / toggles it). Copying an id or an email from a list is a common need in admin apps.

Related: #10492 asked to pass the click event to rowClick so apps could detect this themselves. This PR fixes it for everyone instead, with no change needed in apps.

Solution

In DataTableRow and DatagridRow, the row stores the text selection on mousedown, and handleClick returns early when the selection is non-empty and differs from it, i.e. the click selected text. Clicking text that was already selected still activates the row. Double-click selection still activates the row on the first click.

How To Test

  1. Open the ra-ui-materialui/list/DataTable > FullApp story with rowClick set to show.
  2. Drag across a title to select part of it and release: the list stays, the text stays selected.
  3. Click the selected text: the record opens.
  4. Click a row without selecting: the record opens as before.

Unit tests: DataTable.spec.tsx and DatagridRow.spec.tsx each check that a click that selected text doesn't call rowClick, and that a click on text selected earlier does.

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why): the existing FullApp story with a rowClick value shows the behavior, so no new story was added
  • The documentation is up to date

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@ogroppo

ogroppo commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Would be a nice addition to have an option to add "copy to clipboard" on desired fields

This branch has not been deployed

No deployments
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.

2 participants