2016-06-22 2 views
2

У меня есть всплывающая подсказка, которую я показываю и скрываю при нажатии. Я хочу скрыть подсказку, когда пользователь нажимает в любом месте на странице. Как я могу это сделать?Отключить наложение при нажатии в любом месте на странице

fiddle

var Alert = ReactBootstrap.Alert; 
var Overlay = ReactBootstrap.Overlay; 
var Tooltip = ReactBootstrap.Tooltip; 
var Button = ReactBootstrap.Button; 

const Example = React.createClass({ 
    getInitialState() { 
    return { show: true }; 
    }, 

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

    render() { 
    const tooltip = <Tooltip>Tooltip overload!</Tooltip>; 

    const sharedProps = { 
     show: this.state.show, 
     container: this, 
     target:() => this.refs.target.getDOMNode() 
    }; 

    return (
     <div style={{ height: 100, paddingLeft: 150, position: 'relative' }}> 
     <Button ref="target" onClick={this.toggle}> 
      Click me! 
     </Button> 

     <div> 
       Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum 
     </div> 

     <Overlay {...sharedProps} placement="left"> 
      { tooltip } 
     </Overlay> 
     </div> 
    ); 
    } 
}); 


React.render(<Example/>, document.getElementById('container')); 

ответ

1

Вы должны пройти два реквизита в компоненте Overlay, чтобы добиться этого, rootClose={true} и onHide={() => this.setState({show: false})}

Он должен выглядеть следующим образом

<Overlay rootClose={true} onHide={() => this.setState({show: false})} {...sharedProps} placement="left"> 
      { tooltip } 
     </Overlay> 

full working example

+1

Вы позиция за несколько секунд до того, как я понял это и написал свой собственный ответ :) –

Смежные вопросы