简体   繁体   English

在 React 中显示黑色背景的模态

[英]Modal showing black backdrop in React

I am a newbie in React and I am facing the following behavior: I have a page with a list of DropDown menus for which I want to show a Modal each time user tries to change the value.我是 React 的新手,我面临以下行为:我有一个页面,其中包含一个下拉菜单列表,每次用户尝试更改值时,我想为其显示一个 Modal。

However, when I follow the typical tutorials using a button trigger, everything works as expected: here但是,当我使用按钮触发器遵循典型教程时,一切都按预期工作:这里

But when I simply try to just show the dialog without trigger or triggered by the droppDown menu, the backdrop is always black, like here但是当我只是尝试只显示对话框而不触发或由 droppDown 菜单触发时,背景总是黑色的,就像这里

Here is my code:这是我的代码:

 const styleLink = document.createElement("link"); styleLink.rel = "stylesheet"; styleLink.href = "https://cdn.jsdelivr.net/npm/semantic-ui/dist/semantic.min.css"; document.head.appendChild(styleLink); const options = [ { key: 'Online', text: 'Online', value: 1 }, { key: 'Offline', text: 'Offline', value: 2 }, ]; class TicketAlocation extends React.Component { constructor(props) { super(props); this.state = { items: [], userStatus:[], options:[], value: '', show:false, }; this.itemRenderer = this.itemRenderer.bind(this); } componentDidMount() { let context = this; } handleFieldChange = () => { this.setState({ show:true }); }; setConfirm = () => { this.setState({ show:false}); }; setCancel = () => { this.setState({ show:false}); } itemRenderer(items, index) { var value = this.state; return ( <> <div className="item"> <p className="email">{this.state.items[index].email}</p> <p className="status">{this.state.items[index].isOnline}</p> <div className="small" > <Row> <Col md={3} xl={2}> <Dropdown onChange={this.handleFieldChange} options={options} placeholder={this.state.items[index].isOnline} selection value={value} item={this.state.items[index]} /> </Col> </Row> </div> <Modal trigger={<Button>Show Modal</Button>} //open={this.state.show} // open={true} //onClose={this.setCancel} size={"tiny"} header='Reminder.' content='Call Benjamin regarding the reports,' actions={['Snooze': { key, 'done': content, 'Done': positive; true }]} /> </div> </> ). } render() { const items = this.state;items: return ( <div> <h1>Text</h1> <p> <a href="https.//www.npmjs:com/package/react-list-drag-and-drop"> <img alt="npm install react-list-drag-and-drop" src="https.//nodei.co/npm/react-list-drag-and-drop?png.mini=true" /> </a> </p> <Row> <Col md={6} xl={3}> <ReactList cssClasses="example" items={items} itemRenderer={this.itemRenderer} length={this.state.items;length} /> </Col> </Row> </div> ); } }

Could someone explain to me what am I doing wrong?有人可以向我解释我做错了什么吗?

I solved this issue by moving the Modal component into render, as before it was in itemRenderer.我通过将 Modal 组件移动到渲染中解决了这个问题,就像之前在 itemRenderer 中一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM