Open In App

React.js Blueprint MultiSelect Props interface

Blueprint is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex and data-dense for desktop applications.

In this article, we’ll discuss the React.js Blueprint MultiSelect Props interface. The MultiSelect component displays a UI of the list of items through which a user can choose multiple items. MultiSelect renders a TagInput wrapped in a Popover.



React.js BluePrint MultiSelect Props:

Syntax:



<MultiSelect
    items={ITEM_DATA}
    onClear={...}
      ...
/>

Creating React Application And Installing Module:

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

npm create-react-app appname

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

cd appname

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

npm install @blueprintjs/core

Project Structure:

 

Step 4: Run the project as follows:

npm start

Example 1: The below example demonstrates the usage of items, selectedItems, tagRenderer, onItemSelect, onRemove, onClear, etc props of the MultiSelect component.




import { MultiSelect } from "@blueprintjs/select";
import { MenuItem } from "@blueprintjs/core";
import "normalize.css";
import "@blueprintjs/core/lib/css/blueprint.css";
import "@blueprintjs/select/lib/css/blueprint-select.css";
import { useState } from "react";
  
export default function App() {
  
    const [item, setItem] = useState("Stack");
    const [items, setItems] = useState([]);
  
    return (
        <center>
            <div style={{ textAlign: "center", color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJs Blueprint MultiSelect Props Interface</h2>
            </div>
            <div style={{ width: 700 }}>
                <MultiSelect
                    items={["Stack", "Queue"
                      "Linked List", "Array", "Heaps"]}
                    selectedItems={items}
                    itemRenderer={(val, itemProps) => {
                        return (
                            <MenuItem
                                key={val}
                                text={val}
                                onClick={(elm) => {
                                    setItem(elm.target.textContent);
                                    setItems((items) => {
                                        return [...items, 
                                             elm.target.textContent];
                                    });
                                }}
                                active={itemProps.modifiers.active}
                            />
                        );
                    }}
                    onItemSelect={() => { }}
                    tagRenderer={(item) => item}
                    onRemove={(item) => {
                        setItems((items) => items.filter(
                           (elm) => elm !== item));
                    }}
                    onClear={() => setItems([])}
                />
            </div>
        </center>
    );
}

Output:

 

Example 2: The below example demonstrates the usage of activeItems and placeholder props of the MultiSelect component.




import { MultiSelect } from "@blueprintjs/select";
import { MenuItem } from "@blueprintjs/core";
import "normalize.css";
import "@blueprintjs/core/lib/css/blueprint.css";
import "@blueprintjs/select/lib/css/blueprint-select.css";
import { useState } from "react";
  
export default function App() {
  
    const [item, setItem] = useState("Python");
    const [items, setItems] = useState([]);
  
    return (
        <center>
            <div style={{ textAlign: "center", color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJs Blueprint MultiSelect Props Interface</h2>
            </div>
            <div style={{ width: 700 }}>
                <MultiSelect
                    activeItem={item}
                    items={["Stack", "Queue", "Linked List",
                           "Array", "Heaps"]}
                    selectedItems={items}
                    itemRenderer={(val, itemProps) => {
                        return (
                            <MenuItem
                                key={val}
                                text={val}
                                onClick={(elm) => {
                                    setItem(elm.target.textContent);
                                    setItems((items) => {
                                        return [...items, 
                                        elm.target.textContent];
                                    });
                                }}
                                active={itemProps.modifiers.active}
                            />
                        );
                    }}
                    placeholder="Select data structures..."
                    onItemSelect={() => { }}
                    tagRenderer={(item) => item}
                    onRemove={(item) => {
                        setItems((items) => items.filter(
                          (elm) => elm !== item));
                    }}
                    onClear={() => setItems([])}
                />
            </div>
        </center>
    );
}

Output:

 

Reference: https://blueprintjs.com/docs/#select/multi-select.props-interface


Article Tags :