diff --git a/packages/react-component-library/jest/setupTests.js b/packages/react-component-library/jest/setupTests.js index 9b2dd791ff..a1aec8cee8 100644 --- a/packages/react-component-library/jest/setupTests.js +++ b/packages/react-component-library/jest/setupTests.js @@ -6,7 +6,7 @@ import { format } from 'util' const originalConsoleError = global.console.error global.console.error = (...args) => { - const reactFailures = [/Failed prop type/, /Warning: /] + const reactFailures = [/Failed prop type/, /Warning: /, /StrictMode/] if (reactFailures.some((p) => p.test(args[0]))) { originalConsoleError(...args) diff --git a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.test.tsx b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.test.tsx index 432e09a5d8..e46077aef9 100644 --- a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.test.tsx +++ b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.test.tsx @@ -53,6 +53,20 @@ const notifications = ( describe('SidebarE', () => { let wrapper: RenderResult + describe('when rendered in React strict mode', () => { + it('should not throw deprecation warning about findDOMNode', () => { + expect(() => { + wrapper = render( + + + + ) + + fireEvent.mouseOver(wrapper.getByTestId('sidebar')) + }).not.toThrowError(/findDOMNode is deprecated in StrictMode/) + }) + }) + describe('when composed with minimal props', () => { beforeEach(() => { wrapper = render() diff --git a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.tsx b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.tsx index 1d2aa50b39..0cbc01db47 100644 --- a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.tsx +++ b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarE.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useRef } from 'react' import { Transition } from 'react-transition-group' import { SidebarHandle } from './SidebarHandle' @@ -45,6 +45,8 @@ export const SidebarE: React.FC = ({ notifications, ...rest }) => { + const nodeRef = useRef(null) + return ( @@ -56,9 +58,17 @@ export const SidebarE: React.FC = ({ onMouseLeave={(_) => setHasMouseOver(false)} {...rest} > - + {(state) => ( - + )} {title && ( diff --git a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarHandle.tsx b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarHandle.tsx index e66f26cbc8..a06c433d1e 100644 --- a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarHandle.tsx +++ b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarHandle.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react' +import React, { useContext, forwardRef } from 'react' import { IconChevronLeft, IconChevronRight } from '@royalnavy/icon-library' import { ComponentWithClass } from '../../../common/ComponentWithClass' @@ -6,27 +6,30 @@ import { SidebarContext } from './context' import { StyledHandle } from './partials/StyledHandle' interface SidebarHandleProps extends ComponentWithClass { - style?: React.CSSProperties + style: React.CSSProperties } -export const SidebarHandle: React.FC = (props) => { - const { isOpen, setIsOpen } = useContext(SidebarContext) +export const SidebarHandle = forwardRef( + (props: SidebarHandleProps, ref?: React.Ref) => { + const { isOpen, setIsOpen } = useContext(SidebarContext) - function handleClick(e: React.MouseEvent) { - e.preventDefault() - setIsOpen(!isOpen) - } + function handleClick(e: React.MouseEvent) { + e.preventDefault() + setIsOpen(!isOpen) + } - return ( - - {isOpen ? : } - - ) -} + return ( + + {isOpen ? : } + + ) + } +) SidebarHandle.displayName = 'SidebarHandle' diff --git a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarNavItemE.tsx b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarNavItemE.tsx index 771fdc1766..78925d17f5 100644 --- a/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarNavItemE.tsx +++ b/packages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarNavItemE.tsx @@ -1,4 +1,4 @@ -import React, { useState, useContext } from 'react' +import React, { useState, useContext, useRef } from 'react' import { Transition } from 'react-transition-group' import { SidebarSubNav } from './SidebarSubNav' @@ -34,15 +34,22 @@ export const SidebarNavItemE: React.FC = ({ const [hasMouseOver, setHasMouseOver] = useState(false) const { isOpen } = useContext(SidebarContext) const linkElement = link as React.ReactElement + const nodeRef = useRef(null) const item = React.cloneElement(linkElement, { ...link.props, children: ( <> {icon && {icon}} - + {(state) => (