Skip to content

[Bug]: DataGrid onSelectionChange can trigger when the selection has not changed #35035

@evantrimboli

Description

@evantrimboli

Component

DataGrid

Package version

9.66.5

React version

18.2.0

Environment

System:
    OS: Windows 11 10.0.26100
    CPU: (28) x64 Intel(R) Core(TM) i7-14700K
    Memory: 26.18 GB / 63.77 GB
  Browsers:
    Edge: Chromium (139.0.3405.102)
    Internet Explorer: 11.0.26100.1882

Current Behavior

When clicking on an already selected row, onSelectionChange fires again with the same set of selected items.

The same behaviour also applies for the List component.

Expected Behavior

Either:

  • onSelectionChange should not trigger unless there is some actual change in selection.
  • The row should be deselected and onSelectionChange should trigger with 0 items.

Reproduction

https://stackblitz.com/edit/pxsuvgmu?file=src%2Fexample.tsx

Steps to reproduce

  1. Open: https://stackblitz.com/edit/pxsuvgmu?file=src%2Fexample.tsx
  2. Click "Foo" row in the grid. The selection change function runs, the current value is [] and the new value is [1].
  3. Click the "Foo" row in the grid a second time. The selection change function runs, the current value is [1] and the new value is [1]

Are you reporting an Accessibility issue?

None

Suggested severity

Medium - Has workaround

Products/sites affected

No response

Are you willing to submit a PR to fix?

yes

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions