Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic react ui Popup close button

I'm using semantic-react-ui's Popup component and I was wondering how to trigger close popup event by clicking a button inside the popup without using jquery.

Thank you

like image 931
riyoz Avatar asked Feb 15 '18 23:02

riyoz


1 Answers

According to the docs, you have to create a controlled Popup.
Create a component which nests the Popup component, and maintain a state in it:

class ControlledPopup extends React.Component {
  constructor() {
    super();
    this.state = {
      isOpen: false
    };                  // state to control the state of popup
  }
  
  handleOpen = () => {
    this.setState({ isOpen: true });
  }
  
  handleClose = () => {
    this.setState({ isOpen: false });
  }
  
  render() {
    return (
      <div>
        <Popup
          trigger={<button>click to open</button>}
          content={<button onClick={this.handleClose}>click to close</button>}
          on='click'
          open={this.state.isOpen}
          onOpen={this.handleOpen}
        />
      </div>
    );
  }
}
like image 55
Dane Avatar answered Oct 19 '22 04:10

Dane