-
Notifications
You must be signed in to change notification settings - Fork 232
<Dialog /> is not a controlled component #772
Comments
Thanks for opening this issue. I realize that this and other components in this library do not follow the controlled component pattern. This repo's main goal is to implement the foundation/adapter pattern of MDC Web. RE: When |
@moog16 No, I'm saying when users click to close the dialog, this would only trigger the |
@foisonocean ahhh gotcha - I understand what you're saying now, sorry for the confusion. I do see how this breaks that pattern as you describe, especially when thinking of the |
@foisonocean If you have not started working on this, I can take a look. |
I've also noticed this the controlled component pattern is not working in checkbox either...I haven't checked, but this is probably not the case in many of the other components. @dawsonc623 if you start working on this, this will be a BreakingChange. I think this should be opt-in for the first two months, with a console.warning that says we're going to deprecate. Does that make sense? Similar to what this issue is referencing. |
@moog16 That makes sense. Opt-in might be a little tricky - do we just want to make it so if |
Ya - I think the only way we could do that is with a temporary prop...If we have that, people could slowly migrate over. Its not the best, but its the simplest thing I can think of. I also don't want to break people that have been using this component, and they should be given ample time to upgrade. So let's go with the temporary prop. Could you make sure to comment next to it and open an issue to remove it as well? |
@dawsonc623 please be advised @gugu is updating dialog: https://github.com/material-components/material-components-web-react/pull/779/files. You might want to branch from this branch as his code might get in before yours. I'm not sure how quickly you'll finish. |
@moog16 I saw that. I plan on branching off of that branch, and if I happen to finish before that gets merged in we can just wait to merge mine until that one is in. That work is already done, so I do not want to risk mucking up that PR with my work. |
Cool - Sounds good! |
I opened #785 to eventually follow up on the others as well. |
@moog16 I have been running through the flow of how
I will keep looking at it and maybe fiddle around with what it would take to implement option 2 in case it helps think of something else that does not require code duplication or reaching into the foundation code (or to get a head start if option 2 is what we decide to go with). As an aside, I had a little difficulty getting unit tests to run through the Windows Subsystem for Linux on Windows 10, but Karma can be configured to do it. I did not see any documentation related to this, so I am curious if we wanted to add documentation for getting that working (or even add a |
@dawsonc623 I'll have to bring this up during our issue triage if it requires MDC web changes. This would also be a pattern change, since there are no cancellable events in Web. And I do agree that it would be a lot nicer to not have to duplicate logic. RE Windows: We have no confirmed reports of anyone developing on windows. It would great to get some documentation if you get it up and running. :) |
@dawsonc623 I haven't forgottten about this...we have a meeting today with the team to discuss. :) |
@dawsonc623 - we had a discussion about MDC Web issue #4357 and this issue. I was wondering if you have any bandwidth to experiment with your proposed solution. We liked your #2 idea, but we aren't sure how it will pan out. Let us know :) |
@moog16 I am more than happy to dig into it. I will experiment and let you know how it goes (with any luck in PR form :) ). |
Sweet! LMK if you need any help with anything. Feel free to ping me here or on our discord channel. |
@lucasecdb shared an interesting article highlighting patterns that should be avoided (which I agree with). Dan explains that we shouldn't have state within props, which should result in a controlled component. I just wanted to share this for reference when we get to this. |
Example:
When I click the mask, the dialog still closed.
According to the React docs, just like the native input element in React,
<input type="text" value={this.state.value} onChange={this.handleChange} />
, when you try to type something in the input element, this would trigger onChange event, but if you don't changethis.state.value
in the onChange event handler, the value of this input element won't changed, just like this input element is being locked.In my opinion, the correct logic for Dialog component is that, when users try to close the dialog(via mouse click or keyboard), this would trigger onClose event, but finally the dialog is closed or not, is depending on the prop
open
, which respect React controlled components pattern.The text was updated successfully, but these errors were encountered: