BottomSheet

BottomSheet presents a focused task from the bottom edge of the viewport. Choose it for a mobile-first secondary task; choose Drawer for a side panel that fits a desktop workflow.

Examples

Project details

Provide a visible title for both the header and the sheet's accessible name. Pass closeLabel whenever the default English close-button name is not appropriate for the product.

An action sheet without a visible heading

When the sheet has no visible title, aria-label is required to name the modal dialog. The localized closeLabel still names the close button.

When to use

Use BottomSheet for a short, mobile-first task or details that should rise from the bottom of the current view.

Reach for something else when:

  • The task belongs in a side panel, especially on desktop — use Drawer.
  • A blocking decision needs a centred, explicit modal — use Dialog.
  • The content is anchored to a small control and should not block the page — use Popover.

Accessibility

  • BottomSheet is a portaled role="dialog" with aria-modal="true". A visible title labels it with aria-labelledby; without a title, a translated aria-label is required.
  • On open, focus moves to a safe initial destination in the sheet and stays trapped there. Background scroll is locked. Declare initialFocusTo when the application owns the task meaning, and returnFocusTo for a pointer-opened workflow that needs an explicit return destination.
  • Escape, the close button and a genuine backdrop click call onClose. The backdrop records where mousedown began, so dragging from the sheet onto the backdrop cannot dismiss it.
  • The sheet is portaled to document.body unless container supplies another portal host. It remains mounted for its animated exit; reduced-motion preferences disable the animation.
  • The close button defaults to the English accessible name "Close". Pass closeLabel to translate it.

React initial focus

initialFocusTo is optional and has the type () => HTMLElement | null. For each accepted opening of a visible modal panel, Lyra synchronously calls the read-only resolver once. Return a current, eligible member of that panel; applications choose a least-destructive Cancel action for a confirmation, a named tabIndex={-1} reading heading for content, or the intended field for a form.

An eligible target is an HTMLElement in the panel's document and current modal panel, connected, visible with rendered rectangles, enabled (including its fieldset), programmatically focusable, and outside hidden, inert, or aria-hidden ancestry. A null or invalid result focuses the named panel directly; it never falls through to another control. Omitting the option uses the first eligible task control, then the panel. The resolver is not replayed on rerenders; a later accepted opening reads the current resolver.

Form composition owns focus after failed validation; initial entry does not infer failure from aria-invalid. The resolver only reads committed state and refs: do not focus, mutate, or start asynchronous work. If it throws, Lyra focuses the panel and propagates the same error through React's effect handling.

React return focus

returnFocusTo is optional and has the type () => HTMLElement | null. It resolves freshly after an accepted close, so it can read current workflow state and refs instead of preserving a stale element. Use it for a stable, eligible trigger; when that trigger can be removed, disabled, hidden, or no longer meaningful, return a logical successor instead.

An eligible destination is connected in the same document, visible, enabled, programmatically focusable, and outside the closing sheet and overlay. A composition must not return a target that it removes while closing. Omitting returnFocusTo retains only a valid captured opener that was already focused, such as after keyboard opening. Unprepared WebKit mouse usage without a usable explicit target remains unqualified: adding this optional prop does not repair unmigrated consumers.

tsx
import { BottomSheet, Button } from '@lyra-ds/react';
import { useRef, useState } from 'react';

function ProjectDetails({ canReturnToTrigger }: { canReturnToTrigger: boolean }) {
  const [open, setOpen] = useState(false);
  const triggerRef = useRef<HTMLButtonElement>(null);
  const successorRef = useRef<HTMLHeadingElement>(null);

  return (
    <>
      <Button ref={triggerRef} disabled={!canReturnToTrigger} onClick={() => setOpen(true)}>
        Open project details
      </Button>
      <h2 ref={successorRef} tabIndex={-1}>
        Project overview
      </h2>
      <BottomSheet
        open={open}
        onClose={() => setOpen(false)}
        returnFocusTo={() =>
          canReturnToTrigger ? (triggerRef.current ?? successorRef.current) : successorRef.current
        }
        title="Project details"
      >
        Review the latest milestone before you continue.
      </BottomSheet>
    </>
  );
}

Project overview is a named, meaningful tabIndex={-1} destination. The canReturnToTrigger state represents current availability; a non-null ref alone does not make a target eligible. A removed trigger also falls through its null ref to the successor.

After an accepted close, Lyra prefers an eligible resolver result, then only a still-eligible captured opener. It ignores an ineligible resolver result and never picks an arbitrary page control or body as a fallback. If neither is eligible, Lyra makes no invalid focus call and the controlled close still proceeds; the browser may land on body. This is an invalid composition, and the application must provide a logical successor. One development diagnostic reports the invalid composition for that close cycle; it is not successful focus restoration. The resolver must only read current state and refs: do not focus, mutate the DOM, or start asynchronous work in it.

