React Spring Bottom Sheet

3.4.1 · active · verified Sun Apr 19

react-spring-bottom-sheet is a React component library designed for creating accessible, animated bottom sheets (also known as bottom drawers or modals) for web applications. It is built upon the `react-spring` library for physics-based animations and `react-use-gesture` for robust gesture control, delivering a smooth and interactive user experience. The current stable version is 3.4.1, which includes support for React 18. Key features include content drag expansion, customizable snap points, and an opt-out focus trap for accessibility. The library differentiates itself by its focus on combining delightful animations with strong accessibility standards through its underlying animation libraries and CSS custom properties for styling. While not adhering to a strict time-based release schedule, the project is actively maintained with updates addressing bug fixes, dependency compatibility, and new features as needed.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a controlled bottom sheet with open/close functionality, programmatic snap-to, multiple snap points, and custom header/footer. It includes the necessary CSS import.

import { useState, useRef } from 'react';
import { BottomSheet, BottomSheetRef } from 'react-spring-bottom-sheet';
import 'react-spring-bottom-sheet/dist/style.css';

function MyBottomSheetComponent() {
  const [open, setOpen] = useState(false);
  const sheetRef = useRef<BottomSheetRef>(null);

  const handleDismiss = () => {
    console.log('Sheet dismissed');
    setOpen(false);
  };

  const handleSnapToMax = () => {
    if (sheetRef.current) {
      sheetRef.current.snapTo(({ maxHeight }) => maxHeight);
    }
  };

  return (
    <>
      <button onClick={() => setOpen(true)}>Open Bottom Sheet</button>
      <BottomSheet
        open={open}
        onDismiss={handleDismiss}
        ref={sheetRef}
        snapPoints={({ minHeight, maxHeight }) => [
          minHeight,
          maxHeight * 0.5,
          maxHeight,
        ]}
        header={<div>Sheet Header</div>}
        footer={<div>Sheet Footer</div>}
      >
        <div style={{ padding: '16px' }}>
          <h2>Welcome to the Bottom Sheet!</h2>
          <p>This is some content inside the sheet. You can drag it up or down to different snap points.</p>
          <p>The sheet will automatically adjust its height based on the content or snap to predefined points.</p>
          <button onClick={handleSnapToMax}>Expand to full height</button>
        </div>
      </BottomSheet>
    </>
  );
}

export default MyBottomSheetComponent;

view raw JSON →