React-modal: Deprecate `isOpen`

Created on 27 Mar 2015  路  8Comments  路  Source: reactjs/react-modal

I find this more convenient compared to the current approach.

{ condition ? (
<Modal
  onRequestClose={fn}
  closeTimeoutMS={n}
>
  <h1>Modal Content</h1>
  <p>Etc.</p>
</Modal>
) : null }

However, I haven't tried this (whether is works), and I do not acknowledge any pros and cons of the approach besides a cleaner API.

question discussion

Most helpful comment

@pstoica @srph @monsieurnebo @diasbruno So basically the whole point of isOpen is to allow animations through ReactTransitionGroup ?

If I don't have animation, can you confirm that no using isOpen and returning null (no render atl all) is straightforward and well.. better.

What the point of the portal? Only animation or is there some a11y magic?

Related to https://github.com/reactjs/react-modal/pull/205

All 8 comments

I've also found it to be more convenient this way

I think you'd lose out on being able to animate? I don't think you can wrap <Modal> in something like ReactTransitionGroup since it needs to open up through another portal.

@pstoica Yea. I just realized this. Closing this because I just made myself look stupid :tada: haha

@pstoica @srph @monsieurnebo @diasbruno So basically the whole point of isOpen is to allow animations through ReactTransitionGroup ?

If I don't have animation, can you confirm that no using isOpen and returning null (no render atl all) is straightforward and well.. better.

What the point of the portal? Only animation or is there some a11y magic?

Related to https://github.com/reactjs/react-modal/pull/205

The Modal.js is responsible for setting all the environment (specially a11y, toggle the body class...). It also contains the timer for the animation since it doesn't uses css events to control its state.

@yvele Can you elaborate your idea to handle this?

Resources:
Modal.js#L81
Modal.js#L110
Modal.js#L117

@yvele @diasbruno i modified the library a bit and not using isOpen works fine but then you lose out on animation. The reason I did it is because if i use the library, as is, I can't get react-router to work properly where i render a component based on a route. In my app the modals have urls and it seems react-modal is designed to be mounted when the page loads and show or hides the modal based on the isOpen prop instead of mounting and unmounting the whole component based on a route. I think it'd be better to get rid of the isOpen prop but i don't know how you'd handle animation then. I was not able to figure that part out, but i imagine there must be some other way to handle animations.

@monsieurnebo CC

I believe i've been able to get it working without having to remove isOpen with react-router by using the children function:
https://reacttraining.com/react-router/web/api/Route/children-func

That way the component mounts no matter what and the modal can continue using isOpen with animation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

claydiffrient picture claydiffrient  路  4Comments

davidmfoley picture davidmfoley  路  3Comments

shaun-sweet picture shaun-sweet  路  3Comments

dragonball9816 picture dragonball9816  路  3Comments

gavmck picture gavmck  路  3Comments