Skip to content

Drawer

Drawer

The drawer component is a modal sidebar built on top of the native <dialog> element. It provides a smooth sliding animation and a seamless user experience across both desktop and mobile devices. The default implementation slides in from the left when opened and snaps closed when dismissed. It includes a semi-transparent blurred background and can be closed using the ESC key or by clicking on the background. The drawer is fully accessible with ARIA attributes and supports both mouse and keyboard navigation.

Complete Drawer with Button Example

Simple Drawer

This Drawer opens with a transition from the left and can be closed with ESC key or by clicking the background

The styling of the base drawer is defined by the following variables. As with all components, they will use these default values, but can be redefined within your main css file.

VariableDefault ValueDescription
--drawer-backdrop-colorrgba(0, 0, 0, 0.3)Color and opacity of the drawer backdrop
--drawer-backdrop-blur4pxBlur effect intensity for the backdrop
--drawer-width-min320pxMinimum width of the drawer container
--drawer-width-max80vwMaximum width of the drawer container
--drawer-margin2remMargin around the drawer on desktop
--drawer-padding2remInternal padding of the drawer content
--drawer-mobile-padding1remInternal padding on mobile devices
--drawer-mobile-margin0remMargin around the drawer on mobile
--drawer-mobile-max-width80vwMaximum width of the drawer container on mobile
--drawer-hero-width18remWidth of hero content area in drawer
--drawer-mobile-hero-height150pxHeight of hero content area on mobile
--drawer-animation-speedvar(--duration-speed-slow)Duration of drawer animations and transitions
--drawer-radiusvar(--radius-site)Border radius of the drawer corners
--drawer-shadowvar(--shadow-site)Shadow effect for the drawer box
--drawer-shadow-mobilevar(--shadow-site)Shadow effect for the drawer box on mobile

Accessibility

The drawer is built following the WAI-ARIA Modal Dialog Pattern, implementing key accessibility features through semantic HTML and ARIA attributes.

Current Implementation Features

Closing animation

The current snap-close implementation can only be further customised with the use of Javascript and the HTMLDialogElement: showModal() method.

Structure and Labeling

Each Drawer includes:

  • The role="dialog" attribute to identify it as a modal dialog
  • aria-modal="true" to indicate it’s a modal context
  • aria-label to provide an accessible name for the drawer
  • aria-controls on trigger buttons to associate them with their respective drawers

Keyboard Support

The native HTML <dialog> element provides:

  • ESC key to close the drawer
  • Tab key to navigate through focusable elements
  • Automatic focus management within the drawer

Screen Reader Support

The drawer includes:

  • Clear labeling of all interactive elements
  • Proper content organization
  • Hidden decorative elements using aria-hidden="true"
  • Descriptive button labels for actions and close buttons

Mobile Accessibility

For mobile devices:

  • Clear close mechanisms (either close button or backdrop)
  • Touch-friendly target sizes
  • Maintained content structure

Required Implementation Steps

When implementing drawers in your project, ensure you:

Content Structure

  • Use semantic HTML elements for content structure
  • Include descriptive text for all buttons and interactive elements
  • Maintain proper focus management

Keyboard Navigation & focus

  • Javascript must be used to entirely trap the focus within the drawer. In some browsers such as Chrome, when the user has reached the end of the drawer, tabbing again will move focus to the browsers toolbar. In order to make the drawer as accessible as possible, it should ignore the tool bar and go back to the start of the drawer’s index.

ARIA Attributes

  • Add appropriate aria-label value to the dialog element
  • Include aria-controls on trigger buttons
  • Add descriptive aria-label values for action buttons
  • Use aria-hidden="true" for decorative elements