Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react perfect scrollbar is causing problems at small screen sizes

here's a material ui template which has a problem at small screensizes, scrollbar may not appear until you click on the table and in the console this appears: enter image description here

error exists in the node modules but I don't really feel it could be fixed by modifying the node modules file but by changing the component's jsx so all solutions I found online were setting the 'touchStart' to passive and I don't feel that's the solution but we need a solution in the component itself

and I don't know how to fix it in the component itself and here's the component:

const LatestOrders = ({ className, ...rest }) => {
  const classes = useStyles();
  const [orders] = useState(data);
 
  return (
    <Card
      className={clsx(classes.root, className)}
      {...rest}
    >
      <CardHeader title="Latest Orders" />
      <Divider />
      <PerfectScrollbar>
        <Box minWidth={800}>
          <Table>
            <TableHead>
              <TableRow>
                <TableCell>
                  Order Ref
                </TableCell>
                <TableCell>
                  Customer
                </TableCell>
                <TableCell sortDirection="desc">
                  <Tooltip
                    enterDelay={300}
                    title="Sort"
                  >
                    <TableSortLabel
                      active
                      direction="desc"
                    >
                      Date
                    </TableSortLabel>
                  </Tooltip>
                </TableCell>
                <TableCell>
                  Status
                </TableCell>
              </TableRow>
            </TableHead>
            <TableBody>
              {orders.map((order) => (
                <TableRow
                  hover
                  key={order.id}
                >
                  <TableCell>
                    {order.ref}
                  </TableCell>
                  <TableCell>
                    {order.customer.name}
                  </TableCell>
                  <TableCell>
                    {moment(order.createdAt).format('DD/MM/YYYY')}
                  </TableCell>
                  <TableCell>
                    <Chip
                      color="primary"
                      label={order.status}
                      size="small"
                    />
                  </TableCell>
                </TableRow>
              ))}
            </TableBody>
          </Table>
        </Box>
      </PerfectScrollbar>
     
      <Box
        display="flex"
        justifyContent="flex-end"
        p={2}
      >
        <Button
          color="primary"
          endIcon={<ArrowRightIcon />}
          size="small"
          variant="text"
        >
          View all
        </Button>
      </Box>
    </Card>
  );
};

LatestOrders.propTypes = {
  className: PropTypes.string
};
like image 770
mai mohamed Avatar asked Oct 14 '22 21:10

mai mohamed


1 Answers

I ran into the same issue and fixed it by adding style={{ touchAction: "none" }} to the ScrollBar component.

import ScrollBar from "react-perfect-scrollbar";


<ScrollBar style={{ touchAction: "none" }}>
  ...
</ScrollBar>
like image 129
First Arachne Avatar answered Oct 20 '22 15:10

First Arachne