0

I want to add close button to my react pop up so I added this line

 <button onClick = {$('.scoreboard-trigger').close}>Close</button>

but when I clik Close button it does not close

here is my all component

import $ from 'jquery';
import React from 'react';

import { FormattedMessage } from 'util/IntlComponents';

import OkeyScoreboard from './OkeyScoreboard';

class OkeyScoreboardDialog extends React.Component {
  componentDidMount() {
    $('.scoreboard-trigger').leanModal({
      opacity: 0
    });
  }



  render() {
    const { scoreboard, profiles } = this.props;
    const scoreboardTitle = <FormattedMessage message="room_title.scoreboard"/>;

    return (<div id='scoreboardModal'
         className='scoreboard-modal modal'>

       <div className='modal-content'>
            <h4 className='center'>{scoreboardTitle}</h4>
          <OkeyScoreboard profiles={profiles} scoreboard={scoreboard}/>
                 <button onClick = {$('.scoreboard-trigger').close}>Close</button>
      </div>

      <div className='modal-footer'>

      </div>
    </div>);
  }
}


class OkeyScoreboardDialogTrigger extends React.Component {
  render() {
    const scoreboardTitle = <FormattedMessage message="room_title.scoreboard"/>;

    return <a className='scoreboard-trigger modal-trigger btn blue-grey darken-3'
              href='#scoreboardModal'>
      {scoreboardTitle}
    </a>;
  }
}


export { OkeyScoreboardDialog };
export { OkeyScoreboardDialogTrigger };

2 Answers 2

1

I think you should wrap this in function

$('.scoreboard-trigger').close

in function and pass it to onClick method in button, I create the example wrap it in function close and pass it to the onClick

import $ from 'jquery';
import React from 'react';

import { FormattedMessage } from 'util/IntlComponents';

import OkeyScoreboard from './OkeyScoreboard';

class OkeyScoreboardDialog extends React.Component {
  componentDidMount() {
    $('.scoreboard-trigger').leanModal({
      opacity: 0
    });
  }
  close() {
     $('.scoreboard-trigger').close;
  }


  render() {
    const { scoreboard, profiles } = this.props;
    const scoreboardTitle = <FormattedMessage message="room_title.scoreboard"/>;

    return (<div id='scoreboardModal'
         className='scoreboard-modal modal'>

       <div className='modal-content'>
            <h4 className='center'>{scoreboardTitle}</h4>
          <OkeyScoreboard profiles={profiles} scoreboard={scoreboard}/>
                 <button onClick = {this.close()}>Close</button>
      </div>

      <div className='modal-footer'>

      </div>
    </div>);
  }
}


class OkeyScoreboardDialogTrigger extends React.Component {
  render() {
    const scoreboardTitle = <FormattedMessage message="room_title.scoreboard"/>;

    return <a className='scoreboard-trigger modal-trigger btn blue-grey darken-3'
              href='#scoreboardModal'>
      {scoreboardTitle}
    </a>;
  }
}


export { OkeyScoreboardDialog };
export { OkeyScoreboardDialogTrigger };here
Sign up to request clarification or add additional context in comments.

1 Comment

this not work.I copy this but when click cose it does not close.I delete:here in last line of your code
0

Try to use reacjs-popup A simple react popup component ( 3kb)

1 Comment

why are you using jquery with react?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.