Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data grid] Incorrect class name rendered to GridToolbarQuickFilter when customized with GridToolbarContainer #12400

Closed
EvgenyWaveBL opened this issue Mar 10, 2024 · 3 comments · Fixed by #12484
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features feature: Filtering Related to the data grid Filtering feature good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@EvgenyWaveBL
Copy link

EvgenyWaveBL commented Mar 10, 2024

Steps to reproduce

Link to live example

  1. Create custom implementation of toolbar with GridToolbarContainer with GridToolbarQuickFilter
  2. use CustomToolbar in toolbar slot

Current behavior

MuiFormControl rendered with class like: css-3be3ve-MuiFormControl-root-MuiTextField-root-MuiDataGrid-toolbarQuickFilter

Expected behavior

MuiFormControl rendered with class like: css-3be3ve-MuiFormControl-root MuiTextField-root MuiDataGrid-toolbarQuickFilter

Context

I am trying to write override styling using themeOptions, themeAugmentation and MuiDataGrid styleOverrides

Your environment

No response

Search keywords: QuickFilter, GridToolbar

@EvgenyWaveBL EvgenyWaveBL added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 10, 2024
@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Mar 10, 2024
@michelengelen
Copy link
Member

Hi @EvgenyWaveBL ... thanks for raising this issue.
I can indeed confirm that this is a slight inconsistency.

Since this is a relatively small fix I will add the good first issue label to this.
Following is a diff that will add the correct class to the component:

diff --git a/packages/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx b/packages/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
index a5ceb6edc..6758d62fb 100644
--- a/packages/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
+++ b/packages/x-data-grid/src/components/toolbar/GridToolbarQuickFilter.tsx
@@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
 import TextField, { TextFieldProps } from '@mui/material/TextField';
 import { styled } from '@mui/material/styles';
 import { unstable_debounce as debounce } from '@mui/utils';
+import generateUtilityClass from '@mui/utils/generateUtilityClass';
+import composeClasses from '@mui/utils/composeClasses';
+import { getDataGridUtilityClass } from '@mui/x-data-grid/constants';
 import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
 import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
 import { useGridSelector } from '../../hooks/utils/useGridSelector';
@@ -71,9 +74,20 @@ export type GridToolbarQuickFilterProps = TextFieldProps & {
   debounceMs?: number;
 };

+const useUtilityClasses = (ownerState: OwnerState) => {
+  const { classes } = ownerState;
+
+  const slots = {
+    root: ['toolbarQuickFilter'],
+  };
+
+  return composeClasses(slots, getDataGridUtilityClass, classes);
+};
+
 function GridToolbarQuickFilter(props: GridToolbarQuickFilterProps) {
   const apiRef = useGridApiContext();
   const rootProps = useGridRootProps();
+  const classes = useUtilityClasses(rootProps);
   const quickFilterValues = useGridSelector(apiRef, gridQuickFilterValuesSelector);

   const {
@@ -141,6 +155,7 @@ function GridToolbarQuickFilter(props: GridToolbarQuickFilterProps) {
       placeholder={apiRef.current.getLocaleText('toolbarQuickFilterPlaceholder')}
       aria-label={apiRef.current.getLocaleText('toolbarQuickFilterLabel')}
       type="search"
+      className={classes.root}
       {...other}
       InputProps={{
         startAdornment: <rootProps.slots.quickFilterIcon fontSize="small" />,

Thanks again for raising this issue! 🙇🏼

@michelengelen michelengelen added bug 🐛 Something doesn't work feature: Filtering Related to the data grid Filtering feature customization: theme Centered around the theming features good first issue Great for first contributions. Enable to learn the contribution process. and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 11, 2024
@michelengelen michelengelen changed the title Incorrect class name rendered to GridToolbarQuickFilter when customized with GridToolbarContainer [data grid] Incorrect class name rendered to GridToolbarQuickFilter when customized with GridToolbarContainer Mar 11, 2024
@EvgenyWaveBL
Copy link
Author

Thanks buckets @michelengelen !

jhawkins11 added a commit to jhawkins11/mui-x that referenced this issue Mar 18, 2024
When creating a custom toolbar in DataGrid with GridToolbarQuickFilter, GridToolbarQuickFilter would not have MuiDataGrid-toolbarQuickFilter rendered as expected.

Fixes mui#12400
Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @EvgenyWaveBL?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features feature: Filtering Related to the data grid Filtering feature good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants