React-modal: Add `onAfterClose` property

Created on 20 Aug 2016  路  5Comments  路  Source: reactjs/react-modal

A proper modal window resets itself upon closing.
It can be reset immediately when isOpen is set to false but that introduces glitches due to resetting and repainting the modal window before closing animation is played.
An onAfterClose handler run in componentWillUnmount would resolve this issue.
I can make a PR if you are willing to accept this feature.

bug discussion

All 5 comments

This would be awesome.

While this prop would be very helpful, my case was simple enough to implement it manually:

    onRequestClose = () => {
        this.props.closeModal()
        setTimeout(
            this.props.resetModal,
            this.props.closeTimeoutMS
        )
    }

@megapctr no, this won't work, because there's absolutely no guarantee that by that time the modal component has been unmounted.

@megapctr And also this workaround won't work for programmatically closing the modal since it will either have to call this.refs.modal.close() (which is non-React way) or have to be upgraded to duplicate ModalPortal functionality:

  componentWillReceiveProps: function(newProps) {
    if (this.props.isOpen && !newProps.isOpen) {
        setTimeout(
            this.props.resetModal,
            this.props.closeTimeoutMS
        )
    }
  },

I found another way: simply componentWillUnmount() in the modal contents component

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChristopherVH picture ChristopherVH  路  3Comments

claydiffrient picture claydiffrient  路  4Comments

leoasis picture leoasis  路  4Comments

jrock17 picture jrock17  路  4Comments

yaoyao1024 picture yaoyao1024  路  3Comments