[英]Semantic UI modal component onClose with React
I need a way to define behavior on a Semantic modal that gets executed when it closes. 我需要一种方法来定义关闭时执行的语义模式的行为。
What I'm doing now uses a 'portal', but I think the "onClick" event doesn't work because these html elements are outside of react. 我现在正在使用“门户”,但我认为“ onClick”事件不起作用,因为这些html元素不在react范围内。
I had: 我有:
componentDidMount() {
console.log('mounting modal', this);
this.node = React.findDOMNode(this);
this.$modal = $(this.node);
this.$icon = $("<i class='close icon' /></i>");
this.$header = $("<div class='header'></div>").html(this.props.header);
this.$content = $("<div class='content'></div>");
this.$modal.append(this.$header);
this.$modal.append(this.$icon);
this.$modal.append(this.$content);
this.renderDialogContent(this.props);
}
componentWillReceiveProps(newProps) {
this.renderDialogContent(newProps);
}
renderDialogContent(props) {
props = props || this.props;
React.render(<div>{props.children}</div>, this.$content[0]);
if (props.isOpen) {
this.$modal
.modal('setting', 'closable', false)
.modal('show');
}
else {
this.$modal.modal('hide modal');
}
}
How do I define that behavior? 如何定义该行为?
For some reason, I'm unsure why, you can't use the regular React event handlers inside the modal view. 由于某些原因,我不确定为什么,您不能在模式视图中使用常规的React事件处理程序。
So on the close icon, I registered a jquery onClick handler. 因此,在关闭图标上,我注册了一个jQuery onClick处理程序。
$('#' + id).click(this.props.close);
and I passed close in bound to the parent component. 然后我通过绑定到父组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.