Open In App

React Suite Cascader Inline

React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The Cascader component is used as a cascade selection box. It helps the user in a Single selection of data with a hierarchical relationship structure.

Inline in cascader helps to create a cascader like an inline element in HTML.  An inline element only takes up as much width as necessary. 



Cascader Props:

Syntax:



<Cascader inline data={data} />

Creating React Application And Installing Module:

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

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command:

cd foldername

Step 3: After creating the ReactJS application, Install the required module using the following command:

npm install rsuite

Project Structure: It will look like the following.

 

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

In this example, we will simply create a cascader and use inline keyword with it ,




import react from 'react'
import { Cascader } from 'rsuite';
import 'rsuite/dist/rsuite.min.css';
  
export default function App() {
    // Sample Options
    const options = [
        {
            "label": "GeeksforGeeks",
            "value": 1,
            "children": [
                {
                    "label": "Machine Learning",
                    "value": 2
                },
                {
                    "label": "Data Structures",
                    "value": 3,
  
                }
            ]
        },
        {
            "label": "StackOverFlow",
            "value": 8,
            "children": [
                {
                    "label": "Databases",
                    "value": 9
                },
                {
                    "label": "Operating System",
                    "value": 10,
  
                }
            ]
        },
        {
            "label": "Tutorial Point",
            "value": 13,
            "children": [
                {
                    "label": "Engineering Mathematics",
                    "value": 14
                },
                {
                    "label": "Theory of Computation",
                    "value": 15
                }
            ]
        }
    ]
    return (
        <div className="App">
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3>React Suite Cascader Inline</h3>
            <Cascader inline data={options} />
        </div>
    );
}

Output:

 

Example 2: In this example, we will create nested inline cascader i.e options inside options.




import react from 'react'
import { Cascader } from 'rsuite';
import 'rsuite/dist/rsuite.min.css';
  
export default function App() {
    // Sample Options
    const options = [
        {
            "label": "Uttar Pradesh",
            "value": 1,
            "children": [
                {
                    "label": "Moradabad",
                    "value": 2
                },
                {
                    "label": "Bareilly",
                    "value": 3,
                    "children": [
                        {
                            "label": "Vijay Nagar",
                            "value": 4
                        },
                        {
                            "label": "Rajiv Gandhi Square",
                            "value": 5
                        },
                        {
                            "label": "MR 10",
                            "value": 6
                        },
                    ]
                },
                {
                    "label": "Lucknow",
                    "value": 7
                }
            ]
        }
    ]
    return (
        <div className="App">
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks</h1>
            <h3>React Suite Cascader Block</h3>
            <Cascader inline data={options} 
                searchable={false} />
        </div>
    );
}

Output:

 

Reference: https://rsuitejs.com/components/cascader/#inline


Article Tags :