-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to use React component life-cycle methods as they were intended to be used #292
Comments
The modal was created when react was still very young. When Ryan created it, he was still getting started doing a lot of react stuff and it was built to meet a need we had at Instructure. Based on what the component lifecycle methods the modal utilizes do, I don't see much that seems unorthodox. I mean, sure there's some rendering and stuff that goes on, but at least when the modal was created it was experimental and has turned out to be successful. I don't think these implementations have caused the root of the problem with testing. |
That's fair enough.
The fact that the
As I said, the implementation works great, but it falls down with regard to testing in my opinion and that is a deal breaker for me.
What has then, in your opinion? |
Since the modal uses the "portal" approach, this is fully acceptable, even expected. See this and this.
I believe the difficulty in testing is because of the setup required to properly test it. We have the Don't get me wrong, I'm not saying the modal is perfect by any means or that we aren't open to change. In fact, #112 is a proposed solution to avoid many of these issues. It will likely be part of our v2. |
Personally, I'd say that's up for debate.
I'm aware that it's possible to do testing with react-modal, but yes it is unnecessarily painful, in my opinion.
I don't see why it's even necessary to render using any kind of portal at all. I think I'm just going to implement my own base Modal component, with only the limited set of features I require. If you'd like to close this issue, be my guest, otherwise I'm happy for it to stay open for further discussion. |
@begincalendar can you get an experimental branch implementing this? Checklist:
|
@diasbruno I'm all for doing anything that helps the library. I would add to your checklist that it maintains/improves the accessibility story for the modal. That is the strongest point of the portal approach in my opinion at least. To note, almost all other major React modal libraries use portals:
|
...i mean, if we get this implementation working and it proves to be better than the current implementation, i think, there is no reason to miss this improve. |
I can see now that the portal approach is justified for the feature-set that this library provides, thank you @claydiffrient for the enlightenment. Having said that, an inevitable consequence of the current implementation that it makes testing arduous (relative to components that don't need to children outside of their parent). An ideal would be to have the best of both worlds (ability to render the modal outside of the parent, but implemented with greater alignment to the React "intended way", to make testing easier). @claydiffrient #112 does appear to be a step towards that ideal (in that it does at least give you the option to do away with notion of portals, which suits my particular use case and it decouples from For me personally, I'm going to stick with my own bespoke implementation of a base modal component, only because I require a fraction of the features that this library provides (hence I don't want to pay for features I don't need, with more verbose tests) and I was already wrapping this library's |
@begincalendar I'm glad I could assist. I appreciate you bringing this up for us as well. I do think you are right about the ReactGateway approach. I'm hoping that we might be able to contain it within the modal and keep things to the same scale as using react-modal like it is now. In any case, I'm going to go ahead and close the issue because it seems we figured out what's going on here :) |
Are there any compelling reasons as to why the Modal component does not utilise the React component life-cycle methods (e.g.
componentWillReceiveProps
), as the React design intends them to be used?The implementation obviously works, but because it is unorthodox (in at least my opinion), issues such as these have arisen (and wouldn't have existed if this approach had not been taken):
#71 #291
If there are no compelling reasons, should we look at refactoring the implementations of those life-cycle methods?
The text was updated successfully, but these errors were encountered: