Skip to content

Commit

Permalink
fix: Dialog 開閉時にコンソールエラーが発生する問題を修正 (#4778)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Miyaji <[email protected]>
  • Loading branch information
s-sasaki-0529 and hiroki0525 authored Jul 16, 2024
1 parent d957a5a commit 8b5f3ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ export const AccordionPanelContent: FC<Props & ElementProps> = ({ className, ...
const isInclude = getIsInclude(expandedItems, name)
const wrapperRef = useRef<HTMLDivElement>(null)
const styles = useMemo(() => accordionPanelContent({ className }), [className])
const nodeRef = useRef<HTMLDivElement>(null)

return (
<Transition in={isInclude} timeout={150} nodeRef={nodeRef}>
<Transition in={isInclude} timeout={150} nodeRef={wrapperRef}>
{(status) => (
<div
{...props}
Expand Down
23 changes: 20 additions & 3 deletions packages/smarthr-ui/src/components/Dialog/DialogOverlap.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import React, { FC, PropsWithChildren, ReactNode, useEffect, useMemo, useState } from 'react'
import React, {
FC,
PropsWithChildren,
ReactNode,
useEffect,
useMemo,
useRef,
useState,
} from 'react'
import { CSSTransition } from 'react-transition-group'
import { tv } from 'tailwind-variants'

Expand Down Expand Up @@ -28,6 +36,7 @@ const dialogOverlap = tv({
export const DialogOverlap: FC<Props> = ({ isOpen, children }) => {
const styles = useMemo(() => dialogOverlap(), [])
const [childrenBuffer, setChildrenBuffer] = useState<ReactNode>(null)
const nodeRef = useRef<HTMLDivElement>(null)

useEffect(() => {
if (isOpen) {
Expand All @@ -36,8 +45,16 @@ export const DialogOverlap: FC<Props> = ({ isOpen, children }) => {
}, [isOpen, children])

return (
<CSSTransition classNames="shr-dialog-transition" in={isOpen} timeout={300} unmountOnExit>
<div className={styles}>{isOpen ? children : childrenBuffer}</div>
<CSSTransition
classNames="shr-dialog-transition"
in={isOpen}
timeout={300}
unmountOnExit
nodeRef={nodeRef}
>
<div ref={nodeRef} className={styles}>
{isOpen ? children : childrenBuffer}
</div>
</CSSTransition>
)
}

0 comments on commit 8b5f3ae

Please sign in to comment.