Open In App

React Suite CheckPicker Container and prevent overflow

Last Updated : 08 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • appearance: It is used for component appearance.
  • block: It is used to block an entire row.
  • classPrefix: It denotes the prefix of the component CSS class.
  • cleanable: It indicates whether the option can be emptied or not.
  • container: It is used to set the rendering container.
  • data: It denotes the selectable data.
  • defaultValue: It denotes the default value.
  • disabled: It indicates whether the component is disabled or not.
  • disabledItemValues: It is used to disable optional.
  • groupBy: It is used to set the grouping criteria ‘key’ in ‘data’.
  • labelKey: It is used to set the options to display the ‘key’ in ‘data’.
  • listProps: It denotes the list-related properties in react-virtualized.
  • menuMaxHeight: It is used to set the max height of the Dropdown.
  • menuClassName: It denotes a CSS class to apply to the Menu DOM node.
  • menuStyle: It denotes a style to apply to the Menu DOM node.
  • onChange: It is a callback function that is triggered when the value changes.
  • onClean: It is a callback function that is triggered when the value is clean.
  • onClose: It is a callback function that is triggered on a close event.
  • onEnter: It is a callback function that is triggered before the overlay transitions in.
  • onEntered: It is a callback function that is triggered after the overlay finishes transitioning in.
  • onEntering: It is a callback function that is triggered as the overlay begins to transition in.
  • onExit: It is a callback function that is triggered right before the overlay transitions out.
  • onExited: It is a callback function that is triggered after the overlay finishes transitioning out.
  • onExiting: It is a callback function that is triggered as the overlay begins to transition out.
  • onGroupTitleClick: Click the callback function for the group header.
  • onOpen: It is a callback function that is triggered on open of the component.
  • onSearch: It is a callback function for the search.
  • onSelect: It is a callback function that is triggered on the selection of an option.
  • placeholder: It denotes the placeholder.
  • placement: It is used for the placement of components.
  • preventOverflow: It is used to prevent floating element overflow.
  • renderExtraFooter: It is used for the custom render extra footer.
  • renderMenu: It is used for customizing the Rendering Menu list.
  • renderMenuGroup: It is used for the custom Render Options Group.
  • renderMenuItem: It is used for the custom Render Options.
  • renderValue: It is used for the custom Render selected options.
  • searchBy: It is used for the custom search rules.
  • searchable: It indicates whether you can search for options or not.
  • size: It denotes the picker size.
  • sort: It is used for the sort options.
  • sticky: It is used to position the top of the selected option in the options.
  • toggleAs: It can be used for the custom element for this component.
  • value: It denotes the value (Controlled).
  • valueKey: It is used to set the option value ‘key’ in ‘data’.
  • virtualized: It indicates whether to use Virtualized List or not.
  • caretAs: It adds a Custom component for the caret icon.

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.

App.js




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.

App.js




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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads