SidePanel
Renders a side panel with an overlay over the app.
Usage
Demonstration
Props
children
children
The content of the sidepanel.
title
title
The main title for the panel.
opened
opened
Toggles the visibility of the panel. Note: when the panel finishes closing, the children components will get unmounted.
onClose
onClose
Gets called when the user tries to close the panel, by clicking on the close button or the overlay.
blocking
blocking
When set, removes the ability to close the panel by using the close button or the overlay.
Related hooks
useSidePanel()
This hook should be used inside SidePanel
, and returns an object with two entries:
status
represents the current state of the panel:opened
,closed
,opening
,closing
.readyToFocus
can be used to focus an element as soon as possible inside the panel without affecting the transition.
About the need to have readyToFocus
: browser engines tend to force newly focused elements to move inside the viewport, skipping current transitions in the process. readyToFocus
detects that the transition is half way, which is generally a safe point to start focusing an element without any transition issue. If you still notice a transition issue, another option is to use status === 'opened'
.
Example
And because calling .focus()
on a reference is a very common use case, another hook is provided to do it easily: useSidePanelFocusOnReady()
.
useSidePanelFocusOnReady()
This hook can be used to focus a ref (usually a TextInput
) when readyToFocus
is set to true
.
It takes a React ref as a parameter, or creates one if not provided. It returns this ref.
This is how useSidePanelFocusOnReady()
can be used:
Last updated