Skip to content
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

[Dialog] Open state bug #4686

Closed
valentinvichnal opened this issue Jul 11, 2016 · 3 comments
Closed

[Dialog] Open state bug #4686

valentinvichnal opened this issue Jul 11, 2016 · 3 comments
Labels
component: dialog This is the name of the generic UI component, not the React module! v0.x

Comments

@valentinvichnal
Copy link

valentinvichnal commented Jul 11, 2016

Problem description

I created a Dialog component and control its open state with this.state.openState which is connected to this.props.open. Another component which contains this Dialog component, also include a button which sets the open prop to true for Dialog when clicked.

After the first button click the Dialog open prop was set to true, but it's openState state still false. It only changes to true after the second click on the button.

Any idea why this is happening? It should change the state on the first click because of the shouldComponentUpdate.

Subsequent clicks on the button works properly, only the first click on the button after the render has this bug.

Steps to reproduce

import React from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';

class DialogExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      openState: props.open
    };
  }
  // ... handleClose, handleSubmit
  shouldComponentUpdate(nextProps) {
    this.setState({ openState: nextProps.open });
    return true;
  }
  render() {
    const {openState} = this.state;
    const actions = [
      <FlatButton
        className="button"
        label="No"
        onTouchTap={this.handleClose}
        />,
      <FlatButton
        className="button"
        label="Yes"
        primary={true}
        onTouchTap={this.handleSubmit}
        />,
    ];
    return (
      <Dialog
        title="example"
        actions={actions}
        modal={true}
        open={openState}
        >
        Text?
      </Dialog>
    );
  }
}

export default DialogExample;

Versions

  • Material-UI: 0.15.1
  • React: 15.1.0
  • Browser: Chrome, FF, IE
@nehalbhanushali
Copy link

@valentinvichnal does your application require the calling button to be in another component and not with the dialog? It would not happen if it is a part of the same component the dialog is.

@valentinvichnal
Copy link
Author

@nehalbhanushali yes, because I have a list of item each has a related icon button for the Dialog.
When dialogs were in the same components it worked, but there is too much Dialog related code so I moved them to their own module.

Now I use only the props to check if the Dialog is open, pass a callback to the Dialog which can call it and it will change the open prop to false. It works but not a nice solution.

@mpontikes mpontikes mentioned this issue Aug 5, 2016
13 tasks
@aahan96
Copy link
Contributor

aahan96 commented Aug 17, 2016

@valentinvichnal Looks like we can close this issue then

@aahan96 aahan96 closed this as completed Aug 17, 2016
@oliviertassinari oliviertassinari added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 21, 2022
@zannager zannager added component: dialog This is the name of the generic UI component, not the React module! v0.x and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: dialog This is the name of the generic UI component, not the React module! v0.x
Projects
None yet
Development

No branches or pull requests

5 participants