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

fix(ui-modal): fix second modal closing the first one if two of them are open #1355

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

balzss
Copy link
Contributor

@balzss balzss commented Nov 8, 2023

INSTUI-3929

test plan:

  • use the following modal example:
const fpo = lorem.paragraphs(5)

class Example extends React.Component {
  constructor (props) {
    super(props)

    this.state = {
      open: false,
      open2: false,
    }
  }

  handleButtonClick = () => {
    this.setState(function (state) {
      return { open: !state.open }
    })
  };

  handleButton2Click = (event) => {
    this.setState(function (state) {
      return { open2: !state.open2 }
    })
    console.log('kettes bezar')
  };

  renderCloseButton () {
    return (
      <CloseButton
        placement="end"
        offset="small"
        onClick={this.handleButtonClick}
        screenReaderLabel="Close"
      />
    )
  }

  renderCloseButton2 () {
    return (
      <CloseButton
        placement="end"
        offset="small"
        onClick={this.handleButton2Click}
        screenReaderLabel="Close"
      />
    )
  }

  render () {
    return (
      <div style={{ padding: '0 0 11rem 0', margin: '0 auto' }}>
        <Button onClick={this.handleButtonClick}>
          {this.state.open ? 'Close' : 'Open'} the Modal
        </Button>
        <Modal
          open={this.state.open}
          onDismiss={() => { this.setState({ open: false }) }}
          size="auto"
          label="Modal Dialog 1"
          shouldCloseOnDocumentClick
        >
          <Modal.Header>
            {this.renderCloseButton()}
            <Heading>Hello World</Heading>
          </Modal.Header>
          <Modal.Body>
            <TextInput renderLabel="Example" placeholder="if you hit enter here, it should submit the form" />
            <Text lineHeight="double">{fpo}</Text>
          </Modal.Body>
          <Modal.Footer>
            <Button onClick={() => { this.setState({ open2: true }) }} margin="0 x-small 0 0">open modal 2</Button>
            <Button onClick={this.handleButtonClick} margin="0 x-small 0 0">Close</Button>
          </Modal.Footer>
        </Modal>
        <Modal
          open={this.state.open2}
          onDismiss={() => { this.setState({ open2: false }) }}
          size="auto"
          label="Modal Dialog 2"
          shouldCloseOnDocumentClick
        >
          <Modal.Header>
            {this.renderCloseButton2()}
            <Heading>Hello World</Heading>
          </Modal.Header>
          <Modal.Body>
            <TextInput renderLabel="Example" placeholder="if you hit enter here, it should submit the form" />
          </Modal.Body>
          <Modal.Footer>
            <Button onClick={this.handleButton2Click} margin="0 x-small 0 0">Close 2</Button>
            <Button onClick={() => console.log('yoyo')} margin="0 x-small 0 0">yoyo</Button>
          </Modal.Footer>
        </Modal>
      </div>
    )
  }
}

render(<Example />)
  • open the first modal then open the second
  • close the second modal with its close button -> the first modal should remain open

@balzss balzss requested review from HerrTopi and joyenjoyer November 8, 2023 13:08
@balzss balzss force-pushed the fix/double-modal-closing branch from 8921641 to e7e3f51 Compare November 8, 2023 13:41
Copy link

github-actions bot commented Nov 8, 2023

Preview URL: https://1355--preview-instui.netlify.app

@balzss balzss self-assigned this Nov 8, 2023
@balzss balzss merged commit 73a3001 into master Nov 10, 2023
4 checks passed
@balzss balzss deleted the fix/double-modal-closing branch November 10, 2023 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants