Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Material UI: Box not scroll-able in y-axis [duplicate]

I have been stuck at this problem for hours now and I need some help. I am trying to create a Chat component and I just want to be able to scroll it vertically. Here's a minimum reproducible example at Codesandbox: https://codesandbox.io/s/reverent-panini-lsbfg?file=/src/chat/ChatHistory.tsx

I have made the container's height fixed (600px) and added the overflow: "hidden" and overflowY: "scroll" styles, but it still does not work, and I have no idea why. Thanks in advance.

like image 450
mahieyin-rahmun Avatar asked Apr 15 '26 08:04

mahieyin-rahmun


1 Answers

Welp, screw CSS. Apparently, it's a CSS bug.

Use justify-content: flex-end and to have vertical scrollbar

All I had to do was to remove justifyContent: "flex-end".

For MUI v5


    <Box
      sx={{
          mb: 2,
          display: "flex",
          flexDirection: "column",
          height: 700,
          overflow: "hidden",
          overflowY: "scroll",
         // justifyContent="flex-end" # DO NOT USE THIS WITH 'scroll'
        }}
    >

For MUI v4

<Box
      mb={2}
      display="flex"
      flexDirection="column"
      // justifyContent="flex-end" # DO NOT USE THIS WITH 'scroll'
      height="700px" // fixed the height
      style={{
        border: "2px solid black",
        overflow: "hidden",
        overflowY: "scroll" // added scroll
      }}
    >
like image 62
mahieyin-rahmun Avatar answered Apr 16 '26 22:04

mahieyin-rahmun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!