Skip to content

Commit

Permalink
fix(ui-tray): fix Tray component unmounting twice when closed
Browse files Browse the repository at this point in the history
  • Loading branch information
balzss committed Oct 30, 2023
1 parent a716ceb commit 9aae923
Showing 1 changed file with 54 additions and 51 deletions.
105 changes: 54 additions & 51 deletions packages/ui-tray/src/Tray/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,23 @@ class Tray extends Component<TrayProps> {
shadow: true,
border: false
}
ref: Element | null = null

state: TrayState = {
transitioning: false
constructor(props: TrayProps) {
super(props)
this.state = {
transitioning: false,
open: props.open
}
}
ref: Element | null = null

componentDidMount() {
this.props.makeStyles?.()
}

componentDidUpdate(prevProps: TrayProps, _prevState: TrayState) {
if (this.props.open !== prevProps.open) {
this.setState({ transitioning: true })
this.setState({ transitioning: true, open: this.props.open })
}
this.props.makeStyles?.()
}
Expand Down Expand Up @@ -163,7 +168,7 @@ class Tray extends Component<TrayProps> {
...props
} = this.props

const portalIsOpen = open || this.state.transitioning
const portalIsOpen = this.state.open || this.state.transitioning

Check failure on line 171 in packages/ui-tray/src/Tray/index.tsx

View workflow job for this annotation

GitHub Actions / pr_validation

Property 'open' does not exist on type 'Readonly<{}>'.

Check failure on line 171 in packages/ui-tray/src/Tray/index.tsx

View workflow job for this annotation

GitHub Actions / pr_validation

Property 'transitioning' does not exist on type 'Readonly<{}>'.

Check failure on line 171 in packages/ui-tray/src/Tray/index.tsx

View workflow job for this annotation

GitHub Actions / chromatic_deployment

Property 'open' does not exist on type 'Readonly<{}>'.

Check failure on line 171 in packages/ui-tray/src/Tray/index.tsx

View workflow job for this annotation

GitHub Actions / chromatic_deployment

Property 'transitioning' does not exist on type 'Readonly<{}>'.

return (
<Portal
Expand All @@ -172,54 +177,52 @@ class Tray extends Component<TrayProps> {
insertAt={insertAt}
mountNode={mountNode}
>
{portalIsOpen && (
<Transition
in={open}
type={this.transition}
onTransition={onTransition}
onEnter={onEnter}
onEntering={onEntering}
onEntered={createChainedFunction(
this.handleTransitionComplete,
onEntered,
onOpen
)}
onExit={onExit}
onExiting={onExiting}
onExited={createChainedFunction(
this.handleTransitionComplete,
onExited,
onClose
)}
transitionOnMount={transitionOnMount}
transitionEnter={transitionEnter}
transitionExit={transitionExit}
<Transition
in={open}
type={this.transition}
onTransition={onTransition}
onEnter={onEnter}
onEntering={onEntering}
onEntered={createChainedFunction(
this.handleTransitionComplete,
onEntered,
onOpen
)}
onExit={onExit}
onExiting={onExiting}
onExited={createChainedFunction(
this.handleTransitionComplete,
onExited,
onClose
)}
transitionOnMount={transitionOnMount}
transitionEnter={transitionEnter}
transitionExit={transitionExit}
>
<span
{...omitProps(props, Tray.allowedProps)}
css={this.props.styles?.tray}
ref={contentRef}
>
<span
{...omitProps(props, Tray.allowedProps)}
css={this.props.styles?.tray}
ref={contentRef}
<Dialog
as="div"
label={label}
defaultFocusElement={defaultFocusElement}
open
shouldContainFocus={
!this.state.transitioning && shouldContainFocus

Check failure on line 213 in packages/ui-tray/src/Tray/index.tsx

View workflow job for this annotation

GitHub Actions / pr_validation

Property 'transitioning' does not exist on type 'Readonly<{}>'.

Check failure on line 213 in packages/ui-tray/src/Tray/index.tsx

View workflow job for this annotation

GitHub Actions / chromatic_deployment

Property 'transitioning' does not exist on type 'Readonly<{}>'.
}
shouldReturnFocus={shouldReturnFocus}
shouldCloseOnDocumentClick={shouldCloseOnDocumentClick}
shouldCloseOnEscape
liveRegion={liveRegion}
onDismiss={onDismiss}
role={role}
>
<Dialog
as="div"
label={label}
defaultFocusElement={defaultFocusElement}
open
shouldContainFocus={
!this.state.transitioning && shouldContainFocus
}
shouldReturnFocus={shouldReturnFocus}
shouldCloseOnDocumentClick={shouldCloseOnDocumentClick}
shouldCloseOnEscape
liveRegion={liveRegion}
onDismiss={onDismiss}
role={role}
>
<div css={this.props.styles?.content}>{children}</div>
</Dialog>
</span>
</Transition>
)}
<div css={this.props.styles?.content}>{children}</div>
</Dialog>
</span>
</Transition>
</Portal>
)
}
Expand Down

0 comments on commit 9aae923

Please sign in to comment.