单击页面上的任何位置时禁用覆盖层



我有一个我显示的工具提示,并在单击时隐藏。我想 hida 当用户单击 wherewhere 时,工具提示。我该如何完成?

小提琴

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'));

您必须将两个道具传递给覆盖组件才能实现这一目标,rootClose={true}onHide={() => this.setState({show: false})}

看起来应该像这样

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

完整的工作示例

最新更新