gpt4 book ai didi

reactjs - 单击页面上任意位置时禁用覆盖

转载 作者:行者123 更新时间:2023-12-03 14:21:24 25 4
gpt4 key购买 nike

我有一个工具提示,可以在单击时显示和隐藏。我想在用户单击页面上的任意位置隐藏工具提示。我怎样才能做到这一点?

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

最佳答案

您必须向 Overlay 组件传递两个属性才能实现此目的:rootClose={true}onHide={() => this.setState({show: false}) }

应该是这样的

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

full working example

关于reactjs - 单击页面上任意位置时禁用覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37974735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com