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-tray): fix Tray component unmounting twice when closed #1342

Merged
merged 1 commit into from
Nov 3, 2023

Conversation

balzss
Copy link
Contributor

@balzss balzss commented Oct 30, 2023

INSTUI-3923

test plan

  • open docs app at the Tray component and paste the following code:
function TrayContent() {
  React.useEffect(() => {
    console.log("TrayContent is loaded");

    return () => console.log("Tray content is unloaded");
  }, []);
  return <>This is a test.</>;
}

const FPO = lorem.paragraph()
class Example extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      open: false
    }
  }

  hideTray = () => {
    this.setState({
      open: false
    })
  }

  renderCloseButton () {
    return (
      <Flex>
        <Flex.Item shouldGrow shouldShrink>
          <Heading>Hello</Heading>
        </Flex.Item>
        <Flex.Item>
          <CloseButton
            placement="end"
            offset="small"
            screenReaderLabel="Close"
            onClick={this.hideTray}
          />
        </Flex.Item>
      </Flex>
    )
  }

  render () {
    return (
      <div style={{ padding: '0 0 16rem 0', margin: '0 auto' }}>
        <Button
          onClick={() => { this.setState({ open: true }) }}
          ref={(c) => this._showButton = c}
        >
          Show the Tray
        </Button>
        <Tray
          label="Tray Example"
          open={this.state.open}
          onDismiss={() => { this.setState({ open: false }) }}
          size="small"
          placement="start"
        >
          <View as="div" padding="medium">
            {this.renderCloseButton()}
            <Text as="p" lineHeight="double">{FPO}</Text>
            <TrayContent/>
          </View>
        </Tray>
      </div>
    )
  }
}

render(<Example />)
  • open and close the tray component
  • the mount and unmount logs should only appear once in the console

@github-actions
Copy link

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

@balzss balzss force-pushed the fix/tray-unmounts-twice branch from 9961e86 to a24751d Compare October 30, 2023 15:34
@balzss balzss self-assigned this Oct 31, 2023
@balzss balzss merged commit 1ec7647 into master Nov 3, 2023
4 checks passed
@balzss balzss deleted the fix/tray-unmounts-twice branch November 3, 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