Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Semantic UI - Modal without trigger?

Is it possible to use a Modal without a trigger? I will open and close it via state. For example, I want to use onClick on an input field(with a file name) to open the modal with a file chooser and then edit the name of the choosen file in the input field. All this in a nested modal... Looks much simpler if I will have both modals in a parent component without the triggers, and I will display/hide them via open={true/false}

Thanks

like image 973
stgewehr Avatar asked Dec 10 '22 09:12

stgewehr


1 Answers

Yes it is. Don't set the prop trigger (it is not required) and just provide the open value from state/props.

class container extends Component {
    state = {
        isParentOpen: false,
        isChildOpen: false
    }
    
    handleClick = () => {
        this.setState({
            isParentOpen: !this.state.isOpen
        });
    }
    
    handleFocus = () => {
        this.setState({
            isChildOpen: true
        });
    }
    
    render() {
        return (
          <div>
            <Modal
              open={this.state.isParentOpen}
              size="large"
            >
              ...
              <Input onFocus={this.handleFocus} />
            </Modal>
            <Modal
              open={this.state.isChildOpen}
              size="small"
            >
              ...
            </Modal>
            <Button onClick={this.handleClick} />
          </div>
        );
    }
}

(You can nest Modal if you want to)

like image 184
user2866468 Avatar answered Dec 26 '22 00:12

user2866468