Material-ui: [Table] Sticky header table with buttons/inputs

Created on 2 Sep 2019  路  10Comments  路  Source: mui-org/material-ui

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

https://codesandbox.io/s/create-react-app-6v20t

Buttons and input are visible on top of the sticky header.

Expected Behavior 馃

The buttons and input go below the sticky header.

Steps to Reproduce 馃暪

Use a button or input field (I haven't checked anything else) in a table with sticky headers.

Context 馃敠

I'm trying to make a table which has options within its rows.

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.4.0 |
| React | v16.9.0 |
| Browser | Any |

bug 馃悰 Table good first issue

Most helpful comment

@Studio384 Thanks for the report. It seems that the fix is simple, creating a stacking context address it:

diff --git a/packages/material-ui/src/TableCell/TableCell.js b/packages/material-ui/src/TableCell/TableCell.js
index a81b2417e..a034c45fe 100644
--- a/packages/material-ui/src/TableCell/TableCell.js
+++ b/packages/material-ui/src/TableCell/TableCell.js
@@ -101,6 +101,7 @@ export const styles = theme => ({
     position: 'sticky',
     top: 0,
     left: 0,
+    zIndex: 1,
     backgroundColor: theme.palette.background.default,
   },
 });

All 10 comments

@Studio384 Thanks for the report. It seems that the fix is simple, creating a stacking context address it:

diff --git a/packages/material-ui/src/TableCell/TableCell.js b/packages/material-ui/src/TableCell/TableCell.js
index a81b2417e..a034c45fe 100644
--- a/packages/material-ui/src/TableCell/TableCell.js
+++ b/packages/material-ui/src/TableCell/TableCell.js
@@ -101,6 +101,7 @@ export const styles = theme => ({
     position: 'sticky',
     top: 0,
     left: 0,
+    zIndex: 1,
     backgroundColor: theme.palette.background.default,
   },
 });

Thanks, Super easy fix, was obvious but didn't try until seeing this,
Why does this occur only on certain components and not on other components like Typography?

To be honest, I don't know why it happens with such component. Maybe we already create a stacking context for them?

Does anyone want to submit a pull request for the problem? :)

I can open a new issue for this, but I figure this is basically the same issue. Buttons work, but the checkboxes are still affected.

See: https://codesandbox.io/s/create-react-app-4stgk

@Lavoaster I can't reproduce it. What environment are you using? Do you have a screenshot,

@oliviertassinari Sorry, I just realised that the issue is a little bit different.

In this case if you try to check the box in the header, whilst a checkbox is beneath it, it checks the the one beneath the sticky header.

I'm on mac OS 10.15, with Chrome77.0.3865.120, I also tested this in safari and the same issue occurs.

@Lavoaster I can reproduce it too. The z-index: 1 added in #17389 conflicts. What about increasing the z-index to 2 for the sticky header?

@oliviertassinari That makes it work for me.

@Lavoaster Do you want to submit a pull request? Or do you have a better fix in mind? :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranBran picture FranBran  路  3Comments

ghost picture ghost  路  3Comments

sys13 picture sys13  路  3Comments

rbozan picture rbozan  路  3Comments

ghost picture ghost  路  3Comments