Skip to content
Related Articles

Related Articles

React Suite <Tooltip> Props

View Discussion
Improve Article
Save Article
  • Last Updated : 22 Jun, 2022
View Discussion
Improve Article
Save Article

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 tooltip component allows the user to display informative text when users hover over, focus on, or tap an element. The tooltip props are used to add property values to the tooltip element.

Tooltip Props:

  • children: It is used to denote the primary content.
  • classPrefix: It is used to denote the prefix of the component CSS class.
  • visible: It is used to indicate whether the component is visible or not.
  • arrow: Whether show the arrow indicator

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 1: 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 learn about prop: arrow. When it is set to false, it won’t display an arrow.

Javascript




import React from 'react'
  
import "rsuite/dist/rsuite.min.css";
import { Button, Tooltip, Whisper } from 'rsuite'
  
export default function App() {
  
    return (
        <div style={{
            display: 'block', width: 700, paddingLeft: 100
        }}>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
            <h3>React Suite Tooltip Props</h3>
  
            <Whisper
                placement="right"
                speaker={<Tooltip arrow>Required Text</Tooltip>}
            >
                <Button appearance="subtle">With Arrow</Button>
            </Whisper>
            <br />
            <hr />
            <Whisper
                speaker={<Tooltip arrow={false}>
                    Required Text
                </Tooltip>}
            >
                <Button appearance="subtle">Without Arrow</Button>
            </Whisper>
        </div>
    );
}

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Example 2: In this example, we will learn about another prop; classPrefix. You will see, how the styling of tooltip will be changed like that of a placeholder.

Javascript




import React from 'react'
  
import "rsuite/dist/rsuite.min.css";
import { Button, Tooltip, Whisper } from 'rsuite'
  
export default function App() {
  
    return (
        <div style={{
            display: 'block', width: 700, paddingLeft: 100
        }}>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3>React Suite Tooltip Props</h3>
            <Whisper
                placement="right"
                speaker={<Tooltip classPrefix="tooltip">
                    Required Text
                </Tooltip>}
            >
                <Button appearance="subtle">Right</Button>
            </Whisper>
            <br />
            <hr />
            <Whisper
                speaker={<Tooltip classPrefix="placeholder">
                    Required Text
                </Tooltip>}
            >
                <Button appearance="subtle">Right</Button>
            </Whisper>
        </div>
    );
}

Output:

 

Reference: https://rsuitejs.com/components/tooltip/#code-lt-tooltip-gt-code


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!