我有一个这样的组件:
<Dialog id="_login" modal={true} onSubmit={() => console.log("x")} onCancel={() => console.log("C")} visible={true} >
<DialogHead>
Title Here
</DialogHead>
<DialogBody>
<Field id="username" label="User Name" onChange={(id, value) => { console.log(id, value) }} />
<Field id="password" label="Password" onChange={(id, value) => { console.log(id, value) }} />
</DialogBody>
<DialogFoot>
<button onClick={e => console.log(e)}>Close</button>
</DialogFoot>
</Dialog>
下面是<Dialog>
渲染代码
public render() {
return <div className="hx-dialog-outer" onClick={this.onCancel.bind(this)}>
<div className="hx-dialog-inner" onClick={(e) => {e.stopPropagation()}}>
<form name={this.props.id}>
{this.props.children}
</form>
</div>
</div>
}
如何在父元素下强制子元素?我的意思是,<DialogHead>
,<DialogBody>
并且<DialogFoot>
不应该在<Dialog>
容器外有效。例如,如果像下面这样使用它,它将产生类似“错误:DialogHead 必须嵌套在对话框组件中”的错误
<div>
<DialogHead>
Title Here
</DialogHead>
</div>