-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 cell width calculation when using css border #15472
Comments
Is this what you're going for? (I added padding to make it easier to see the borders.) https://codesandbox.io/p/sandbox/epic-hodgkin-z2gl5d?file=%2Fsrc%2Findex.tsx%3A20%2C26 Check out the MDN box-sizing docs for more info. (I should note that this is the repo for Material UI, which is separate from the MUI X repo where the Data Grid lives; and we generally reserve GitHub issues for bug reports and feature requests. In the future, if you find a bug in the Data Grid, the MUI X repo is the best place to report it. If you need help with implementation then Stack Overflow is usually the best place to go—be sure to add the mui-x-data-grid tag to your post so others can find it.) |
Thank you @samuelsycamore for your fast response! P.S. Thank you for your hint about the second repo. Should I close this issue here and reopen it in the other repo? |
Sorry for the confusion with the padding—I just added it to make it easier to see the borders with the Looks like this issue was moved to the correct repo so no action is needed there. I'll leave this for the Data Grid maintainers to take a look at. |
Mmh, this works for me: export const CustomThemeOptions = createTheme({
components: {
MuiDataGrid: {
styleOverrides: {
root: {
border: "1px solid grey",
},
row: {
boxSizing: "border-box",
borderWidth: "0px 3px",
borderColor: "blue",
borderStyle: "solid",
},
},
},
},
}); Although I am not sure why we do not set @romgrk do you know if this might prove to be a problem if we set that property? |
@michelengelen, you are absolutely right, that when only row gets a border, your provided styling works. When also cell gets a Border, it does not work properly.
|
All right ... that's correct. we do calculate the width manually and apply it in our rendering process as a CSS variable ... I am not sure if we can change that behavior, so. the best course of action for you would be to use box shadow as a border. |
Sorry I missed this, yes the grid needs to do its own calculations for virtualization, we can't allow borders that haven't been included in the calculations (e.g. with |
Steps to reproduce
Steps:
Current behavior
When adding css border to row and cell, cell width does not change. As a result cells are wider than provided width.
In provided example Table width is 600px. Row has 1px border, the width of row is 598px (correct behavior).
There are 2 cells in a row, each with 1px border. First cell width 200px (incorrect, should be 198px). Second cell has flex = 1 property, calculated width 398px (incorrect, should be 396px).
Expected behavior
When adding css border to row and cell, cell width is correctly calculated. Meaning cell width shrinks when cell border is added.
Context
Our Style-Guidelines require that both rows and cells have borders. Rows when they are selected and cells when keyboard focus is applied, as example for keyboard navigation. Having both properties active is in our case not unusual.
Your environment
npx @mui/envinfo
Search keywords: DataGrid width
Order ID: 99555
Search keywords:
The text was updated successfully, but these errors were encountered: