Bottom Sheet
A mobile touch surface for filters, actions, forms, and detail views that should rise from the bottom of the viewport. For a multi-step flow, give each step its own sheet and one state value that names the open step (see Replacing a sheet); open a second sheet over the first when a step should stay visible beneath it. Stacking. Every sheet keeps its own isOpen. Open a sheet while another scrim sheet is open and it stacks on top: the sheet beneath stays mounted with its scroll position and inputs, recedes behind the new one (the nearest covered sheet shrinks to 0.96 and lifts 8px, deeper ones to 0.92 and 16px), and is blocked from pointer, keyboard, and assistive technology by the top sheet's modal dialog. The sheets can be siblings, live in separate components, sit inside another sheet's content, or sit inside a BottomSheetSwitcher step; a whole switcher is one level, and switching its step in place does not change its position. Nothing moves in the DOM: each sheet's dialog stays where it is written, and no wrapper component is needed. Order is open order. The top sheet is the one presented most recently that is still open; a sheet that closes and reopens comes back on top. When several sheets open in one update (a deep link into a flow), there is no open order between them, so tree order decides: a sheet below the sheets rendered in its content, siblings in the order they are written. That order is right in the first painted frame. One scrim. Only the bottom sheet's backdrop dims the page; the backdrops of the sheets above it are transparent, so a stack never darkens per level. The dim holds steady while sheets push and pop, and if the bottom sheet closes while sheets remain above it, the next sheet's backdrop takes over in the same frame. Dismissal. Escape, a tap on the scrim, a downward swipe, and a platform close request (Android back, a close watcher) reach only the top sheet, through that sheet's own onOpenChange, and that sheet's purpose applies: required blocks all of them, form blocks the scrim and the swipe. Nothing closes a whole stack at once; set every sheet closed in one update when a flow is done and they leave together. Closing a covered sheet from code. Sheets rendered inside the closing sheet's content are part of it: they are presented only while it is open and leave with it. Their isOpen stays yours, as with a Dialog rendered in a closed Dialog: nothing is written to it, and a nested sheet that is still open when its host reopens is presented again, on top. Set it closed yourself when the flow is done. Sheets above the closing sheet that are not in its content stay open and keep their order; the closing sheet slides out from beneath them, and if it owned the scrim, the sheet above takes it over. Replacing a sheet. Close the top sheet and open another in the same update (one state value that names the open step does this) and the new sheet replaces it instead of stacking on it: the new sheet rises above the one it replaces; if the replaced sheet is taller it moves down to meet the new sheet's top edge at the same time; the replaced sheet fades only after both motions finish, and is inert and hidden from assistive technology from the start. The scrim holds steady throughout, with no dip; focus moves into the new sheet; and when the flow closes, focus returns to the element that opened its first sheet, whichever sheet closed last. This is the handoff the deprecated BottomSheetSwitcher ran between its steps; a multi-step flow needs no switcher: give each step its own BottomSheet and one state value. A replace happens only when exactly one sheet closes and one opens in the update, the closing sheet was the top sheet of its stack, and the move was made from inside it (the control last pressed, or with no recent press the focused element, was in the closing sheet, as a step's own Continue or Back button is); a covered sheet closing while a sheet opens, a close and an open in different updates, or a close and an open driven from a control outside the closing sheet (two unrelated owners acting at once) keep the ordinary push and pop motion and their own focus return. A replace over an open stack runs one level up and leaves the sheets beneath covered. Non-modal sheets (hasScrim={false}) replace each other the same way, with no scrim: they are hosted in the browser top layer as manual popovers, so the entering step orders above the retained one with no page-level z-index, and toasts raised before or while the sheet is open stay above it. Below the Popover API support floor (Tier 2 in the browser support guide) the sheet falls back to show() in page stacking order: usable, but with no promise over later page content. A non-modal sheet returns focus to its opener on close only while focus is still inside it; focus taken elsewhere on the live page stays there. Focus. Opening a sheet, modal or not, focuses its data-autofocus field (a TextInput with hasAutoFocus) in every browser. Without one, focus goes wherever the engine's native dialog focusing steps land: the panel in Chromium, and in Safari on iOS for a modal sheet; the first focusable control in Firefox. So to open on a field in every browser, mark it data-autofocus (a TextInput with hasAutoFocus). A step entering as a replacement also focuses a data-autofocus descendant first, so a flow that opens on a field keeps the keyboard on it. Closing the top sheet returns focus into the sheet it reveals: to the control that opened it when that control is still there, otherwise to the revealed sheet's panel. When the last sheet closes, the standalone rules apply: finalFocusRef, else the element that opened the sheet, with a focus ring only after keyboard input. When every sheet of a stack closes in one update, focus returns once, to the bottom sheet's finalFocusRef or opener, after the last dialog has closed. Caveats. A Dialog, AlertDialog, or Popover opened from a sheet paints above the sheet and does not make it recede; a sheet opened from inside that Dialog paints above the Dialog and stacks over the sheet beneath. Sheets with hasScrim={false} stay out of the stack entirely (they replace each other, but never stack, recede, or take the scrim). A sheet React hides (a suspended Suspense boundary, Activity mode="hidden") leaves the stack and closes its dialog; when it is shown again it is presented again, on top. Only sheets rendered in the same document stack; a sheet inside an iframe is its own stack.
Panoramica
Quando usarlo
Indicazioni
- Da utilizzare per superfici mobile-first (filtri, fogli di condivisione, azioni rapide) in cui il contenuto deve sollevarsi dal bordo inferiore.
- Per un drill-in, aprire il foglio successivo su quello corrente e mantenere isOpen di ciascun foglio dove risiedono i dati; un foglio dettagli può trovarsi all'interno del foglio elenco che lo apre, proprio accanto alla riga. Chiudi ogni foglio in un aggiornamento per chiudere l'intero flusso.
- Scegli l'altezza iniziale adatta al contenuto: "abbraccio" per contenuti brevi, "limitato" per elenchi e "alto" per moduli o contenuti in streaming/ridimensionamento.
- Usa scopo = 'form' per proteggere i dati inseriti da scrim click e scorrimenti mantenendo Escape disponibile; Reserve Purpose='required' per i flussi che devono terminare tramite un'azione esplicita.
Da evitare
- Non rendere il contenuto del foglio eccessivamente lungo. Suddividerlo in passaggi, ciascuno con il proprio foglio, con un valore di stato che denomina il passaggio aperto; andare avanti ne sostituisce uno con il successivo.
- Non impilare più di due o tre fogli: i fogli più profondi condividono il secondo gradino di arretramento e l'utente deve sollevarli uno alla volta. Sostituisci invece i passaggi (chiudine uno, apri il successivo in un unico aggiornamento) quando non è necessario che rimangano visibili.
Anatomia
- Pannello in lamiera
- Superficie verniciata che risale dal bordo inferiore e contiene la lamiera.
- Area contenuti
- Contenitore imbottito e scorrevole che presenta il contenuto del foglio fornito dal chiamante.
- Maniglia
- Zona decorativa di presa e trascinamento nella parte superiore del pannello.
- Tela
- Sfondo che oscura e blocca la pagina in una presentazione con supporto in tela.
Proprietà
| Proprietà | Tipo | Default | Comportamento |
|---|---|---|---|
isOpen | boolean | — | Indica se un foglio autonomo è aperto. Completamente controllato; accoppiare con onOpenChange. Omesso solo all'interno del deprecato BottomSheetSwitcher, che guida da solo i suoi passi. |
onOpenChange | (isOpen: boolean) => void | — | Per un foglio autonomo, chiamato quando richiede una modifica dello stato aperto. Le chiamate automatiche seguono lo scopo: le informazioni vengono chiuse con Escape, scrim click o swipe; il modulo viene chiuso solo in modalità Escape; richiesto non licenzia mai implicitamente. Omesso solo all'interno del deprecato BottomSheetSwitcher, che guida da solo i suoi passi. |
finalFocusRef | RefObject<HTMLElement | null> | — | Destinazione di restituzione del focus esplicita opzionale per un foglio autonomo. Da utilizzare quando l'apriporta può essere rimontato o l'elemento attivo non è un trigger affidabile, come un interruttore di presentazione adattivo. Sempre concentrato quando il telo si chiude da solo o per ultimo; quando un foglio modale è ancora aperto sotto, il focus ritorna su quel foglio (su questo elemento se è al suo interno, altrimenti sul pannello rivelato). Omesso solo all'interno del deprecato BottomSheetSwitcher, che guida da solo i suoi passi. |
purpose | 'required' | 'form' | 'info' | 'info' | Controlla il comportamento di licenziamento implicito, corrispondente alla finestra di dialogo. le informazioni consentono di uscire, fare clic su scrim e scorrere per ignorare. il modulo protegge i dati immessi bloccando il clic e lo scorrimento dello schermo consentendo l'Escape. obbligatorio blocca ogni percorso di licenziamento implicito e utilizza role='alertdialog'. I controlli espliciti possono comunque aggiornare lo stato controllato. Funziona con fogli autonomi e gestiti da BottomSheetSwitcher. |
sheetId | string | — | Deprecato con BottomSheetSwitcher: assegna invece a ogni passaggio il proprio foglio autonomo con isOpen. Funziona ancora come rilasciato: l'ID univoco di questo foglio all'interno di un BottomSheetSwitcher, che lo apre quando activeSheet corrisponde; omettere isOpen e onOpenChange quando viene utilizzato sheetId. |
label | string | Obbligatoria | Etichetta accessibile per il foglio. Necessario; il foglio non ha un'intestazione incorporata da cui derivare un nome. |
children | ReactNode | Obbligatoria | Contenuto del foglio in un'area scorrevole. Il corpo indicato è raggiungibile tramite tastiera durante l'overflow. La voce della scheda Avanti può spostarsi direttamente al primo collegamento o pulsante nativo; i controlli di input, i widget compositi e le aree di scorrimento nidificate mantengono l'interruzione del corpo. Maiusc+Tab di un primo figlio delegato salta il corpo. L'adattamento del contenuto non aggiunge alcun arresto al corpo. La casella interna del contenuto osservato preserva il flusso dei blocchi e le altezze percentuali. Se include un controllo di immissione testo in grado di visualizzare la tastiera mobile, utilizza Height='tall' e mantieni il foglio completamente espanso durante la modifica. |
padding | 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | — | Riempimento interno del contenuto del foglio utilizzando la scala di spaziatura, corrispondente alla finestra di dialogo. Se omesso, utilizza il tema predefinito per i fogli inferiori (--spacing-4 a meno che il tema non imposti il riempimento sul foglio inferiore). Un bambino della Sezione solitario sfugge all'imbottitura e i bambini sanguinanti come Tavolo e Divisore compensano ciò. Utilizza 0 per contenuti da bordo a bordo che forniscono il proprio riquadro. Qualunque sia il riempimento, l'inserto di inizio blocco non è mai inferiore all'altezza della barra di presa (--spacing-6), quindi il contenuto a riposo inizia sotto la barra. |
height | 'hug' | 'capped' | 'tall' | number | string | 'capped' | Quanto è alto il foglio. Budget denominati: "hug" si adatta ai contenuti fino al 92% dell'area visibile, "capped" è un pannello scorrevole a media altezza (~62%) e "tall" è un pannello quasi pieno bloccato (~92%) per i contenuti in streaming. Oppure passa un numero (px)/lunghezza CSS per un budget personalizzato. Fornisci punti di snap per consentire all'utente di trascinare tra le altezze. Nelle finestre più corte la tavola riempie l'altezza disponibile. Solo un foglio "alto" completamente espanso fornisce l'alloggio della tastiera mobile: rimane fermo e fa scorrere ciascun controllo focalizzato sopra la tastiera. Le altezze Hug, Capped, numeriche e di lunghezza CSS non lo fanno mai, e un foglio alto smette di farlo nel momento in cui l'utente lo trascina su un fermo più breve, riprendendo quando lo trascina indietro. Al di fuori di questo stato il foglio non si sposta né aggiunge spazio di scorrimento sulla tastiera. Un TextInput, TextArea o NumberInput al suo interno viene fatto scorrere sopra la tastiera da uno scroller nel foglio quando quello scroller può portarlo lì; altrimenti la pagina lo porta in vista, cosa che su iOS può spostare l'intera pagina. In Firefox per Android, dove la pagina non può scorrere ulteriormente, il campo può rimanere sotto la tastiera. Questa sistemazione si applica laddove l'area di visualizzazione visiva si restringe per la tastiera, come in Safari su iOS, Firefox per Android e Chrome su Android, dove il foglio posiziona il controllo focalizzato appena sopra la tastiera non appena si solleva e il controllo sposta il resto della diapositiva di Gboard verso l'alto e la diapositiva verso il basso dopo aver perso il focus; un nascondi report di Chrome in ritardo, come Indietro, scompare dal report di Chrome (`design system docs browser-support`). |
snapPoints | ReadonlyArray<number | string> | — | Altezze extra a cui può appoggiarsi il foglio quando viene trascinato; la sua altezza è sempre la fermata più alta, e omettendola si ottiene un foglio che si apre e si chiude solo. Ogni fermata è l'altezza visibile del foglio: un numero è una frazione del viewport (0,5 è metà dello schermo), "50%" lo stesso in CSS, "320px" una lunghezza assoluta. Uno stop di un quarto del foglio o meno è una sbirciatina: scivola via invece di rifluire, e assottiglia la tela. |
hasScrim | boolean | true | Per un BottomSheet autonomo, sia per eseguire il rendering di una tela, la sovrapposizione semitrasparente che copre e blocca lo sfondo. true (impostazione predefinita) utilizza showModal(): livello superiore, contenimento del focus nativo, ::tela dello sfondo, blocco dello scorrimento del corpo e tap-scrim-to-dismiss quando scopo='info', con lo sfondo inerte. Anche un foglio di tela prende parte all'impilamento (vedere Impilamento di seguito). false presenta il foglio nel livello superiore come un popover manuale (sotto il piano di supporto dell'API Popover, show() nell'ordine di sovrapposizione delle pagine come fallback ridotto) senza scrim, senza focus trap e senza blocco dello scorrimento, lasciando la pagina interattiva e scorrevole; un foglio senza tela non si impila né è impilato, ma i passaggi senza tela si sostituiscono a vicenda con lo stesso trasferimento. Un foglio senza tela mostrato mentre un modale (un foglio di tela o una finestra di dialogo) che non lo contiene è aperto è inerte sotto quel modale e rimane sotto di esso (show(), nessun z-index a livello di pagina) finché quel modale non è andato, quindi entra nel livello superiore; un'uscita modale a metà viene considerata scomparsa e, renderizzato all'interno del modale, il foglio entra immediatamente nel livello superiore. In un flusso a più fasi, imposta hasScrim allo stesso modo in ogni passaggio. |
Esempi e codice
Apri un esempio per provarlo e leggere il codice.
Lenzuolo inferiore - Varianti di altezza
Confronta le altezze iniziali abbraccio, limitato e alto per diverse quantità di contenuto.
Vedi codice
Codice dell’esempio
Caricamento del codice…Foglio inferiore: tastiera mobile
Utilizza un modulo alto e scorrevole che mantiene i controlli mirati visibili sopra la tastiera del dispositivo mobile.
Vedi codice
Codice dell’esempio
Caricamento del codice…Lenzuolo inferiore — Senza tela
Mantiene la pagina visibile e interattiva dietro un foglio inferiore non modale.
Vedi codice
Codice dell’esempio
Caricamento del codice…Lenzuolo inferiore
Superficie filtrante mobile che risale dal bordo inferiore.
Vedi codice
Codice dell’esempio
Caricamento del codice…Foglio inferiore: punti di ancoraggio
Arresti di trascinamento per ridimensionare: una superficie di lavoro a mezza altezza e una sbirciatina che scivola via e assottiglia la tela.
Vedi codice
Codice dell’esempio
Caricamento del codice…Base
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Filters">
<FilterControls />
</BottomSheet>Foglio alto (un elenco)
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Nearby places"
height="tall">
<PlaceList />
</BottomSheet>Ripiegabile fino a metà dello schermo
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Nearby places"
height="tall"
snapPoints={[0.5]}>
<PlaceList />
</BottomSheet>Una sbirciatina, un'altezza di lavoro e piena
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Route"
height="tall"
snapPoints={['96px', '50%']}>
<RouteDetails />
</BottomSheet>Altezza abbraccio (adatto al contenuto)
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Share"
height="hug">
<ShareActions />
</BottomSheet>Contenuto a scorrimento lungo
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Release notes"
height="hug">
<ReleaseNotes />
</BottomSheet>Flusso multifase (un foglio alla volta, ogni passo sostituisce l'ultimo)
// One value names the open step. Moving on closes one sheet and opens the
// next in the same update: the next step rises above the current one, which
// fades once it has arrived. A dismissed step closes the flow.
const [step, setStep] = useState(null);
const stepProps = own => ({
isOpen: step === own,
onOpenChange: isOpen => !isOpen && setStep(current => (current === own ? null : current)),
});
<>
<Button label="Start" onClick={() => setStep('details')} />
<BottomSheet {...stepProps('details')} label="Details">
<Button label="Continue" onClick={() => setStep('confirm')} />
</BottomSheet>
<BottomSheet {...stepProps('confirm')} label="Confirm">
<Button label="Back" onClick={() => setStep('details')} />
<Button label="Done" onClick={() => setStep(null)} />
</BottomSheet>
</>Fogli impilati (drill-in: elenco, ordine, modifica)
const [isListOpen, setIsListOpen] = useState(false);
const [orderId, setOrderId] = useState(null);
const [isEditing, setIsEditing] = useState(false);
const closeAll = () => {
setIsListOpen(false);
setOrderId(null);
setIsEditing(false);
};
<>
<Button label="Orders" onClick={() => setIsListOpen(true)} />
<BottomSheet isOpen={isListOpen} onOpenChange={setIsListOpen} label="Orders">
{orders.map(order => (
<Button key={order.id} label={order.title} onClick={() => setOrderId(order.id)} />
))}
</BottomSheet>
{/* Opens over the list; the list recedes and stays mounted. */}
<BottomSheet
isOpen={orderId != null}
onOpenChange={open => !open && setOrderId(null)}
label="Order">
<Button label="Edit" onClick={() => setIsEditing(true)} />
<Button label="Close all" onClick={closeAll} />
</BottomSheet>
<BottomSheet isOpen={isEditing} onOpenChange={setIsEditing} label="Edit order">
<Button label="Save" onClick={() => setIsEditing(false)} />
</BottomSheet>
</>Scheda dettaglio all'interno del foglio elenco che lo apre
function PlaceRow({place}) {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button label={place.name} onClick={() => setIsOpen(true)} />
{/* Rendered in the list sheet's content: stacks above it, leaves with it, and comes back with it while still open. */}
<BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label={place.name}>
<PlaceDetail place={place} />
</BottomSheet>
</>
);
}
<BottomSheet isOpen={isListOpen} onOpenChange={setIsListOpen} label="Places">
{places.map(place => <PlaceRow key={place.id} place={place} />)}
</BottomSheet>Collegamento diretto in uno stack (più fogli aperti in un unico aggiornamento)
// From a URL: list, order and editor open together. With no open order
// between them, tree order decides: the list is at the bottom, the editor on top.
const [isListOpen, setIsListOpen] = useState(() => route.list);
const [orderId, setOrderId] = useState(() => route.orderId);
const [isEditing, setIsEditing] = useState(() => route.edit);
<>
<BottomSheet isOpen={isListOpen} onOpenChange={setIsListOpen} label="Orders">…</BottomSheet>
<BottomSheet isOpen={orderId != null} onOpenChange={open => !open && setOrderId(null)} label="Order">…</BottomSheet>
<BottomSheet isOpen={isEditing} onOpenChange={setIsEditing} label="Edit order">…</BottomSheet>
</>Tastiera portatile
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Add a comment"
height="tall">
<LongCommentForm />
</BottomSheet>Senza tela
const [isOpen, setIsOpen] = useState(true);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
label="Nearby places"
hasScrim={false}>
<PlaceList />
</BottomSheet>Proteggi l'input del modulo
const [isOpen, setIsOpen] = useState(false);
<BottomSheet
isOpen={isOpen}
onOpenChange={setIsOpen}
purpose="form"
label="Edit profile">
<ProfileForm onSave={() => setIsOpen(false)} />
</BottomSheet>Accessibilità
Verifiche da eseguire nella tua interfaccia.
- Verifica focus, contrasto e comportamento con il lettore di schermo nel contesto di utilizzo.