单击页面上的任意位置时禁用覆盖
Disable overlay when clicking anywhere on page
我有一个工具提示,可以在点击时显示和隐藏。我想在用户单击页面上的任意位置 时隐藏 工具提示。我怎样才能做到这一点?
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'));
您必须将两个道具传递给 Overlay 组件才能实现,rootClose={true}
和 onHide={() => this.setState({show: false})}
它应该是这样的
<Overlay rootClose={true} onHide={() => this.setState({show: false})} {...sharedProps} placement="left">
{ tooltip }
</Overlay>
我有一个工具提示,可以在点击时显示和隐藏。我想在用户单击页面上的任意位置 时隐藏 工具提示。我怎样才能做到这一点?
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'));
您必须将两个道具传递给 Overlay 组件才能实现,rootClose={true}
和 onHide={() => this.setState({show: false})}
它应该是这样的
<Overlay rootClose={true} onHide={() => this.setState({show: false})} {...sharedProps} placement="left">
{ tooltip }
</Overlay>