我正在使用semantic-react-ui的Popup组件,想知道如何在不使用jQuery的情况下通过单击弹出窗口内的按钮触发关闭弹出窗口事件。
谢谢。
谢谢。
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>
);
}
}
import { FC, useState } from 'react';
import { Popup } from 'semantic-ui-react';
const ControlledPopup: FC = () => {
const [isOpen, setIsOpen] = useState(false);
return (
<Popup
trigger={<button>click to open</button>}
content={<button onClick={() => setIsOpen(!isOpen)}>click to close</button>}
on="click"
open={isOpen}
onOpen={() => setIsOpen(!isOpen)}
/>
);
};
export default ControlledPopup;
onClose={this.handleClose}
添加进去,以启用在菜单外部点击时关闭的默认行为。 - Julio FefermanisPopup1Open
、isPopup2Open
等等。 - Dane