I am creating chat box UI with react-bootstrap
and using Accordion
for it. However, when messages are overflow from container height of 50vh
its not behave to scroll.
Expected Behavior
Scrolling behavior should be achieved
Actual Behavior
Its not scrolling when messages overflow. I have also added overflow-y: scroll
to container div.
import React from "react";
import Accordion from "react-bootstrap/Accordion";
import Card from "react-bootstrap/Card";
import Button from "react-bootstrap/Button";
import "bootstrap/dist/css/bootstrap.min.css";
import "./styles.css";
export default function App() {
const [messages, setMessages] = React.useState([
{
id: 1,
from: "me",
to: "Jash Jariwala",
text: "Hi, How Are You ?"
},
{
id: 2,
from: "me",
to: "Jash Jariwala",
text:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Autem, quas."
},
{
id: 3,
from: "Jash Jariwala",
to: "me",
text:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque, aperiam iure atque exercitationem ab ducimus."
},
{
id: 4,
from: "Jash Jariwala",
to: "me",
text: "Lorem ipsum dolor sit amet consectetur adipisicing."
},
{
id: 5,
from: "me",
to: "Jash Jariwala",
text: "Hi, How Are You ?"
},
{
id: 6,
from: "me",
to: "Jash Jariwala",
text: "Hi, How Are You ?"
},
{
id: 7,
from: "me",
to: "Jash Jariwala",
text: "Hi, How Are You ?"
},
{
id: 8,
from: "me",
to: "Jash Jariwala",
text: "Hi, How Are You ?"
},
{
id: 9,
from: "me",
to: "Jash Jariwala",
text: "Hi, How Are You ?"
},
{
id: 10,
from: "me",
to: "Jash Jariwala",
text: "Hi, How Are You ?"
}
]);
return (
<div className="PopMessageBox-wrapper">
<Accordion>
<Card>
<Card.Header>
<Accordion.Toggle as={Button} variant="link" eventKey="0">
Message
</Accordion.Toggle>
</Card.Header>
<Accordion.Collapse eventKey="0">
<Card.Body>
<div className="read-message-wrapper">
{messages.length ? (
messages.map((item) => {
return (
<div
key={item.id}
className={
item.from === "me"
? "message-item float-right"
: "message-item"
}
id={item.id}
>
{item.from === "me" ? (
<span></span>
) : (
<p style={{ color: "black" }}>From: {item.from}</p>
)}
<h6 style={{ color: "black" }}>{item.text}</h6>
</div>
);
})
) : (
<span>No Messages. Start Chatting ...</span>
)}
</div>
<div className="send-message-wrapper"></div>
</Card.Body>
</Accordion.Collapse>
</Card>
</Accordion>
</div>
);
}