I have a dropdown and a modal, and I would like to show the modal when one of the dropdown item is clicked. Is it possible? I couldn't find a way to do so because I cannot obtain the target DropdownItem, which is required by Modal's trigger props.
export class Demo extends React.Component<{}, {}> {
private options = [
{ text: 'doNothing', value: 'doNothing' },
{ text: 'openModal', value: 'openModal' },
]
render() {
return (
<div>
<Dropdown
fluid
selection
options={this.options}
defaultValue={this.options[0].value} />
<Modal trigger={<Button>trigger</Button>}>
<Modal.Header>Select a Photo</Modal.Header>
<Modal.Content image>
<Modal.Description>
<p>Some contents.</p>
</Modal.Description>
</Modal.Content>
</Modal>
</div>
)
}
}
You could use prop open
of Modal
to programmatically control it. When you detect that the desired Dropdown
item was clicked setState
appropriately.
Something among those lines.
import * as React from 'react';
export class Demo extends React.Component<{}, {}> {
state = {
options: [
{ text: 'doNothing', value: 'doNothing' },
{ text: 'openModal', value: 'openModal' }
],
open: false
};
onClose = () => this.setState({open: false});
onChange = (selected) => {
// if the correct one is selected then...
// this.setState({open: true});
}
render() {
return (
<div>
<Dropdown
fluid
selection
options={this.options}
onChange={this.onChange}
defaultValue={this.options[0].value} />
<Modal open={this.state.open} onClose={this.onClose}>
<Modal.Header>Select a Photo</Modal.Header>
<Modal.Content image>
<Modal.Description>
<p>Some contents.</p>
</Modal.Description>
</Modal.Content>
</Modal>
</div>
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With