Skip to content
GitHub

Drawer

The most basic setup for a drawer.

Drawer Content

This drawer uses both the built-in close button (X) and a custom close button:

Close Drawer

Set the align prop to "right" or "left" to change the alignment of the drawer.

Drawer Content

This drawer uses both the built-in close button (X) and a custom close button:

Close Drawer

Integrate forms seamlessly within the drawer. You might want to close the drawer when the form is submitted.

Settings

By default, the drawer is modal, meaning it blocks interaction with the underlying content. To create a non-modal drawer, set the modal prop to false.

Drawer Content

This drawer uses both the built-in close button (X) and a custom close button:

Close Drawer

PropertyTypeDefaultDescription
openbooleanfalseControls the visibility of the drawer
modalbooleantrueWhether drawer blocks interaction with underlying content
show-closebooleantrueShow/hide the close button in the drawer header
alignstring"bottom"Position of the drawer: "left", "right", "top", "bottom"

The drawer component uses CSS custom properties for extensive customization:

PropertyDefaultDescription
--drawer-width448pxWidth of left/right drawers
--drawer-height100vh (sides), 400px (top/bottom)Height of drawers
PropertyDefaultDescription
--drawer-backgroundhsl(var(--background))Background color of the drawer
--drawer-borderhsl(var(--border))Border color around the drawer
--drawer-overlayrgba(0, 0, 0, 0.8)Backdrop overlay color (modal only)
--drawer-animation300ms ease-in-outSlide animation duration and easing
<fulcrum-element-drawer
  align="right"
  style="
    --drawer-width: 500px;
    --drawer-background: #f8f9fa;
    --drawer-border: #dee2e6;
    --drawer-animation: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  "
>
  <!-- Content -->
</fulcrum-element-drawer>
<fulcrum-element-drawer
  align="bottom"
  style="
    --drawer-height: min(70vh, 500px);
    --drawer-background: white;
    --drawer-border: #e5e7eb;
    --drawer-animation: 250ms ease-out;
  "
>
  <!-- Content -->
</fulcrum-element-drawer>
MethodDescription
open()Open the drawer programmatically
close()Close the drawer programmatically

The drawer dispatches custom events that bubble up:

EventDetailDescription
drawer-open{ dialog }Fired when drawer opens
drawer-close{ dialog }Fired when drawer closes
drawer-cancel{ dialog }Fired when drawer is cancelled (ESC key)
// Get drawer element
const drawer = document.querySelector("fulcrum-element-drawer");

// Open/close programmatically
drawer.open();
drawer.close();

// Listen to events
drawer.addEventListener("drawer-open", (event) => {
  console.log("Drawer opened");
});

drawer.addEventListener("drawer-close", (event) => {
  console.log("Drawer closed");
});

// Toggle based on current state
function toggleDrawer() {
  if (drawer._open) {
    drawer.close();
  } else {
    drawer.open();
  }
}

The drawer component includes comprehensive accessibility support:

  • Tab: Navigate through interactive elements within the drawer
  • Escape: Close the drawer (when dismissible)
  • Enter/Space: Activate focused elements
  • Proper ARIA roles and labels
  • Focus management and trapping (modal mode)
  • State changes are announced to assistive technologies
  • Focus is trapped within modal drawers
  • Focus returns to trigger element when closed

The drawer component works seamlessly across different screen sizes:

<!-- Mobile-first approach -->
<fulcrum-element-drawer
  align="bottom"
  class="mobile-drawer"
  style="
    --drawer-height: 50vh;
    --drawer-animation: 200ms ease-out;
  "
>
  <!-- Mobile-optimized content -->
</fulcrum-element-drawer>

<style>
  @media (min-width: 768px) {
    .mobile-drawer {
      --drawer-width: 400px;
      --drawer-height: 100vh;
      /* Note: This would require JavaScript to change the align attribute */
    }
  }
</style>
<fulcrum-element-drawer align="right" id="settings-drawer">
  <form style="padding: 1rem;">
    <h3>Settings</h3>
    <div>
      <label for="username">Username:</label>
      <input type="text" id="username" name="username" />
    </div>
    <div>
      <label for="email">Email:</label>
      <input type="email" id="email" name="email" />
    </div>
    <div style="margin-top: 1rem;">
      <button type="submit">Save</button>
      <button
        type="button"
        onclick="document.getElementById('settings-drawer').close()"
      >
        Cancel
      </button>
    </div>
  </form>
</fulcrum-element-drawer>
  • Use CSS transforms for positioning rather than changing layout properties
  • Implement lazy loading for drawer content when possible
  • Use appropriate animations that respect prefers-reduced-motion
  • Ensure touch targets are at least 44px for mobile devices
  • Consider the drawer’s impact on the main content flow
  • Use semantic HTML within drawer content
  • Provide clear headings and navigation structure
  • Consider the drawer’s role (navigation, complementary content, etc.)
  • Ensure content is accessible without the drawer open