Components

Drawer

A panel docked to the bottom of the screen that peeks or opens beside the page, which stays live.

Previews are drawn in the theme you made.

Edit it
scheme
direction

Basic #

The page under the drawer stays live.

import { Bundles, Button, Drawer, DrawerSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { frame } from '../../gallery/previewShared.js'

const Primary = Recipes.Button.style({})

// A panel docked to the bottom of the screen: the handle peeks, and a press,
// Enter or a drag opens it. The page under it stays live. `keepFocus` keeps
// focus on the handle when it goes down with focus inside.
export default example({
  title: 'Basic',
  slots: DrawerSlots,
  recipe: Recipes.Drawer,
  state: Bundles.Drawer.with({ id: 'order' }),
  view: ({ style, model, onMessage, h }) =>
    frame(h, { height: '22rem', overflow: 'hidden' }, [
      h.p([h.Style({ margin: '0', padding: '1rem' })], ['The page under the drawer stays live.']),
      Drawer.view(
        {
          model,
          onMessage,
          label: 'Order details',
          style,
          mixins: Drawer.keepFocus,
          draw: ({ panel, handle, body }) =>
            h.aside(
              [...panel, h.AriaLabel('Order')],
              [
                h.button(handle, []),
                h.div(body, [
                  h.div(
                    [
                      h.Style({
                        display: 'grid',
                        gap: '0.75rem',
                        justifyItems: 'start',
                        padding: '0 1rem',
                      }),
                    ],
                    [
                      h.p([h.Style({ margin: '0' })], ['Two items, shipped tomorrow.']),
                      Button.view({ label: 'Track the order', style: Primary }, h),
                    ],
                  ),
                ]),
              ],
            ),
        },
        h,
      ),
    ]),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Usage

Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.

The recipe ↗This code ↗

Keyboard and accessibility

  • The handle is a real button of type="button": Tab reaches it, and Enter and Space press it. label names it once, so the name does not change as the drawer opens.
  • aria-expanded on the handle says whether the panel is open, and aria-controls names the body.
  • Nothing is trapped, dimmed or locked: the page under the drawer stays live, and Tab goes on through it.
  • A peeking drawer hides its body (visibility: hidden) once the slide ends, so its controls leave the tab order and the accessibility tree.
  • Drawer.keepFocus, passed beside the style, moves focus to the handle when the drawer goes down with focus in its body.

Sheet and Drawer in the README ↗