Labels
Trays require an accessibility label, which we set to title
by default. However, if you don't want to provide a title
or there's other text that gives the user better context to the tray, then you can pass an element id to accessibilityLabelledBy
. Alternatively, you may directly provide a contextual label to accessibilityLabel
.
Basic usage with Callback
The recommended way to use a Tray
is by passing a callback as children, which receives a handleClose
function:
Using Ref to Control the Tray
Trigger Focus
A ref
to the trigger that opens the tray, along with an onClosedComplete
method to reset focus on the trigger when the tray closes, needs to be wired up for accessibility (see code example below).
You can also control the Tray using a ref, which provides a close()
method:
Scrollable Content
Trays with long content will automatically be scrollable.
Non-Dismissible Tray
Trays can be configured to prevent the user from dismissing the tray by clicking close, clicking outside, or pressing ESC.
Multiple Overlay Flow
When transitioning between overlays, ensure proper dismounting using onCloseComplete
:
Note: The Tray component is an elevated container that is pinned to the bottom of the screen and provides a standardized way to present bottom sheets in your web application. Key points:
- Use
onCloseComplete
for cleanup when the tray is dismissed - Children can be either a React node or a render function that receives a
handleClose
function - The
ref
providesopen()
andclose()
methods for controlling the tray - When transitioning between overlays, ensure proper dismounting using lifecycle methods