Open In App

React.js Blueprint Suggest2 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 Suggest2 Props interface. The Suggest2 component renders a text input as the Popover2 target rather than as an arbitrary child.



React.js BluePrint Suggest2 Props:

 



Syntax:

<Suggest2 
    items={ITEM_DATA}
    inputValueRenderer={...}
      ...
/>

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 modules using the following command:

npm install @blueprintjs/core
npm install @blueprintjs/select

Project Structure:

 

Step 4: Run the project as follows:

npm start

Example 1: The below example demonstrates the usage of items, itemPredicate, onItemSelect, tagRenderer, inputValueRenderer, etc props of the Suggest2 component.




import { Suggest2 } 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";
  
const itemData = ["Java", "Python", "C++", "JavaScript", "CSS"];
  
export default function App() {
    const [item, setItem] = useState();
  
    return (
        <center>
            <div style={{ textAlign: "center"
                color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>
                    ReactJs Blueprint Suggest2 Props Interface
                </h2>
            </div>
            <div style={{ width: 400 }}>
                <Suggest2
                    items={itemData}
                    itemPredicate={(query, dataItems, _index, 
                        exactMatch) => {
                        const normalizedTitle = 
                            dataItems?.toLowerCase();
                        const normalizedQuery = 
                            query.toLowerCase();
                        if (exactMatch) {
                            return normalizedTitle === 
                                normalizedQuery;
                        } else {
                            return normalizedTitle.includes
                                (normalizedQuery);
                        }
                    }}
                    itemRenderer={(val, itemProps) => {
                        return (
                            <MenuItem
                                key={val}
                                text={val}
                                onClick={(elm) => {
                                    setItem(elm.target.textContent);
                                }}
                                active={itemProps.modifiers.active}
                            />
                        );
                    }}
                    onItemSelect={() => { }}
                    tagRenderer={(item) => item}
                    inputValueRenderer={(item) => 
                        item.toString()}
                />
            </div>
        </center>
    );
}

Output:

 

Example 2: The below example demonstrates the usage of activeItem and selectedItem props of the Suggest2 component.




import { Suggest2 } 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";
  
const itemData = ["Java", "Python", "C++", "JavaScript", "CSS"];
  
export default function App() {
    const [item, setItem] = useState('JavaScript');
  
    return (
        <center>
            <div style={{ textAlign: "center", color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJs Blueprint Suggest2 Props Interface</h2>
            </div>
            <div style={{ width: 400 }}>
                <Suggest2
                    activeItem={item}
                    items={itemData}
                    selectedItem={item}
                    itemPredicate={(query, dataItems, _index, 
                        exactMatch) => {
                        const normalizedTitle = 
                            dataItems?.toLowerCase();
                        const normalizedQuery = 
                            query.toLowerCase();
                        if (exactMatch) {
                            return normalizedTitle === 
                                normalizedQuery;
                        } else {
                            return normalizedTitle.includes
                                (normalizedQuery);
                        }
                    }}
                    itemRenderer={(val, itemProps) => {
                        return (
                            <MenuItem
                                key={val}
                                text={val}
                                onClick={(elm) => {
                                    setItem(elm.target.textContent);
                                }}
                                active={itemProps.modifiers.active}
                            />
                        );
                    }}
                    onItemSelect={() => { }}
                    tagRenderer={(item) => item}
                    inputValueRenderer={(item) => item.toString()}
                />
            </div>
        </center>
    );
}

Output:

 

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


Article Tags :