yuz*_*zır 5 javascript reactjs semantic-ui semantic-ui-react
我正在使用semantic-react-ui的Popup组件,我想知道如何通过单击弹出窗口内的按钮而不使用jquery来触发关闭弹出事件.
谢谢
根据文档,您必须创建一个受控制的Popup.
创建一个嵌套Popup组件的组件,并在其中维护一个状态:
class ControlledPopup extends React.Component {
constructor() {
super();
this.state = {
isOpen: false
}; // state to control the state of popup
}
handleOpen = () => {
this.setState({ isOpen: true });
}
handleClose = () => {
this.setState({ isOpen: false });
}
render() {
return (
<div>
<Popup
trigger={<button>click to open</button>}
content={<button onClick={this.handleClose}>click to close</button>}
on='click'
open={this.state.isOpen}
onOpen={this.handleOpen}
/>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2793 次 |
| 最近记录: |