Ad

Why React-Semantic-UI Transition Not Animating The Component?

I am having a Component which is a Modal alert. For animating the Modal, I am using the Transition from semantic-ui-react. But only a few animations(pulse,bounce, flash) are working and that too only while mounting of Component, and not working while I close the Modal. Also the duration property is also not working.

class Alert extends React.Component {
  state = {
    open: true
  };

  close = () => {
    this.setState({
      open: false
    });
  };

  render() {
    const { open } = this.state;
    return (
      <Transition animation="fade" duration={1000} visible={open}>
        <Modal
          size="mini"
          closeOnDimmerClick={false}
          closeOnEscape={false}
          open={this.state.open}
          onClose={this.close}>

          <Modal.Content>
            <p>
              Hello user
            </p>
          </Modal.Content>
          <Modal.Actions>
            <Button color="blue" onClick={this.close}>
              Ok
            </Button>
          </Modal.Actions>
        </Modal>
      </Transition>
    );
  }
}

Why such weird behavior? What am I doing wrong?

Ad

Answer

Modal is unmounting way before Transition can animate it, one way would be to let Transition unmount the Modal:

class Alert extends React.Component {
  state = {
    open: true
  };

  close = () => {
    this.setState({
      open: false
    });
  };

  render() {
    const { open } = this.state;
    return (
      <Transition
        animation="fade"
        duration={1000}
        unmountOnHide={true}
        visible={open}
      >
        <Modal
          size="mini"
          closeOnDimmerClick={false}
          closeOnEscape={false}
          open={true}
          onClose={this.close}
        >
          <Modal.Content>
            <p>Hello user</p>
          </Modal.Content>
          <Modal.Actions>
            <Button color="blue" onClick={this.close}>
              Ok
            </Button>
          </Modal.Actions>
        </Modal>
      </Transition>
    );
  }
}

Edit Alert

I hope it helps!

Ad
source: stackoverflow.com
Ad