Currently, I am facing an issue with creating a sticky header for my table. The problem arises when the header of the table has rounded edges (top right and top left) along with a box-shadow applied to the entire table. As the user scrolls through the table, the box-shadow also moves, causing a visible gap between the header and the beginning of the table.
To provide better context, please refer to this video demonstration showcasing the mentioned issues.
The structure of my simple header is defined in Header.jsx:
import { styles } from "../DataTablesStyles";
export default function Header() {
return (
<TableHead sx={{position: 'sticky',top: '0px',zIndex: '1'}}>
<TableRow >
<TableCell style={styles.TableHeaderStyleFirst}>Actions</TableCell>
<TableCell style={styles.TableHeaderStyle}>Status</TableCell>
<TableCell style={styles.TableHeaderStyle}>Device ID</TableCell>
<TableCell style={styles.TableHeaderStyle}>Model</TableCell>
<TableCell style={styles.TableHeaderStyle}>Operation<br></br>System</TableCell>
<TableCell style={styles.TableHeaderStyle}>Api<br></br>level</TableCell>
<TableCell style={styles.TableHeaderStyle}>Last activity</TableCell>
<TableCell style={styles.TableHeaderStyleLast}></TableCell>
</TableRow>
</TableHead>
);
}
In DataTablesStyles.js, the styling for the table and headers is specified:
// In TableStyle I define the style of the whole table
const TableStyle = {
borderTopRightRadius: '8px',
borderTopLeftRadius: '8px',
alignItems: 'center',
justifyContent: "flex-end",
padding: '16px',
minWidth: '750px',
boxShadow: '0px 0px 10px 0.1px rgba(124, 159, 236, 0.3)',
}
const TableHeaderStyle = {
fontWeight: '400',
fontSize: '14px',
letterSpacing: '0.4px',
color: 'black',
backgroundColor: '#EAECF4',
textAlign: 'center',
padding: '2px',
}
const TableHeaderStyleFirst = {
borderTopLeftRadius: '8px',
fontWeight: '400',
fontSize: '14px',
letterSpacing: '0.4px',
color: 'black',
backgroundColor: '#EAECF4',
textAlign: 'center',
padding: '2px',
}
const TableHeaderStyleLast = {
borderTopRightRadius: '8px',
fontWeight: '400',
fontSize: '14px',
letterSpacing: '0.4px',
color: 'black',
backgroundColor: '#EAECF4',
borderTopRightRadius: '8px',
textAlign: 'center',
padding: '2px',
}
If you grasp the gist of my query, how can I prevent the scrolling behavior of the shadow and eliminate the visible gap?