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] Header filters - Label of a Select input always shrinks even when there's no value selected #16324

Open
snelsi opened this issue Jan 24, 2025 · 6 comments
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Filtering on header Related to the header filtering (Pro) feature

Comments

@snelsi
Copy link

snelsi commented Jan 24, 2025

Steps to reproduce

https://mui.com/x/react-data-grid/filtering/header-filters/

Image

Current behavior

For free-text header filters label shrinks only when the input has some value.

However, label of the select/dropdown filter is always shrinked, even when there are no value selected.

This looks off

Expected behavior

Label should shrink only when some option is selected

Image

Context

Would be really nice if someone could provide a codesandbox with DataGrid Header filters:

  1. not shrinking if there's no value selected
  2. their underline border removed

Your environment

System:
OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
Binaries:
Node: 20.12.1 - ~/.nvm/versions/node/v20.12.1/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v20.12.1/bin/npm
pnpm: Not Found
Browsers:
Chrome: Not Found
npmPackages:
@emotion/react: ^11.13.3 => 11.14.0
@emotion/styled: ^11.13.0 => 11.14.0
@mui/core-downloads-tracker: 6.3.0
@mui/material: ^6.0.0 => 6.3.0
@mui/private-theming: 6.3.0
@mui/styled-engine: 6.3.0
@mui/system: 6.3.0
@mui/types: 7.2.20
@mui/utils: 6.3.0
@mui/x-data-grid: 7.23.6
@mui/x-data-grid-pro: 7.23.6
@mui/x-date-pickers: 7.23.3
@mui/x-date-pickers-pro: ^7.18.0 => 7.23.3
@mui/x-internals: 7.23.6
@mui/x-license: ^7.17.0 => 7.23.6
@types/react: ^18.3.1 => 18.3.18
react: ^18.3.1 => 18.3.1
react-dom: ^18.3.1 => 18.3.1
typescript: ^5.6.2 => 5.7.2

Search keywords: Data Grid, Header filters, Select input, Label

@snelsi snelsi added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 24, 2025
@github-actions github-actions bot added the component: data grid This is the name of the generic UI component, not the React module! label Jan 24, 2025
@snelsi snelsi changed the title Data Grid Header filters - Label of a Select input always shrinks even when there's no value selected [data grid] Header filters - Label of a Select input always shrinks even when there's no value selected Jan 24, 2025
@MBilalShafi
Copy link
Member

Hey @snelsi, the header filters in v8 had a design rehaul that makes the behavior consistent for all the column types. You can check the updated version here: https://next.mui.com/x/react-data-grid/filtering/header-filters/

v8 stable release is scheduled to be around the end of Q1 2025, so it should not be far from now.
Does the design update work for you?

@MBilalShafi MBilalShafi added status: waiting for author Issue with insufficient information feature: Filtering on header Related to the header filtering (Pro) feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 24, 2025
@snelsi
Copy link
Author

snelsi commented Jan 24, 2025

Can you please provide a codesabdbox with a workaround for v7 in the meantime?
I'd rather have a quick patch now

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Jan 24, 2025
@michelengelen
Copy link
Member

Seems related to this: #15778

Might be because the value is not undefined, but null or ''. We should check that as it might be an easy fix!

@michelengelen michelengelen removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 24, 2025
@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Jan 24, 2025
@snelsi
Copy link
Author

snelsi commented Jan 24, 2025

Tried manually overriding item.value in headerFilterCell function with undefined / null / '', but it doesn't seem to have any effect

@MBilalShafi
Copy link
Member

MBilalShafi commented Jan 28, 2025

The reason why the label doesn't go to its position is because of (1) we use an empty value in the beginning of the select options and (2) the shrink prop passed to the InputLabel component forces the label to shrink.

<rootProps.slots.baseInputLabel
{...rootProps.slotProps?.baseInputLabel}
id={labelId}
htmlFor={id}
shrink

For a quick patch, I've duplicated the GridFilterInputSingleSelect component, removed the shrink prop and used it in this example: https://stackblitz.com/edit/react-avwqjfur?file=Demo.tsx

Let me know if it could work for you for now.

@MBilalShafi MBilalShafi added the status: waiting for author Issue with insufficient information label Jan 28, 2025
@snelsi
Copy link
Author

snelsi commented Jan 29, 2025

I think I found an easier way to do the same thing

<DataGrid
  slots={{
    baseInputLabel: ({ shrink, ...rest }) => <InputLabel {...rest} />,
  }}
/>

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Jan 29, 2025
@michelengelen michelengelen removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 29, 2025
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! feature: Filtering on header Related to the header filtering (Pro) feature
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

3 participants