-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(SidebarE): Use explicit refs with
Transition
Stops a deprecation warning for `findDOMNode` usage being throwin in React strict mode.
- Loading branch information
Showing
5 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 22 additions & 19 deletions
41
...ages/react-component-library/src/components/TopLevelNavigation/SidebarE/SidebarHandle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import React, { useContext } from 'react' | ||
import React, { useContext, forwardRef } from 'react' | ||
import { IconChevronLeft, IconChevronRight } from '@royalnavy/icon-library' | ||
|
||
import { ComponentWithClass } from '../../../common/ComponentWithClass' | ||
import { SidebarContext } from './context' | ||
import { StyledHandle } from './partials/StyledHandle' | ||
|
||
interface SidebarHandleProps extends ComponentWithClass { | ||
style?: React.CSSProperties | ||
style: React.CSSProperties | ||
} | ||
|
||
export const SidebarHandle: React.FC<SidebarHandleProps> = (props) => { | ||
const { isOpen, setIsOpen } = useContext(SidebarContext) | ||
export const SidebarHandle = forwardRef( | ||
(props: SidebarHandleProps, ref?: React.Ref<HTMLButtonElement>) => { | ||
const { isOpen, setIsOpen } = useContext(SidebarContext) | ||
|
||
function handleClick(e: React.MouseEvent<HTMLButtonElement>) { | ||
e.preventDefault() | ||
setIsOpen(!isOpen) | ||
} | ||
function handleClick(e: React.MouseEvent<HTMLButtonElement>) { | ||
e.preventDefault() | ||
setIsOpen(!isOpen) | ||
} | ||
|
||
return ( | ||
<StyledHandle | ||
onClick={handleClick} | ||
aria-label={`${isOpen ? 'Collapse' : 'Expand'} sidebar`} | ||
data-testid="sidebar-handle" | ||
{...props} | ||
> | ||
{isOpen ? <IconChevronLeft /> : <IconChevronRight />} | ||
</StyledHandle> | ||
) | ||
} | ||
return ( | ||
<StyledHandle | ||
ref={ref} | ||
onClick={handleClick} | ||
aria-label={`${isOpen ? 'Collapse' : 'Expand'} sidebar`} | ||
data-testid="sidebar-handle" | ||
{...props} | ||
> | ||
{isOpen ? <IconChevronLeft /> : <IconChevronRight />} | ||
</StyledHandle> | ||
) | ||
} | ||
) | ||
|
||
SidebarHandle.displayName = 'SidebarHandle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters