Filters
Side sheets show secondary content anchored to the side of the screen. Use a side sheet to provide optional content and actions without interrupting the main content, from a list of actions to supplemental content in a table.
A SideSheet comes in two variants:
- Standard (the default): The sheet sits beside the page's body, at the end of a row that makes room for it, and the page remains in use. Standard sheets are used mostly in medium to expanded windows, like tablet and desktop.
- Modal, with
isModal: The sheet opens in front of the page over a scrim and stays until it is closed. Modal sheets are preferred in compact windows, like mobile.
In compact windows, consider a bottom sheet instead.
A side sheet is composed of these parts:
| Part | Use |
|---|---|
SheetTrigger | The trigger. Wraps the button that opens the sheet and the SideSheet, with the button first. Without it, control the sheet with isOpen and onOpenChange. |
SideSheet | The sheet: a standard sheet (the default) or, with isModal, a modal sheet |
SideSheetHeader | The header, first in the sheet. It holds the headline and the icon buttons. See Header, content and actions. |
import { SheetTrigger, SideSheet, SideSheetHeader } from '@material-web/react'
import { Heading } from 'react-aria-components'Basic side sheet
Wrap the button that opens the sheet and the sheet in a SheetTrigger. Write the sheet's content as its children: a SideSheetHeader first, then the rest, as described under Header, content and actions. This sheet is a modal sheet.
import {
Button,
Checkbox,
Divider,
Icon,
IconButton,
SheetTrigger,
SideSheet,
SideSheetHeader,
} from '@material-web/react'
import { Heading } from 'react-aria-components'
const labels = ['Events', 'Personal', 'Projects', 'Reminders', 'Family', 'Travel', 'Work']
export default function Basic() {
return (
<SheetTrigger>
<Button variant="tonal">Show filters</Button>
<SideSheet isModal>
<SideSheetHeader>
<Heading slot="title">Filters</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<div className="flex min-h-0 grow flex-col items-start overflow-y-auto px-space-300 py-space-200 text-body-lg">
{labels.map((label) => (
<Checkbox key={label} className="h-14 shrink-0">
{label}
</Checkbox>
))}
</div>
<Divider />
<div className="flex gap-space-100 px-space-300 pt-space-200 pb-space-300">
<Button variant="filled" slot="close">
Save
</Button>
<Button variant="outlined" slot="close">
Cancel
</Button>
</div>
</SideSheet>
</SheetTrigger>
)
}Modal side sheet
Set isModal for a modal sheet. It is at the end edge of the window and as tall as the window. Without a trigger, control the sheet with isOpen and onOpenChange, or set defaultOpen to start with it open, as with React Aria's Sheet.
While a modal sheet is open, the page behind it cannot be used or scrolled, and the focus stays in the sheet. A menu in a modal sheet opens in front of it. Another dialog or modal sheet opened from it shows in front of it, and Escape closes the one in front.
Dismissal
A click on the scrim, Escape, and a swipe toward the end edge of the window close a modal sheet. Set preventDismissal to turn all of these off. Every side sheet needs a close icon button: put one in the header with slot="close". Any other button in the sheet with slot="close", such as an action, closes it too.
import {
Button,
Divider,
Icon,
IconButton,
SheetTrigger,
SideSheet,
SideSheetHeader,
TextField,
} from '@material-web/react'
import { Heading } from 'react-aria-components'
export default function PreventDismissal() {
return (
<SheetTrigger>
<Button variant="tonal">Edit profile</Button>
<SideSheet isModal preventDismissal>
<SideSheetHeader>
<Heading slot="title">Edit profile</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<div className="min-h-0 grow overflow-y-auto px-space-300 py-space-200">
<TextField label="Display name" variant="outlined" className="w-full" />
</div>
<Divider />
<div className="flex gap-space-100 px-space-300 pt-space-200 pb-space-300">
<Button variant="filled" slot="close">
Save
</Button>
<Button variant="outlined" slot="close">
Cancel
</Button>
</div>
</SideSheet>
</SheetTrigger>
)
}To decide for each press outside the sheet whether it closes the sheet, pass a function as shouldCloseOnInteractOutside. It receives the pressed element, and the sheet stays open when it returns false.
Swiping
A swipe toward the end edge of the window closes a modal sheet. A swipe released part way either returns the sheet to its place or closes it. With preventDismissal, a swipe does not move the sheet. A finger swipes the sheet, and a mouse does not drag it.
A side sheet has no snapPoints, and a standard sheet cannot be swiped.
Standard side sheet
Without isModal, a sheet is a standard sheet. It has no scrim, and the page beside it remains in use.
A standard sheet is a flex item. Write it after the body, in a row as tall as the sheet should be (flex h-dvh, for example), and give the body min-w-0 grow. The sheet stretches to the row's height at the end of the row.
<div className="flex h-dvh">
<main className="min-w-0 grow">…</main>
<SideSheet isOpen={info} onOpenChange={setInfo}>
…
</SideSheet>
</div>A standard sheet shows unless isOpen is false. Pass onOpenChange to let it be dismissed: Escape in the sheet and a button with slot="close" each call onOpenChange with false. The sheet stays until you set isOpen to false. Without onOpenChange, Escape does nothing in the sheet.
When a standard sheet is shown, the focus moves to the first focusable element in it, such as the close button. Tab then moves the focus out to the page. When the sheet is hidden, the focus returns to where it was.
In this example, a box stands in for the row. The info button shows and hides the sheet, and the body shrinks and grows to make room for it. The close button and Escape hide the sheet too.
import { Icon, IconButton, SideSheet, SideSheetHeader } from '@material-web/react'
import { useState } from 'react'
import { Heading } from 'react-aria-components'
export default function Standard() {
const [isOpen, setOpen] = useState(false)
return (
<div className="flex h-96 w-full bg-surface">
<div className="box-border min-w-0 grow overflow-y-auto p-space-300">
<div className="flex items-center justify-between pb-space-200">
<span className="text-title-lg">Cassette Futurism</span>
<IconButton aria-label="Info" onPress={() => setOpen(!isOpen)}>
<Icon name="info" />
</IconButton>
</div>
<div className="h-40 rounded-shape-md bg-tertiary-container" />
</div>
<SideSheet isOpen={isOpen} onOpenChange={setOpen}>
<SideSheetHeader>
<Heading slot="title">Info</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<dl className="m-0 grid min-h-0 grow grid-cols-2 content-start gap-space-100 overflow-y-auto px-space-300 py-space-200">
<dt className="text-on-surface-variant">Artist</dt>
<dd className="m-0">Various artists</dd>
<dt className="text-on-surface-variant">Tracks</dt>
<dd className="m-0">12</dd>
<dt className="text-on-surface-variant">Length</dt>
<dd className="m-0">48 min</dd>
</dl>
</SideSheet>
</div>
)
}Slots
- title
- close
| Slot | Child | Use |
|---|---|---|
title | A Heading, in the header | The sheet's headline, which names the sheet. It is an <h2> unless you set its level. |
close | Any button | Closes the sheet after its own onPress |
Write a back icon button before the headline if the sheet needs one, and the close icon button after the headline, following any other icon buttons. With no headline, the last button is still at the end of the header.
Header, content and actions
A side sheet is composed of these parts, from top to bottom:
| Part | Use |
|---|---|
SideSheetHeader | The header, first in the sheet. It holds the headline and the icon buttons. |
| Content | The rest of the sheet's content, laid out in a column, which scrolls vertically as a whole when it is taller than the sheet |
| Actions | For bottom actions, a row of Buttons under a Divider |
Give the content its side padding, and lay out the actions, with the theme's classes:
<SideSheet>
<SideSheetHeader>…</SideSheetHeader>
<div className="px-space-300">…</div>
<Divider />
<div className="flex gap-space-100 px-space-300 pt-space-200 pb-space-300">…</div>
</SideSheet>To scroll the content on its own instead of with the sheet, between the header and the actions, give it min-h-0 grow overflow-y-auto.
A sheet can hold more than one region. In this example, a section opened from the list shows a back icon button before its headline, which returns to the list.
import {
Button,
Icon,
IconButton,
List,
ListItem,
SheetTrigger,
SideSheet,
SideSheetHeader,
} from '@material-web/react'
import { useState } from 'react'
import { Heading, Text } from 'react-aria-components'
const sections = ['Labels', 'Format', 'Last modified']
function Filters() {
const [section, setSection] = useState<string | null>(null)
return (
<>
<SideSheetHeader>
{section && (
<IconButton aria-label="Back" onPress={() => setSection(null)}>
<Icon name="arrow_back" className="rtl:icon-mirrored" />
</IconButton>
)}
<Heading slot="title">{section ?? 'Filters'}</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
{section ? (
<p className="m-0 px-space-300 py-space-200 text-on-surface-variant">
Choose what to filter by {section.toLowerCase()}.
</p>
) : (
<List aria-label="Filters" className="grow overflow-y-auto">
{sections.map((name) => (
<ListItem
key={name}
id={name}
textValue={name}
className="bg-transparent"
onAction={() => setSection(name)}
>
<Text slot="label">{name}</Text>
<Icon slot="trailing" name="chevron_right" className="rtl:icon-mirrored" />
</ListItem>
))}
</List>
)}
</>
)
}
export default function BackButton() {
return (
<SheetTrigger>
<Button variant="tonal">Filter files</Button>
<SideSheet isModal>
<Filters />
</SideSheet>
</SheetTrigger>
)
}Detached side sheet
Set isDetached to inset either sheet 16dp from the edges of the window, or of its row, with rounded corners all around.
import {
Button,
Icon,
IconButton,
SheetTrigger,
SideSheet,
SideSheetHeader,
} from '@material-web/react'
import { Heading } from 'react-aria-components'
export default function ModalDetached() {
return (
<SheetTrigger>
<Button variant="tonal">Show details</Button>
<SideSheet isModal isDetached>
<SideSheetHeader>
<Heading slot="title">Details</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<p className="m-0 px-space-300 py-space-200 text-on-surface-variant">
Twelve tracks by various artists, 48 minutes.
</p>
</SideSheet>
</SheetTrigger>
)
}A detached standard sheet keeps the same margin from the body. In this example, the sheet's className sets bg-surface-container to set it off from the body.
import { Icon, IconButton, SideSheet, SideSheetHeader } from '@material-web/react'
import { useState } from 'react'
import { Heading } from 'react-aria-components'
export default function Detached() {
const [isOpen, setOpen] = useState(false)
return (
<div className="flex h-96 w-full bg-surface">
<div className="box-border min-w-0 grow overflow-y-auto p-space-300">
<div className="flex items-center justify-between pb-space-200">
<span className="text-title-lg">Cassette Futurism</span>
<IconButton aria-label="Info" onPress={() => setOpen(!isOpen)}>
<Icon name="info" />
</IconButton>
</div>
<div className="h-40 rounded-shape-md bg-tertiary-container" />
</div>
<SideSheet isDetached className="bg-surface-container" isOpen={isOpen} onOpenChange={setOpen}>
<SideSheetHeader>
<Heading slot="title">Info</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<p className="m-0 px-space-300 py-space-200 text-on-surface-variant">
Twelve tracks by various artists, 48 minutes.
</p>
</SideSheet>
</div>
)
}Responsive
A modal sheet in a compact window can become a standard sheet in a wider one. Set isModal from your own breakpoint, and control the sheet with isOpen and onOpenChange, which both variants take.
In this example, the sheet is modal in a window narrower than 600dp, the theme's medium breakpoint, and standard in a wider one.
import { Icon, IconButton, SideSheet, SideSheetHeader } from '@material-web/react'
import { useState, useSyncExternalStore } from 'react'
import { Heading } from 'react-aria-components'
// A compact window: one narrower than the theme's medium breakpoint.
const compact = '(width < 600px)'
function subscribe(onChange: () => void) {
const query = window.matchMedia(compact)
query.addEventListener('change', onChange)
return () => query.removeEventListener('change', onChange)
}
export default function Responsive() {
const isCompact = useSyncExternalStore(
subscribe,
() => window.matchMedia(compact).matches,
() => false,
)
const [isOpen, setOpen] = useState(false)
return (
<div className="flex h-96 w-full bg-surface">
<div className="box-border min-w-0 grow overflow-y-auto p-space-300">
<div className="flex items-center justify-between pb-space-200">
<span className="text-title-lg">Cassette Futurism</span>
<IconButton aria-label="Info" onPress={() => setOpen(!isOpen)}>
<Icon name="info" />
</IconButton>
</div>
<div className="h-40 rounded-shape-md bg-tertiary-container" />
</div>
<SideSheet isModal={isCompact} isOpen={isOpen} onOpenChange={setOpen}>
<SideSheetHeader>
<Heading slot="title">Info</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<p className="m-0 px-space-300 py-space-200 text-on-surface-variant">
Twelve tracks by various artists, 48 minutes.
</p>
</SideSheet>
</div>
)
}Note: Changing isModal while a sheet is shown remounts its content, so the content's scroll position and state are lost.
Right to left
A standard sheet follows the page's dir, and a modal sheet follows the locale, which I18nProvider sets. For a right-to-left language, set both: either sheet is then at the left edge, with its layout mirrored. See Internationalization.
Customization
Pass classes in className to restyle one sheet. className, style and ref apply to the sheet's container. See Styling for the classes, the states and the theme.
- States: While a standard sheet appears and leaves, it has
data-enteringanddata-exiting. See States. - Functions:
className,styleandchildrencan be functions of the sheet's state, on a standard sheet and a modal one alike:state, whoseclose()closes the sheet,isEntering,isExiting,isExpanded(true once the whole sheet shows),position,swipeDirection,stackIndexandhasDescendants. See Children as a function. - Ancestors: A modal sheet is rendered at the end of the page, not inside the element it is written in. A class or a
data-themeon an element around it does not reach it: set it on theSideSheetitself, or on the root element. A standard sheet is rendered where it is written. See Theme. - Attributes: A
SideSheetalso takes attributes and events of its<div>, such asidandonClick.
Width
A sheet is 256dp wide by default. To set another width, add a side-sheet-width-* class to its className. The value is a number on Tailwind's spacing scale (side-sheet-width-90), a spacing token (side-sheet-width-space-900) or any length (side-sheet-width-[22rem]). A sheet is no wider than 400dp, and a modal sheet no wider than the window less its margins.
Note: Set the width with side-sheet-width-*, not with w-*.
import {
Button,
Icon,
IconButton,
Radio,
RadioGroup,
SheetTrigger,
SideSheet,
SideSheetHeader,
} from '@material-web/react'
import { Heading } from 'react-aria-components'
export default function Width() {
return (
<SheetTrigger>
<Button variant="tonal">Open settings</Button>
<SideSheet isModal className="side-sheet-width-90">
<SideSheetHeader>
<Heading slot="title">Settings</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<RadioGroup
aria-label="Density"
defaultValue="default"
className="flex flex-col items-start px-space-300 py-space-200 text-body-lg"
>
{['Default', 'Comfortable', 'Compact'].map((name) => (
<Radio key={name} className="h-14" value={name.toLowerCase()}>
{name}
</Radio>
))}
</RadioGroup>
</SideSheet>
</SheetTrigger>
)
}Divider
To show a divider at the start of a standard sheet that is not detached, set className="border-s border-outline-variant". Without Tailwind's Preflight, add border-0 border-solid as well.
import { Icon, IconButton, SideSheet, SideSheetHeader } from '@material-web/react'
import { useState } from 'react'
import { Heading } from 'react-aria-components'
export default function WithDivider() {
const [isOpen, setOpen] = useState(false)
return (
<div className="flex h-96 w-full bg-surface">
<div className="box-border min-w-0 grow overflow-y-auto p-space-300">
<div className="flex items-center justify-between pb-space-200">
<span className="text-title-lg">Cassette Futurism</span>
<IconButton aria-label="Info" onPress={() => setOpen(!isOpen)}>
<Icon name="info" />
</IconButton>
</div>
<div className="h-40 rounded-shape-md bg-tertiary-container" />
</div>
<SideSheet
className="border-0 border-s border-solid border-outline-variant"
isOpen={isOpen}
onOpenChange={setOpen}
>
<SideSheetHeader>
<Heading slot="title">Info</Heading>
<IconButton aria-label="Close" slot="close">
<Icon name="close" />
</IconButton>
</SideSheetHeader>
<p className="m-0 px-space-300 py-space-200 text-on-surface-variant">
Twelve tracks by various artists, 48 minutes.
</p>
</SideSheet>
</div>
)
}Use cases
Material lists what people should be able to do with assistive technology:
- Dismiss the side sheet
Interaction and style
- Color contrast: The headline has 4.5:1 contrast or more with the container of either sheet, in light and dark schemes at every contrast level.
- Motion: With reduced motion, a modal sheet opens at once, and a standard sheet shows and hides at once.
- Forced colors: Either sheet keeps an edge in forced colors.
- Right to left: In a right-to-left language, either sheet is at the left edge, with its layout mirrored. See Right to left.
- Close button: Material requires a close affordance in every side sheet: put a close icon button in the header, with
slot="close"and anaria-label. It closes a modal sheet even withpreventDismissal, and asks a standard sheet to hide throughonOpenChange.
Focus
- When a modal sheet opens, the focus moves to the sheet itself, and Tab then moves it to the close button. To focus an element as the sheet opens, give it
autoFocus. - While a modal sheet is open, the focus stays in the sheet. When the sheet closes by Escape or a close button, the focus returns to its trigger.
- When a standard sheet is shown, the focus moves to the first focusable element in it, such as the close button. When the sheet is hidden, the focus returns to where it was.
- A standard sheet does not keep the focus: Tab moves it out to the page.
- Tab moves through the header first and then the content, in the order written, as Material shows: write the
SideSheetHeaderfirst and the actions last.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus to the next button in the sheet |
| Space or Enter | Press the focused button, such as the close button |
| Escape | Close a modal sheet, or a standard sheet that has an onOpenChange |
- Escape closes a modal sheet, or the one in front when one is over another, unless
preventDismissalis set. - Escape dismisses a standard sheet only while the focus is in the sheet, and only one that has an
onOpenChange.
Labeling elements
- A side sheet has the
dialogrole, as Material advises. Setroletoalertdialogto change it. - The header's
Headingin thetitleslot names the sheet, unless you set anaria-label. You can also setaria-labelledbyandaria-describedby. Render the headline when the sheet is first shown: a headline added later does not name the sheet. - With neither a headline nor an
aria-label, a modal sheet is named by its trigger's text. - Describe a modal sheet that has
role="alertdialog"with aTextin thedescriptionslot. - An
IconButtonin the header has no visible label, so give each anaria-labelthat names its action, such as Close or Back. See Icon button. - The button of a
SheetTriggerreports whether the modal sheet is open witharia-expanded. - While a modal sheet is open, the page behind it is hidden from assistive technology.
SideSheet
isModalbooleanDefaultfalseTwo variants: standard and modal
Standard side sheets display content that complements the screen’s primary content. They remain visible while people interact with primary content.
Modal side sheets are preferred in compact breakpoints, like mobile, due to limited screen size.
They can display the same kinds of content as standard side sheets, but must be dismissed in order to interact with the underlying content.
Modal side sheets on smaller screens can transition to standard side sheets at larger screen sizes
isDetachedbooleanDefaultfalsePlace side sheets along the edge of the screen, usually on the right side to avoid interference with any navigational components on the left edge. They can be slightly inset by 16dp.
Don’t inset a side sheet from the screen edges far beyond the recommended margin. This makes the sheet’s position and scroll behavior unclear, while obscuring primary content.
- Margins (when detached): 16dp
Props of SideSheet (15)
role'dialog' | 'alertdialog'Default'dialog'The accessibility role for the dialog.
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
styleCSSProperties | (values: SheetRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
classNameClassNameOrFunction<SheetRenderProps>Default'react-aria-Sheet'The CSS className for the element. A function may be provided to compute the class based on component state.
refRef<HTMLDivElement>isOpenbooleanWhether the overlay is open by default (controlled).
defaultOpenbooleanWhether the overlay is open by default (uncontrolled).
onOpenChange(isOpen: boolean) => voidHandler that is called when the overlay's open state changes.
preventDismissalbooleanDefaultfalseWhether to prevent the user from closing the sheet by swiping, pressing Escape, or interacting outside it.
shouldCloseOnInteractOutside(element: Element) => booleanWhen user interacts with the argument element outside of the overlay ref, return true if onClose should be called. This gives you a chance to filter out interaction with elements that should not dismiss the overlay. By default, onClose will always be called on interaction outside the overlay ref.
SideSheet also takes the 70 attributes and events of the element it renders.
SideSheetHeader
SideSheetHeader accepts every prop of a <div>, including className and ref.
SideSheetHeader also takes the 278 attributes and events of the element it renders.
SheetTrigger
Props of SheetTrigger (4)
childrenrequiredReactNodeisOpenbooleanWhether the overlay is open by default (controlled).
defaultOpenbooleanWhether the overlay is open by default (uncontrolled).
onOpenChange(isOpen: boolean) => voidHandler that is called when the overlay's open state changes.