Skip to content

Commit 84ad8f3

Browse files
committed
fix: findDOMNode is deprecated in StrictMode
1 parent 0590bde commit 84ad8f3

File tree

11 files changed

+50
-15
lines changed

11 files changed

+50
-15
lines changed

packages/coreui-react/src/components/alert/CAlert.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import React, { forwardRef, HTMLAttributes, useEffect, useState } from 'react'
1+
import React, { forwardRef, HTMLAttributes, useEffect, useState, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import { Transition } from 'react-transition-group'
55

66
import { Colors, colorPropType } from '../Types'
77
import { CCloseButton } from '../close-button/CCloseButton'
88

9+
import { useForkedRef } from '../../utils/hooks'
10+
911
export interface CAlertProps extends HTMLAttributes<HTMLDivElement> {
1012
/**
1113
* A string of all className you want applied to the component.
@@ -49,6 +51,8 @@ export const CAlert = forwardRef<HTMLDivElement, CAlertProps>(
4951
},
5052
ref,
5153
) => {
54+
const alertRef = useRef<HTMLDivElement>(null)
55+
const forkedRef = useForkedRef(ref, alertRef)
5256
const [_visible, setVisible] = useState(visible)
5357

5458
useEffect(() => {
@@ -69,15 +73,22 @@ export const CAlert = forwardRef<HTMLDivElement, CAlertProps>(
6973
}
7074

7175
return (
72-
<Transition in={_visible} mountOnEnter onExit={onClose} timeout={150} unmountOnExit>
76+
<Transition
77+
in={_visible}
78+
mountOnEnter
79+
nodeRef={alertRef}
80+
onExit={onClose}
81+
timeout={150}
82+
unmountOnExit
83+
>
7384
{(state) => {
7485
const transitionClass = getTransitionClass(state)
7586
return (
7687
<div
7788
className={classNames(_className, transitionClass)}
7889
role="alert"
7990
{...rest}
80-
ref={ref}
91+
ref={forkedRef}
8192
>
8293
{children}
8394
{dismissible && <CCloseButton onClick={() => setVisible(false)} />}

packages/coreui-react/src/components/backdrop/CBackdrop.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React, { forwardRef, HTMLAttributes } from 'react'
1+
import React, { forwardRef, HTMLAttributes, useRef } from 'react'
22
import { Transition } from 'react-transition-group'
33
import PropTypes from 'prop-types'
44
import classNames from 'classnames'
55

6+
import { useForkedRef } from '../../utils/hooks'
7+
68
export interface CBackdropProps extends HTMLAttributes<HTMLDivElement> {
79
/**
810
* A string of all className you want applied to the base component.
@@ -16,17 +18,22 @@ export interface CBackdropProps extends HTMLAttributes<HTMLDivElement> {
1618

1719
export const CBackdrop = forwardRef<HTMLDivElement, CBackdropProps>(
1820
({ className = 'modal-backdrop', visible, ...rest }, ref) => {
21+
const backdropRef = useRef<HTMLDivElement>(null)
22+
const forkedRef = useForkedRef(ref, backdropRef)
23+
1924
const _className = classNames(className, 'fade')
2025

2126
const getTransitionClass = (state: string) => {
2227
return state === 'entered' && 'show'
2328
}
2429

2530
return (
26-
<Transition in={visible} mountOnEnter timeout={150} unmountOnExit>
31+
<Transition in={visible} mountOnEnter nodeRef={backdropRef} timeout={150} unmountOnExit>
2732
{(state) => {
2833
const transitionClass = getTransitionClass(state)
29-
return <div className={classNames(_className, transitionClass)} {...rest} ref={ref} />
34+
return (
35+
<div className={classNames(_className, transitionClass)} {...rest} ref={forkedRef} />
36+
)
3037
}}
3138
</Transition>
3239
)

packages/coreui-react/src/components/collapse/CCollapse.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
9898
return (
9999
<CSSTransition
100100
in={visible}
101+
nodeRef={collapseRef}
101102
onEntering={onEntering}
102103
onEntered={onEntered}
103104
onExit={onExit}

packages/coreui-react/src/components/modal/CModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
228228
<Transition
229229
in={_visible}
230230
mountOnEnter
231+
nodeRef={modalRef}
231232
onEnter={onShow}
232233
onExit={onClose}
233234
unmountOnExit={unmountOnClose}

packages/coreui-react/src/components/nav/CNavGroup.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export const CNavGroup = forwardRef<HTMLLIElement, CNavGroupProps>(
106106
)}
107107
<Transition
108108
in={_visible}
109+
nodeRef={navItemsRef}
109110
onEntering={onEntering}
110111
onEntered={onEntered}
111112
onExit={onExit}

packages/coreui-react/src/components/offcanvas/COffcanvas.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
137137
<>
138138
<Transition
139139
in={_visible}
140+
nodeRef={offcanvasRef}
140141
onEnter={onShow}
141142
onEntered={() => offcanvasRef.current?.focus()}
142143
onExit={onHide}

packages/coreui-react/src/components/popover/CPopover.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, ReactElement, ReactNode, useState } from 'react'
1+
import React, { FC, ReactElement, ReactNode, useRef, useState } from 'react'
22
import { createPortal } from 'react-dom'
33
import PropTypes from 'prop-types'
44
import classNames from 'classnames'
@@ -59,6 +59,7 @@ export const CPopover: FC<CPopoverProps> = ({
5959
...rest
6060
}) => {
6161
const [_visible, setVisible] = useState(visible)
62+
const popoverRef = useRef()
6263

6364
const getTransitionClass = (state: string) => {
6465
return state === 'entering'
@@ -94,9 +95,10 @@ export const CPopover: FC<CPopoverProps> = ({
9495
createPortal(
9596
<Transition
9697
in={_visible}
98+
mountOnEnter
99+
nodeRef={popoverRef}
97100
onEnter={onShow}
98101
onExit={onHide}
99-
mountOnEnter
100102
timeout={{
101103
enter: 0,
102104
exit: 200,

packages/coreui-react/src/components/tabs/CTabPane.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { HTMLAttributes, forwardRef } from 'react'
1+
import React, { HTMLAttributes, forwardRef, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import { Transition } from 'react-transition-group'
55

6+
import { useForkedRef } from '../../utils/hooks'
67
export interface CTabPaneProps extends HTMLAttributes<HTMLDivElement> {
78
/**
89
* A string of all className you want applied to the base component.
@@ -24,6 +25,9 @@ export interface CTabPaneProps extends HTMLAttributes<HTMLDivElement> {
2425

2526
export const CTabPane = forwardRef<HTMLDivElement, CTabPaneProps>(
2627
({ children, className, onHide, onShow, visible, ...rest }, ref) => {
28+
const tabPaneRef = useRef()
29+
const forkedRef = useForkedRef(ref, tabPaneRef)
30+
2731
const getTransitionClass = (state: string) => {
2832
return state === 'entered' && 'show'
2933
}
@@ -37,11 +41,11 @@ export const CTabPane = forwardRef<HTMLDivElement, CTabPaneProps>(
3741
className,
3842
)
3943
return (
40-
<Transition in={visible} onEnter={onShow} onExit={onHide} timeout={150}>
44+
<Transition in={visible} nodeRef={tabPaneRef} onEnter={onShow} onExit={onHide} timeout={150}>
4145
{(state) => {
4246
const transitionClass = getTransitionClass(state)
4347
return (
44-
<div className={classNames(_className, transitionClass)} {...rest} ref={ref}>
48+
<div className={classNames(_className, transitionClass)} {...rest} ref={forkedRef}>
4549
{children}
4650
</div>
4751
)

packages/coreui-react/src/components/toast/CToast.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import classNames from 'classnames'
1212

1313
import { Colors, colorPropType } from '../Types'
1414

15+
import { useForkedRef } from '../../utils/hooks'
16+
1517
export interface CToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
1618
/**
1719
* Apply a CSS fade transition to the toast.
@@ -82,6 +84,8 @@ export const CToast = forwardRef<HTMLDivElement, CToastProps>(
8284
},
8385
ref,
8486
) => {
87+
const toastRef = useRef()
88+
const forkedRef = useForkedRef(ref, toastRef)
8589
const [_visible, setVisible] = useState(false)
8690
const timeout = useRef<number>()
8791

@@ -133,6 +137,7 @@ export const CToast = forwardRef<HTMLDivElement, CToastProps>(
133137
return (
134138
<Transition
135139
in={_visible}
140+
nodeRef={toastRef}
136141
onEnter={() => onShow && onShow(index ? index : null)}
137142
onExited={() => onClose && onClose(index ? index : null)}
138143
timeout={250}
@@ -151,7 +156,7 @@ export const CToast = forwardRef<HTMLDivElement, CToastProps>(
151156
onMouseLeave={() => _autohide}
152157
{...rest}
153158
key={key}
154-
ref={ref}
159+
ref={forkedRef}
155160
>
156161
{children}
157162
</div>

packages/coreui-react/src/components/tooltip/CTooltip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, ReactElement, ReactNode, useState } from 'react'
1+
import React, { FC, ReactElement, ReactNode, useRef, useState } from 'react'
22
import { createPortal } from 'react-dom'
33
import PropTypes from 'prop-types'
44
import classNames from 'classnames'
@@ -48,6 +48,7 @@ export const CTooltip: FC<CTooltipProps> = ({
4848
visible,
4949
...rest
5050
}) => {
51+
const tooltipRef = useRef()
5152
const [_visible, setVisible] = useState(visible)
5253

5354
const getTransitionClass = (state: string) => {
@@ -85,6 +86,7 @@ export const CTooltip: FC<CTooltipProps> = ({
8586
<Transition
8687
in={_visible}
8788
mountOnEnter
89+
nodeRef={tooltipRef}
8890
onEnter={onShow}
8991
onExit={onHide}
9092
timeout={{

0 commit comments

Comments
 (0)