Material-UI Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p> - reactjs

I'm using Material UI and I get this error when I click on Collapse cmp (Material UI) which is inside a table:
validateDOMNesting(...): <p> cannot appear as a descendant of <p>. **
I saw same topic but with Typography which I didn't use.
I have no idea if the problem is the Collapse cmp or the element inside it
Here is the code:
import React from 'react'
import KeyboardArrowDownIcon from '#material-ui/icons/KeyboardArrowDown';
import KeyboardArrowUpIcon from '#material-ui/icons/KeyboardArrowUp';
import TableCell from '#material-ui/core/TableCell';
import TableRow from '#material-ui/core/TableRow';
import IconButton from '#material-ui/core/IconButton';
import Collapse from '#material-ui/core/Collapse';
import Box from '#material-ui/core/Box';
import classes from './post.module.scss'
import Button from '#material-ui/core/Button';
export default function PostRow(props) {
const { row, delatePost, loadProfile, fromProfile } = props;
const [open, setOpen] = React.useState(false);
return (
<React.Fragment>
<TableRow onClick={() => setOpen(!open)} style={{ borderBottom: 'unset', cursor: 'pointer' }}>
<TableCell>
עוד
<IconButton aria-label="expand row" size="small" onClick={() => setOpen(!open)}>
{open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
</IconButton>
</TableCell>
<TableCell align="right">{row.name}</TableCell>
<TableCell align="right" component="th" scope="row">
{row.businessField}
</TableCell>
<TableCell align="right">{row.followers}</TableCell>
</TableRow>
<TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0, }} colSpan={6}>
<Collapse in={open} timeout="auto" unmountOnExit>
<Box margin={0}>
<div className={classes.about}>
<h4>קצת על העסק</h4>
<p>{row.aboutBusiness}
<h4>דרישות</h4>
<p>{row.requirements}</p>
</p>
{fromProfile &&
<Button variant="contained" color="secondary" style={{marginBottom: '15px'}} onClick={async () => {
await delatePost(row._id)
loadProfile()
}}>מחק פוסט</Button>
}
</div>
</Box>
</Collapse>
</TableCell>
</TableRow>
</React.Fragment>
);
}

thanks guys i will read the articles :) meanwhile I just removed the P element and its working great.

Related

How can I Show Only my Videos in Django-Rest-Framework?

I'm using Django and React to create YouTube clone.
And I have an admin panel where user can delete and edit his videos.
But the problem is that it showing my videos and other users videos.
How can make that the admin panel will show only my videos?
views.py Api Views
class AdminVideoDetail(generics.RetrieveAPIView):
permission_classes = [IsAuthenticated]
quesryset = Video.objects.all()
serializer_class = VideoSerializer
videos.js Videos in the admin panel
import React from 'react';
import { makeStyles } from '#material-ui/core/styles';
import Container from '#material-ui/core/Container';
import Link from '#material-ui/core/Link';
import Paper from '#material-ui/core/Paper';
import Table from '#material-ui/core/Table';
import TableBody from '#material-ui/core/TableBody';
import TableCell from '#material-ui/core/TableCell';
import TableContainer from '#material-ui/core/TableContainer';
import TableHead from '#material-ui/core/TableHead';
import TableRow from '#material-ui/core/TableRow';
import DeleteForeverIcon from '#material-ui/icons/DeleteForever';
import EditIcon from '#material-ui/icons/Edit';
import Button from '#material-ui/core/Button';
const useStyles = makeStyles((theme) => ({
cardMedia: {
paddingTop: '56.25%', // 16:9
},
link: {
margin: theme.spacing(1, 1.5),
},
cardHeader: {
backgroundColor:
theme.palette.type === 'light'
? theme.palette.grey[200]
: theme.palette.grey[700],
},
videoTitle: {
fontSize: '16px',
textAlign: 'left',
},
videoText: {
display: 'flex',
justifyContent: 'left',
alignItems: 'baseline',
fontSize: '12px',
textAlign: 'left',
marginBottom: theme.spacing(2),
},
}));
const Videos = (props) => {
const { videos } = props;
const classes = useStyles();
if (!videos || videos.length === 0) return <Button href={'/admin/create'} variant="contained" color="primary">New Video</Button>;
return (
<React.Fragment>
<Container maxWidth="md" component="main">
<Paper className={classes.root}>
<TableContainer className={classes.container}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
<TableCell>Id</TableCell>
<TableCell align="left">Title</TableCell>
<TableCell align="left">Action</TableCell>
</TableRow>
</TableHead>
<TableBody>
{videos.map((video) => {
return (
<TableRow>
<TableCell component="th" scope="row">
{video.id}
</TableCell>
<TableCell align="left">
<Link
color="textPrimary"
href={'/video/' + video.id}
className={classes.link}
>
{video.title}
</Link>
</TableCell>
<TableCell align="left">
<Link
color="textPrimary"
href={'/admin/edit/' + video.id}
className={classes.link}
>
<EditIcon></EditIcon>
</Link>
<Link
color="textPrimary"
href={'/admin/delete/' + video.id}
className={classes.link}
>
<DeleteForeverIcon></DeleteForeverIcon>
</Link>
</TableCell>
</TableRow>
);
})}
<TableRow>
<TableCell colSpan={4} align="right">
<Button
href={'/admin/create'}
variant="contained"
color="primary"
>
New Video
</Button>
</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</Paper>
</Container>
</React.Fragment>
);
};
export default Videos;
If you want to look at the whole project, here is github: https://github.com/PHILLyaHI/diplom-work
Create a python module named permissions.py
add these line of code
from rest_framework import permissions
class IsOwnerOrReadOnly(permissions.BasePermission):
"""
"""
def has_object_permission(self, request, view, obj):
# I check if the request is of type GET or OPTIONS
#I return true, that the use is able to access on this views
if request.method in permissions.SAFE_METHODS:
return True
return obj.owner == request.user
"""
Instance must have an attribute named `owner` or you can change owner with the name of your models fields `user = models.ForeignKey(UserModel, on_delete=models.casscade).
"""
After, go in your views.py module, add
class AdminVideoDetail(generics.RetrieveAPIView):
permission_classes = [IsAuthenticated, IsOwnerOrReadOnly]
quesryset = Video.objects.all()
serializer_class = VideoSerializer
Only videos of owner will be fetch

