Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use reactstrap popover on hover?

I am new to the react . Here I am using a library called reactstrap, In which ,

import React from 'react';
import { Button, Popover, PopoverHeader, PopoverBody } from 'reactstrap';

export default class Example extends React.Component {
  constructor(props) {
    super(props);

    this.toggle = this.toggle.bind(this);
    this.state = {
      popoverOpen: false
    };
  }

  toggle() {
    this.setState({
      popoverOpen: !this.state.popoverOpen
    });
  }

  render() {
    return (
      <div>
        <Button id="Popover1" type="button">
          Launch Popover
        </Button>
        <Popover placement="bottom" isOpen={this.state.popoverOpen} target="Popover1" toggle={this.toggle}>
          <PopoverHeader>Popover Title</PopoverHeader>
          <PopoverBody>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</PopoverBody>
        </Popover>
      </div>
    );
  }
}

Now, Here what I am trying is when user hover on that button itself then only user should be able to see that popover. SO is there any way through which we can use this on hover itself ?

like image 625
ganesh kaspate Avatar asked Oct 27 '25 17:10

ganesh kaspate


1 Answers

For this, you can use the onMouseEnter and onMouseLeave events:

<Button
   id="Popover1"
   type="button"
   onMouseEnter={this.onHover}
   onMouseLeave={this.onHoverLeave}
>
    Launch Popover
</Button>

And the methods should look like:

onHover() {
  this.setState({
    popoverOpen: true,
  })
}

onHoverLeave() {
  this.setState({
    popoverOpen: false,
  })
}

Demo

like image 147
ravibagul91 Avatar answered Oct 29 '25 06:10

ravibagul91



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!