An ignored onClose request leaves the sheet open: Lyra does not resolve returnFocusTo or move focus. Once the sheet is closed, rerenders while open remains false do not restore focus again.

API and code

NameTypeRequiredDescription
openbooleanRequiredControls visibility. `true` mounts the portaled overlay and bottom sheet.
onClose() => void—Called when the user dismisses the sheet with Escape, the backdrop, or the close button.
closeLabelstring—Accessible name for the close button. Default: `"Close"`.
containerHTMLElement—Portal host. Defaults to `document.body`.
returnFocusTo() => HTMLElement | null—Resolves the logical destination for an accepted close. The resolver result is used only when eligible; otherwise an eligible previously focused opener is the fallback. A successor composition must supply a meaningful target when the opener can disappear or become ineligible.
initialFocusTo() => HTMLElement | null—Resolves the initial focus destination inside the modal on each accepted opening.
childrenReactNodeRequiredBottom sheet body content.
titleExclude<ReactNode, boolean | null | undefined> | undefined—Heading rendered in the sheet header and used as its accessible name. Omit the heading when the sheet has no visible title.
'aria-label'never | string—The visible heading supplies the accessible name in this branch. Translated accessible name required when no heading is rendered.

x-data="lyraBottomSheet({ … })"

OptionTypeRequiredDescription
defaultOpenboolean—Whether the sheet starts open. Defaults to `false`.
returnFocusTo() => HTMLElement | null—Resolves the current logical focus destination after an accepted modal close.

After the existing Alpine plugin installation (Alpine.plugin(lyra)), use the registered lyraBottomSheet binding; do not import its internal factory. The plugin owns opening and closing, focus trapping, scroll locking, Escape, and the guarded backdrop click. It does not portal this consumer-served composition automatically.

returnFocusTo is initial binding configuration, not mutable callback data. On an accepted close it synchronously reads current state or refs once: Lyra prefers its eligible explicit target with focus({ preventScroll: true }), then an eligible captured opener with ordinary focus() and scroll behavior. The target must be connected, visible, enabled, focusable, in the same document, outside the closing overlay and panel, and outside hidden, inert, or aria-hidden content. There is no arbitrary body fallback. Return a meaningful successor when the trigger is removed or becomes unsafe; do not focus, mutate, or start asynchronous work from the resolver. This example treats an absent, disabled, or hidden trigger as unavailable and returns the named successor. Other application availability changes, including hidden or inert ancestry and a no-longer-meaningful trigger, must choose their meaningful successor from current state; this example covers its named simple states, not arbitrary automatic discovery. Initial closed state, opening, ignored close requests, exit, and destroy do not resolve it.

html
<div
  x-data="lyraBottomSheet({
    returnFocusTo: () => {
      const trigger = document.getElementById('open-project-sheet');
      return trigger instanceof HTMLButtonElement && !trigger.disabled && !trigger.hidden
        ? trigger
        : document.getElementById('project-overview');
    },
  })"
>
  <button
    id="open-project-sheet"
    class="lyra-btn lyra-btn--primary lyra-btn--md"
    type="button"
    @click="open = true"
  >
    Open project details
  </button>
  <h2 id="project-overview" tabindex="-1">Project overview</h2>

  <div class="lyra-bottomsheet-overlay" x-bind="overlay" style="display: none">
    <div
      class="lyra-bottomsheet"
      role="dialog"
      aria-modal="true"
      aria-labelledby="sheet-title"
      tabindex="-1"
      x-bind="panel"
    >
      <div class="lyra-bottomsheet__header">
        <h2 id="sheet-title" class="lyra-bottomsheet__title">Project details</h2>
        <button class="lyra-bottomsheet__close" aria-label="Close" x-bind="close">×</button>
      </div>
      <div class="lyra-bottomsheet__body">
        Review the latest milestone, owners and activity before you continue.
      </div>
    </div>
  </div>
</div>

<lyra:bottom-sheet> Generated from lyra-ds/blade v0.10.0.

The behavior comes from lyraBottomSheet() — install @lyra-ds/alpine and see the HTML + Alpine tab.

PropDefaultRequiredExample values
titlenull——
ariaLabelnull——
closabletrue——
closeLabel'Close'——
defaultOpenfalse——
blade
<lyra:bottom-sheet title="Share project" close-label="Close">
    Anyone with the link can view this project.
</lyra:bottom-sheet>