Open In App

React Suite CheckPicker Container and prevent overflow

React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application.

In this article, we’ll learn about React suite Checkpicker Container and prevent overflow. Checkpicker is very useful for selecting multiple items or selecting a group of data items. The prevent overflow allows the checkpicker component not to overflow if the user scrolls horizontally or vertically in a container.



Checkpicker Props:

Syntax:



import { CheckPicker } from "rsuite";

Function App() {
  return (
    <CheckPicker 
      preventOverflow
      Sticky
      value={value} 
      onChange={setValue} data={data} 
    />
  );
}

Creating React Application And Installing Module:

Step 1: Create a React application using the given command:

npm create-react-app projectname

Step 2: After creating your project, move to it using the given command:

cd projectname

Step 3: Now Install the rsuite node package using the given command:

npm install rsuite

Project Structure: Now your project structure should look like the following:

 

Example 1: Below example demonstrates the bottomStart positioned to prevent overflow checkpicker container.




import "rsuite/dist/rsuite.min.css";
import { CheckPicker } from "rsuite";
import { useEffect, useRef } from "react";
  
const data = [
    "Java",
    "C++",
    "DSA",
    "Web Development",
    "Android Development",
].map((item) => ({
    label: item,
    value: item,
}));
  
function PreventOverflowContainer({
    children, height = 300, }) {
    const container = useRef();
    const dataContent = useRef();
  
    const containerStyle = {
        overflow: 'auto',
        position: 'relative'
    };
  
    const dataStyle = {
        height: '400%',
        width: '230%',
        justifyContent: 'center',
        alignItems: 'center',
        display: 'flex',
        flexWrap: 'wrap'
    };
  
    useEffect(() => {
        container.current.scrollTop =
            dataContent.current.clientHeight / 2 - 60;
        container.current.scrollLeft =
            dataContent.current.clientWidth / 2 -
            container.current.clientWidth / 2;
    }, [container, dataContent]);
  
    return (
        <div style={{ ...containerStyle, height }}
            ref={container}>
            <div style={dataStyle} ref={dataContent}>
                {children(() => container.current)}
            </div>
        </div>
    );
}
  
export default function App() {
    return (
        <div>
            <div style={{ textAlign: "center" }}>
                <h2>GeeksforGeeks</h2>
                <h4 style={{ color: "green" }}>
                    React Suite CheckPicker Container
                    and prevent overflow
                </h4>
            </div>
            <div style={{ padding: 20, textAlign: "center" }}>
                <PreventOverflowContainer>
                    {getContainer => (
                        <CheckPicker
                            preventOverflow
                            placement={'bottomStart'}
                            style={{ width: 224 }}
                            container={getContainer}
                            data={data}
                        />
                    )}
                </PreventOverflowContainer>
            </div>
        </div>
    );
}

Output:

 

Example 2: Below example demonstrates the rightEnd position to prevent overflow checkpicker container.




import "rsuite/dist/rsuite.min.css";
import { CheckPicker } from "rsuite";
import { useEffect, useRef } from "react";
  
const data = [
    "Java",
    "C++",
    "DSA",
    "Web Development",
    "Android Development",
].map((item) => ({
    label: item,
    value: item,
}));
  
function PreventOverflowContainer({ 
children, height = 300, }) {
    const container = useRef();
    const dataContent = useRef();
  
    const containerStyle = {
        overflow: 'auto',
        position: 'relative'
    };
  
    const dataStyle = {
        height: '400%',
        width: '230%',
        justifyContent: 'center',
        alignItems: 'center',
        display: 'flex',
        flexWrap: 'wrap'
    };
  
    useEffect(() => {
        container.current.scrollTop =
            dataContent.current.clientHeight / 2 - 60;
        container.current.scrollLeft =
            dataContent.current.clientWidth / 2 -
            container.current.clientWidth / 2;
    }, [container, dataContent]);
  
    return (
        <div style={{ ...containerStyle, height }} 
            ref={container}>
            <div style={dataStyle} ref={dataContent}>
                {children(() => container.current)}
            </div>
        </div>
    );
}
  
  
export default function App() {
    return (
        <div>
            <div style={{ textAlign: "center" }}>
                <h2>GeeksforGeeks</h2>
                <h4 style={{ color: "green" }}>
                    React Suite CheckPicker Container 
                    and prevent overflow
                </h4>
            </div>
            <div style={{ padding: 20, textAlign: "center" }}>
                <PreventOverflowContainer>
                    {getContainer => (
                        <CheckPicker
                            preventOverflow
                            placement={'rightEnd'}
                            style={{ width: 224 }}
                            container={getContainer}
                            data={data}
                        />
                    )}
                </PreventOverflowContainer>
            </div>
        </div>
    );
}

Output:

 

Reference: https://rsuitejs.com/components/check-picker/#container-and-prevent-overflow


Article Tags :