简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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