Skip to content

[data grid] Preference Panel state is not updated #17130

@vanderAries

Description

@vanderAries

Steps to reproduce

Use this code for custom toolbar:

import { IconButton } from "@mui/material";
import {
  GridColumnIcon,
  GridPreferencePanelsValue,
  GridToolbarContainer,
  useGridApiContext,
} from "@mui/x-data-grid-premium";

export const Toolbar = () => {
  const apiRef = useGridApiContext();
  const openColumnPanelHandler = () => {
    if (apiRef.current.state.preferencePanel.open) {
      apiRef.current.hidePreferences();
    } else {
      apiRef.current.showPreferences(GridPreferencePanelsValue.columns);
    }
  };
  return (
    <GridToolbarContainer>
      <IconButton
        data-cy="columns-preferences-button"
        onClick={openColumnPanelHandler}
      >
        <GridColumnIcon />
      </IconButton>
    </GridToolbarContainer>
  );
};

Add Toolbar to DataGrid as toolbar slot.

Current behavior

I'm using IconButton with GridColumnIcon, but it could be any button.
After opening preferencesPanel with apiRef in DataGrid v7, state (apiRef.current.state.preferencePanel.open) is not updated and it cannot be closed with clicking the button again. It's always showing open: false. It's a regression.

Expected behavior

apiRef.current.state.preferencePanel.open should be updated after opening preferencesPanel.

Context

No response

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 22.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 11.2.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.5.2 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Chrome: Not Found
    Edge: Chromium (128.0.2739.79)
  npmPackages:
    @emotion/react: ^11.14.0 => 11.14.0 
    @emotion/styled: ^11.14.0 => 11.14.0 
    @mui/core-downloads-tracker:  6.4.8 
    @mui/material: ^6.4.8 => 6.4.8 
    @mui/private-theming:  6.4.8 
    @mui/styled-engine:  6.4.8 
    @mui/system:  6.4.8
    @mui/types:  7.2.24
    @mui/utils:  6.4.8
    @mui/x-data-grid:  7.28.1
    @mui/x-data-grid-premium: ^7.28.1 => 7.28.1
    @mui/x-data-grid-pro:  7.28.1
    @mui/x-internals:  7.28.0
    @mui/x-license:  7.28.0
    @types/react: ^19.0.10 => 19.0.12
    react: ^19.0.0 => 19.0.0
    react-dom: ^19.0.0 => 19.0.0
    typescript: ~5.7.2 => 5.7.3

Search keywords: preferencepanel, datagrid, state

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions