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: Dialog 開閉時にコンソールエラーが発生する問題を修正 #4778

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

で 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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dialog コンポーネントでも同様のエラーが発生していたのであわせて修正。
これで SmartHR UI 内の react-transition-group を使ってる箇所は全部になります。

</CSSTransition>
)
}