How to control material UI Accordian expansion / collapse by click on icon from another component?

Actually, i'm creating the table where i've to expand the Row by clicking the icon on another column! any help will be appreciated ! (i'm using material UI components like table, accordian)
Here's the Demo of my code on sandbox!
https://codesandbox.io/s/proud-resonance-iryir7?file=/src/App.js:73-74
My concern is when I click on message icon, email cell will be expanded!
import {
Accordion,
AccordionDetails,
AccordionSummary,
Box,
Grid,
TextField,
Typography
} from "#mui/material";
import React, { useEffect, useState } from "react";
import PictureAsPdfIcon from "#mui/icons-material/PictureAsPdf";
import Table from "#mui/material/Table";
import TableBody from "#mui/material/TableBody";
import TableCell from "#mui/material/TableCell";
import TableContainer from "#mui/material/TableContainer";
// import Collapse from "#mui/material/Collapse";
import TableHead from "#mui/material/TableHead";
import TableRow from "#mui/material/TableRow";
import Paper from "#mui/material/Paper";
import InfoOutlinedIcon from "#mui/icons-material/InfoOutlined";
import ChatBubbleOutlineOutlinedIcon from "#mui/icons-material/ChatBubbleOutlineOutlined";
import Modal from "#mui/material/Modal";
const Example = () => {
const [Data, setData] = useState([]);
const [open, setOpen] = React.useState(false);
const [expandedId, setExpandedId] = useState("0");
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
function createData(
name,
id,
email
) {
return {
name,
id,
email
};
}
const modalstyle = {
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: 400,
bgcolor: "background.paper",
border: "2px solid #000",
boxShadow: 24,
p: 4
};
useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/users")
.then((res) => res.json())
.then((result) => setData(result));
});
const rows = [
Data.map((data) =>
createData(
data.name,
data.id,
data.email
)
)
];
return (
<div>
<div className="heading">
<Grid container>
<Grid item md={9} sm={9} xs={12}></Grid>
</Grid>
<div className="box">
<TableContainer component={Paper}>
<Table aria-label="simple table">
<TableHead
sx={{
"& .MuiTableCell-head": {
backgroundColor: "#000000",
color: "#ffffff",
height: "55px",
textAlign: "center",
fontSize: "14px"
}
}}
>
<TableRow>
<TableCell>name</TableCell>
<TableCell align="right">email</TableCell>
<TableCell></TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows[0].map((row) => (
<TableRow
sx={{
"& td, & th": {
border: 1,
borderColor: "gray"
}
}}
key={row.id}
>
<TableCell component="th" scope="row">
<div className="codes" onClick={handleOpen}>
{`${row.name} ${row.id}`}
</div>
</TableCell>
<TableCell align="left">
<div className="msg-container">
<Accordion
elevation={0}
key={row.Id}
// onChange={handleChangeExpanded(`panel_${row.id}`)}
expanded = {expandedId === row.id}
>
<AccordionSummary
ariaControls={`${row.id}_panel1a-content`}
id={`${row.id}_panel1a-id`}
>
<div className="msg">{row.email}</div>
</AccordionSummary>
<AccordionDetails>
<TextField placeholder="Enter Here"></TextField>
</AccordionDetails>
</Accordion>
</div>
</TableCell>
<TableCell>
<div className="info-icon-container">
<div className="info-icon" onClick={handleOpen}>
<InfoOutlinedIcon />
</div>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
BackdropProps={{
style: {
background: "transparent"
}
}}
>
<Box sx={modalstyle}>
<Typography
id="modal-modal-title"
variant="h6"
component="h2"
>
Text in a modal
</Typography>
<Typography
id="modal-modal-description"
sx={{ mt: 2 }}
>
Duis mollis, est non commodo luctus, nisi erat
porttitor ligula.
</Typography>
</Box>
</Modal>
<div className="chatbubble-icon">
<ChatBubbleOutlineOutlinedIcon onClick={() => setExpandedId(prev => prev === row.id ? "0" : row.id)} />
</div>
</div>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div>
</div>
</div>
);
};
export default Example;
check this out.

How to get the value of clicked cell in React Material Table?

I am trying to get the corresponding value of cell in React Material UI Table Component.
I was looking for already predefined component api properties but couldn't find anything appropriate.
Working with Material UI DataGrid component, I achieved that, getting the selected row via onSelectionModelChange thanks to this answer.
But in this case, Table doesn't have any checkboxes and I need to retrieve the data by clicking.
Here is the codesandbox link and the example code:
import * as React from "react";
import Table from "#mui/material/Table";
import TableBody from "#mui/material/TableBody";
import TableCell from "#mui/material/TableCell";
import TableContainer from "#mui/material/TableContainer";
import TableHead from "#mui/material/TableHead";
import TableRow from "#mui/material/TableRow";
import Paper from "#mui/material/Paper";
export default function BasicTable({ users }: any) {
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>userId</TableCell>
<TableCell align="right">id</TableCell>
<TableCell align="right">Title</TableCell>
</TableRow>
</TableHead>
<TableBody>
{users &&
users.map((user: any) => (
<TableRow
key={users.id}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell align="right">{user.userId}</TableCell>
<TableCell align="right">{user.id}</TableCell>
<TableCell align="right">{user.title}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
}
Any help will be appreciated.
You can create an onClick function on the cells that you want this behavior to happen. Assuming that you want this on user.title cells and using console.log as example:
<TableCell align="right" onClick={({target}) => console.log(target.textContent)}>{user.title}</TableCell>
Since you are mapping over your data, you can simply use the desired data from the map:
{users &&
users.map((user: any) => (
<TableRow
key={user.id}
onClick={() => console.log(user.id)} // set desired state here
>
<TableCell align="right">{user.userId}</TableCell>
<TableCell align="right">{user.id}</TableCell>
<TableCell align="right">{user.title}</TableCell>
</TableRow>
))}

Customize TableRow with Material UI component

I'm using Material UI table example and trying to customize the rows to have my own component to replace the default row.I want to have some margin between the rows and a shadow (using elevation prop of Paper element). This is what I achieved so far:
import React, { useState } from 'react'
import Paper from '#material-ui/core/Paper';
import Table from '#material-ui/core/Table';
import TableBody from '#material-ui/core/TableBody';
import TableCell from '#material-ui/core/TableCell';
import TableContainer from '#material-ui/core/TableContainer';
import TableHead from '#material-ui/core/TableHead';
import TableRow from '#material-ui/core/TableRow';
const MyPaper = (item) => {
return (
<Paper
elevation={6}>
{item}
</Paper>
);
};
const List = () => {
const items = ['a', 'b'];
return (
<div style={{ maxWidth: "100%" }}>
<TableContainer>
<Table aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
<TableCell align="right">Calories</TableCell>
<TableCell align="right">Fat (g)</TableCell>
<TableCell align="right">Carbs (g)</TableCell>
<TableCell align="right">Protein (g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{items.map(item => (
<TableRow key={item} component={() => MyPaper(item)}>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div>
)
}
export default List
but the result is being applied only in the first column. How do I fix this to have my custom row to occupy the entire table space?
Thanks in advance
You can do it easily with withstyles property of Material-UI, you can arrange Paper or other MUI components to give them classes and arrange them in styles variable:
import React, { useState } from 'react'
import Paper from '#material-ui/core/Paper';
import Table from '#material-ui/core/Table';
import TableBody from '#material-ui/core/TableBody';
import TableCell from '#material-ui/core/TableCell';
import TableContainer from '#material-ui/core/TableContainer';
import TableHead from '#material-ui/core/TableHead';
import TableRow from '#material-ui/core/TableRow';
import { WithStyles } from '#material-ui/core'
const styles = theme => ({
...theme,
Row: {
margin: 10
}
})
const List = () => {
const items = ['a', 'b'];
const {classes} = this.props
return (
<div style={{ maxWidth: "100%" }}>
<TableContainer>
<Table aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
<TableCell align="right">Calories</TableCell>
<TableCell align="right">Fat (g)</TableCell>
<TableCell align="right">Carbs (g)</TableCell>
<TableCell align="right">Protein (g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{items.map(item => (
<TableRow key={item} className={classes.Row}>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
<TableCell>{item}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div>
)
}
export default withStyles(styles)(List)

Material UI Table not being responsive while using example Responsive Drawer

I have created a web app with the base coming from the Material-UI Example on a responsive drawer
I am trying to get a table to resize responsively to the screen width, but, for some reason, the ResponsiveDrawer container provided by Material-UI is breaking the responsiveness of the contents (i.e. the table)
Here is an example that I wrote that is perfectly responsive:
App.js
import React from "react";
import ReactDOM from "react-dom";
import Table from "#material-ui/core/Table/Table";
import TableHead from "#material-ui/core/TableHead/TableHead";
import TableRow from "#material-ui/core/TableRow/TableRow";
import TableCell from "#material-ui/core/TableCell/TableCell";
import TableBody from "#material-ui/core/TableBody/TableBody";
import Paper from "#material-ui/core/Paper/Paper";
import Grid from "#material-ui/core/Grid/Grid";
import "./styles.css";
function App() {
return (
<div className="App">
<Grid container justify={"center"}>
<Grid item xs={12} md={10} style={{ padding: "8px" }}>
<Paper style={{ overflowX: "auto" }}>
<Table style={{ minWidth: "340px" }}>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Column</TableCell>
<TableCell>Operating System</TableCell>
<TableCell>Status</TableCell>
<TableCell>CPU Cores</TableCell>
<TableCell>Memory (MB)</TableCell>
<TableCell>IP Address</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
</TableBody>
</Table>
</Paper>
</Grid>
</Grid>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
And here is that same example using a modified (changed the content to this.props.children instead of static) version of Material-UI's ResponsiveDrawer
ResponsiveDrawer.js
import React from "react";
import PropTypes from "prop-types";
import AppBar from "#material-ui/core/AppBar";
import CssBaseline from "#material-ui/core/CssBaseline";
import Divider from "#material-ui/core/Divider";
import Drawer from "#material-ui/core/Drawer";
import Hidden from "#material-ui/core/Hidden";
import IconButton from "#material-ui/core/IconButton";
import InboxIcon from "#material-ui/icons/MoveToInbox";
import List from "#material-ui/core/List";
import ListItem from "#material-ui/core/ListItem";
import ListItemIcon from "#material-ui/core/ListItemIcon";
import ListItemText from "#material-ui/core/ListItemText";
import MailIcon from "#material-ui/icons/Mail";
import MenuIcon from "#material-ui/icons/Menu";
import Toolbar from "#material-ui/core/Toolbar";
import Typography from "#material-ui/core/Typography";
import { withStyles } from "#material-ui/core/styles";
const drawerWidth = 240;
const styles = theme => ({
root: {
display: "flex"
},
drawer: {
[theme.breakpoints.up("sm")]: {
width: drawerWidth,
flexShrink: 0
}
},
appBar: {
marginLeft: drawerWidth,
[theme.breakpoints.up("sm")]: {
width: `calc(100% - ${drawerWidth}px)`
}
},
menuButton: {
marginRight: 20,
[theme.breakpoints.up("sm")]: {
display: "none"
}
},
toolbar: theme.mixins.toolbar,
drawerPaper: {
width: drawerWidth
},
content: {
flexGrow: 1,
padding: theme.spacing.unit * 3
}
});
class ResponsiveDrawer extends React.Component {
state = {
mobileOpen: false
};
handleDrawerToggle = () => {
this.setState(state => ({ mobileOpen: !state.mobileOpen }));
};
render() {
const { classes, theme } = this.props;
const drawer = (
<div>
<div className={classes.toolbar} />
<Divider />
<List>
{["Inbox", "Starred", "Send email", "Drafts"].map((text, index) => (
<ListItem button key={text}>
<ListItemIcon>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
<Divider />
<List>
{["All mail", "Trash", "Spam"].map((text, index) => (
<ListItem button key={text}>
<ListItemIcon>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
</div>
);
return (
<div className={classes.root}>
<CssBaseline />
<AppBar position="fixed" className={classes.appBar}>
<Toolbar>
<IconButton
color="inherit"
aria-label="Open drawer"
onClick={this.handleDrawerToggle}
className={classes.menuButton}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" noWrap>
Responsive drawer
</Typography>
</Toolbar>
</AppBar>
<nav className={classes.drawer}>
{/* The implementation can be swapped with js to avoid SEO duplication of links. */}
<Hidden smUp implementation="css">
<Drawer
container={this.props.container}
variant="temporary"
anchor={theme.direction === "rtl" ? "right" : "left"}
open={this.state.mobileOpen}
onClose={this.handleDrawerToggle}
classes={{
paper: classes.drawerPaper
}}
>
{drawer}
</Drawer>
</Hidden>
<Hidden xsDown implementation="css">
<Drawer
classes={{
paper: classes.drawerPaper
}}
variant="permanent"
open
>
{drawer}
</Drawer>
</Hidden>
</nav>
<main className={classes.content}>
<div className={classes.toolbar} />
{this.props.children}
</main>
</div>
);
}
}
ResponsiveDrawer.propTypes = {
classes: PropTypes.object.isRequired,
// Injected by the documentation to work in an iframe.
// You won't need it on your project.
container: PropTypes.object,
theme: PropTypes.object.isRequired
};
export default withStyles(styles, { withTheme: true })(ResponsiveDrawer);
App.js
import React from "react";
import ReactDOM from "react-dom";
import Table from "#material-ui/core/Table/Table";
import TableHead from "#material-ui/core/TableHead/TableHead";
import TableRow from "#material-ui/core/TableRow/TableRow";
import TableCell from "#material-ui/core/TableCell/TableCell";
import TableBody from "#material-ui/core/TableBody/TableBody";
import Paper from "#material-ui/core/Paper/Paper";
import ResponsiveDrawer from "./ResponsiveDrawer";
import Grid from "#material-ui/core/Grid/Grid";
import "./styles.css";
function App() {
return (
<div className="App">
<ResponsiveDrawer>
<Grid container justify={"center"}>
<Grid item xs={12} md={10} style={{ padding: "8px" }}>
<Paper style={{ overflowX: "auto" }}>
<Table style={{ minWidth: "340px" }}>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Column</TableCell>
<TableCell>Operating System</TableCell>
<TableCell>Status</TableCell>
<TableCell>CPU Cores</TableCell>
<TableCell>Memory (MB)</TableCell>
<TableCell>IP Address</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
<TableRow>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
<TableCell>Content</TableCell>
</TableRow>
</TableBody>
</Table>
</Paper>
</Grid>
</Grid>
</ResponsiveDrawer>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
I just can't seem to figure out what it is inside the ResponsiveDrawer container that is causing the responsiveness to break.
All help appreciated.
UPDATE (1/7/2019):
It looks like removing display: flex from the root solves the issue, but then I have the issue of it not honoring the left drawer.
UPDATE (1/9/2019):
As suggested by #Gaurav Rana, I have added width: 100%; to the main element and it has half solved the problem. Now, the table will overflow / scroll properly when the sidebar is not visible. But, when the sidebar is still visible but the screen isn't wide enough for the whole table, the table scrolls under the sidebar.
After a bit of troubleshooting, I have come up with a solution:
The styles for content need to be updated as follows (This will force the width of the content element to fit the width of the screen minus the drawer if necessary):
content: {
[theme.breakpoints.up("sm")]: {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`
}
},
And display: flex needs to be removed from root
https://codesandbox.io/s/1zxp2qjmoj
this is a problem width css width. You must specify whole parents width: 100% like this
body {
width: 100%
}
.grandparent {
width: 100%
}
.parent {
width: 100%
}
.tableContainer {
width: 100%
}
add style below style in your styles.css . hope this will solve your issue.
main {
width: 100%;
}

Resources