Drawer for Bricks
A panel that slides in from the side on large screens and turns into a bottom sheet on phones. Drag the handle down to close it, press Back, press Escape or tap the backdrop. It opens from a button or link, on a timer, after scrolling or on exit intent. Anything can go inside, because the drawer is a Bricks nestable element.
Adding one
- Add Drawer to the page (General). It can sit anywhere; it moves itself to the end of the page.
- Give it a Drawer ID such as
filters. - Drop content inside it.
- Make any button or link open it: set its link to
#filters, or add the attributedata-drawer="filters".
Ways to open it
- A link to
#id, or any element withdata-drawer="id". - Any CSS selector, set in Also open from, for example
.open-filters. - The address:
/page/#filtersopens it on arrival, so you can link straight to a drawer. - After a number of seconds, after scrolling a percentage of the page, or when the pointer leaves the top of the window.
- JavaScript:
DRFB.open('id'),DRFB.close('id'),DRFB.close()for all, andDRFB.isOpen('id').
Automatic openings can be once per visit, once every few days, or every page view. Only one opens automatically at a time, and never while another is open. Add the class drfb-reset to a link to clear the remembered openings while testing.
Large screens and phones
- Opens from right, left, top or bottom.
- On small screens a bottom sheet (default), full screen, or the same as large screens. Small means up to 768px unless you change Small screens are up to.
- A sheet has a drag handle. Drag the handle or the header towards the edge it came from; past about a third of its size, or a quick flick, closes it. Short of that it springs back.
- Width, tallest height, widest sheet, speed and slide or fade are all controls.
Push transition
Set Transition to Push the page aside and the whole page moves over by the size of the drawer instead of being covered, like a slide-out menu. It works from any side, follows your finger while you drag it closed, and on a phone a bottom sheet pushes the page up. Full-screen drawers always slide over. Switch on Dim the pushed page to darken the page while it is pushed (it uses the backdrop colour); tapping the page closes the drawer either way. Large screens can push from the left, right, top or bottom, and Bottom sheet opens from lets phones use a top or a bottom sheet, which pushes the page down or up.
Closing
- The cross, or a text button, or none.
- The backdrop, the Escape key, and swiping can each be switched off.
- The Back button closes it. The drawer adds one history entry, so pressing Back on a phone dismisses it instead of leaving the page. The address does not change.
- Add the class
drfb-closeor the attributedata-drawer-closeto any element inside, such as an Apply button, to make it close the drawer.
Accessibility
- The panel is a modal dialog, labelled by its title or by Name for screen readers.
- Focus moves in when it opens (to the panel, or to the first field or button), Tab stays inside, and focus goes back to what opened it when it closes.
- The page behind does not scroll while it is open. Reduced-motion settings turn the animation off.
Style
Background, text colour, corner radius, shadow, padding, backdrop colour and blur, layer, and title typography. Colours and sizes are CSS variables on the drawer: --dr-bg, --dr-ink, --dr-w, --dr-h, --dr-radius, --dr-pad, --dr-back, --dr-z.
Good to know
- In the builder the drawer is shown open and inline so you can edit its content. It only slides on the live page.
- The drawer ID is read by the script, not used as the element’s HTML id.
- Events
drfb:openanddrfb:closefire on the drawer, with the ID inevent.detail.id.