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] .MuiDataGrid-columnHeader: first-of-type doesn't work in v7 #12783

Closed
WhiteWolf-js opened this issue Apr 15, 2024 · 12 comments · Fixed by #12808
Closed

[data grid] .MuiDataGrid-columnHeader: first-of-type doesn't work in v7 #12783

WhiteWolf-js opened this issue Apr 15, 2024 · 12 comments · Fixed by #12808
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: css Design CSS customizability

Comments

@WhiteWolf-js
Copy link

WhiteWolf-js commented Apr 15, 2024

Steps to reproduce

Link to live example: (required)

Steps:
this is a example:
https://codesandbox.io/p/sandbox/flamboyant-leakey-fh6645?file=%2Fsrc%2FDemo.tsx @michelengelen here is my example

Current behavior

cannot effect &:first-of-type css styles

Expected behavior

because in v7 ,here changes some doms structure, It has greatly affected

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: first-of-type

Search keywords:

@WhiteWolf-js WhiteWolf-js added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 15, 2024
@WhiteWolf-js WhiteWolf-js changed the title in V7 dataGrid: & .MuiDataGrid-columnHeader: first-of-type cannot effect [dataGrid v7]: & .MuiDataGrid-columnHeader: first-of-type cannot effect Apr 15, 2024
@danilo-leal danilo-leal transferred this issue from mui/material-ui Apr 15, 2024
@danilo-leal danilo-leal changed the title [dataGrid v7]: & .MuiDataGrid-columnHeader: first-of-type cannot effect [data grid] .MuiDataGrid-columnHeader: first-of-type doesn't work in v7 Apr 15, 2024
@danilo-leal danilo-leal added the component: data grid This is the name of the generic UI component, not the React module! label Apr 15, 2024
@michelengelen
Copy link
Member

Please provide a minimal reproduction test case with the latest version. This would help a lot 👷.

A live example would be perfect. You can find a examples and guides on how to find templates in our docs with which you can provide examples for your specific use-case: Support - Bug reproduction.

Thank you! 🙇🏼

@michelengelen michelengelen added status: waiting for author Issue with insufficient information customization: css Design CSS customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 16, 2024
@WhiteWolf-js
Copy link
Author

@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 Apr 16, 2024
@WhiteWolf-js
Copy link
Author

i noticed that
image
if i delete this element, it will work

@WhiteWolf-js
Copy link
Author

i want to know if this element has some else function?

@michelengelen
Copy link
Member

The :first-of-type pseudo selector cannot be used on classes. Thats why it does not work the way you want it to. It merely selects the first DOM of a specific type. In this case it would select the first div element only.

I am not sure if this will be possible due to the DOM structure we have. With the presentation div present which prevents any selection based on classes in combination with :first-* and :last-*.

@romgrk any idea how we could make this happen?

@romgrk
Copy link
Contributor

romgrk commented Apr 17, 2024

The element creates the virtual offset spacing. I don't think using :first-of-* selectors is good, even if they worked, the first rendered column changes as the virtualization window is scrolled by the user. Use [aria-colindex=N] (1 indexed) if you want to target a specific column.

@romgrk romgrk added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 17, 2024
@WhiteWolf-js
Copy link
Author

but also how i can get the :last-of-type, because i want to set paddingLeft/paddingRight to fit my components @romgrk

@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 Apr 17, 2024
@romgrk
Copy link
Contributor

romgrk commented Apr 17, 2024

At the moment you would use [aria-colindex="${columns.length}"]. If you want classes for those cases, we can convert this in a feature request or you can submit a PR for it.

@romgrk romgrk added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 17, 2024
@michelengelen
Copy link
Member

columns.length might lead to buggy behavior if you are using column visibility.
You can instead use the apiRef.getVisibleColumns method instead and update a state when the visibilityModel changes:

onColumnVisibilityModelChange={(newVisibilityModel) => {
  console.log(apiRef.current?.getVisibleColumns());
}}

Or you can rely on the newVisibilityModel model param to calculate the amount of visible columns that way, but with the apiRef this is a bit easier.

Ojections @romgrk ?

@romgrk
Copy link
Contributor

romgrk commented Apr 17, 2024

That or gridVisibleColumnFieldsSelector.

@romgrk romgrk removed the status: waiting for author Issue with insufficient information label Apr 17, 2024
@romgrk
Copy link
Contributor

romgrk commented Apr 17, 2024

Needed the selector for another bug, I've added .MuiDataGrid-columnHeader--last in an upcoming PR.

Copy link

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@WhiteWolf-js: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: css Design CSS customizability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants