import "rsuite/dist/rsuite.min.css";
import { Cascader } from "rsuite";
import { useEffect, useRef } from "react";
const customData = [
{
label: "Data Structures",
value: 1,
children: [
{
label: "Queue",
value: 2,
children: [
{
label: "Priority Queue",
value: 3,
},
{
label: "FIFO Queue",
value: 4,
},
],
},
{
label: "Linked List",
value: 5,
children: [
{
label: "Circular",
value: 6,
},
{
label: "Double",
value: 7,
},
{
label: "Single",
value: 8,
},
],
},
],
},
{
label: "Algorithms",
value: 1,
children: [
{
label: "Search",
value: 2,
children: [
{
label: "Binary Search",
value: 3,
},
{
label: "Linear Search",
value: 4,
},
],
},
{
label: "Sorting",
value: 5,
children: [
{
label: "Bubble Sort",
value: 6,
},
{
label: "Selection Sort",
value: 7,
},
{
label: "Insertion Sort",
value: 8,
},
],
},
],
},
];
function PreventOverflowContainer(
{
children,
height = 500
}) {
const container = useRef();
const content = useRef();
const containerStyle = {
overflow: 'auto',
position: 'relative'
};
const contentStyle = {
height: '400%',
width: '230%',
justifyContent: 'center',
alignItems: 'center',
display: 'flex',
flexWrap: 'wrap'
};
useEffect(() => {
container.current.scrollTop =
content.current.clientHeight / 2 - 60;
container.current.scrollLeft =
content.current.clientWidth / 2 -
container.current.clientWidth / 2;
}, [container, content]);
return (
<div style={
{
...containerStyle,
height
}} ref={container}>
<div style={contentStyle} ref={content}>
{children(() => container.current)}
</div>
</div>
);
}
export default function App() {
return (
<div>
<div style={
{
textAlign: "center"
}}>
<h2>GeeksforGeeks</h2>
<h4 style={
{
color: "green"
}}>
React Suite Cascader Container
and Prevent Overflow
</h4>
</div>
<div style={
{
padding: 20,
textAlign: "center"
}}>
<div>
<PreventOverflowContainer>
{getContainer => (
<Cascader
preventOverflow
placement={'bottomStart'}
style={{ width: 224 }}
container={getContainer}
data={customData}
/>
)}
</PreventOverflowContainer>
</div>
</div>
</div>
);
}