Skip to content

CdsDrawer

The side panel of the application: navigation sections on the left, the context of a record or filters on the right. Inside CdsLayout the drawer takes its place in the layout and pushes the content aside, and in temporary mode it slides out over it.

Storybook GitLab Figma
Test coverage: 93% — good coverage
API in specs
33 / 33 props, events, slots and exposed members with a test
Test cases
76 unit · 3 browser
Known bugs
3 pinned by an it.fails test
Code coverage
93.1% lines · 82.1% branches measured in v4.0.0-alpha.13
A11y (axe)
14 recommendations in 14 stories measured in v4.0.0-alpha.11

For a list of sections inside the drawer take CdsList; for navigating the subsections of a single page take CdsTabs. The drawer is a part of the CdsLayout frame, but unlike the other parts it also works on its own: with the fixed prop it sticks to the window without a layout.

Anatomy ​

The drawer consists of a scrollable navigation list and two pinned areas: prepend on top — for a logo or a profile, append at the bottom — for the sign-out and utility links. The border prop draws borders between the areas.

Variations ​

Permanent drawer ​

The permanent prop keeps the drawer on the screen at all times. Without it the drawer hides on screens narrower than 1056 px — the content gets the whole width, and the navigation is opened by a button.

Collapsible drawer ​

A regular drawer follows v-model at any screen width. On a wide screen it sits in the layout, and when closed it gives its place back to the content. On a narrow screen the same drawer slides out over the content. When the screen crosses 1056 px, the drawer closes and opens back on its own; disable-resize-watcher turns this sync off. The width prop sets the width in pixels, and the layout shifts the content by exactly that much.

Temporary drawer ​

The temporary prop turns the drawer into a sliding one: it takes no place in the layout, opens through v-model and closes on a click on the overlay or on Esc. The @opened and @closed events report the change of state.

On touch screens a sliding drawer can be pulled out with a swipe from the screen edge and put away with a swipe back. The touchless prop turns the gestures off.

Without the scrim ​

The scrim prop controls the backdrop under a sliding drawer. false removes it: the content under the drawer stays clickable, but a click outside no longer closes the drawer, so provide your own button for that. A string instead of true sets the backdrop color; pass it with transparency, for example rgb(0 0 0 / 0.3), or the content under the drawer is hidden completely.

Protection from an accidental close ​

The persistent prop keeps a click on the scrim and the Esc key from closing the drawer: only v-model closes it. It suits a drawer with a form, where a stray click outside would wipe the input.

Minified drawer ​

The minified prop shrinks the drawer down to icons and gives the width back to the content. On hover the drawer expands over the page without pushing it, so the section labels stay reachable.

Position ​

The right prop moves the drawer to the right edge. The application navigation usually lives on the left, and the context of the current record — history, comments, filters — on the right. Both drawers can work in the same layout at once.

Color ​

The bg-color prop paints the background of the drawer with a palette alias, color paints the text and the icons inside. A dark drawer next to light content emphasizes the border of the working area.

Background image ​

The image prop puts an image from a URL under the drawer content, and the image slot takes custom background markup. Color the text on top with the color prop so it stays readable.

Slots ​

SlotDescription
prependPinned area on top: logo, profile
defaultNavigation items
appendPinned area at the bottom: sign-out, utility links
imageBackground under the drawer content

The fixed-slots prop keeps prepend and append in place and gives the scroll to the list of sections only — long navigation no longer pushes the sign-out button past the edge.

Guidelines ​

Scenarios ​

Application navigation ​

A logo in prepend, the sections in a CdsList with active on the current one, a sign-out button in append. The lhh lpr fff layout scheme gives the top left corner to the drawer, so it starts from the very top and reads as the backbone of the application.

Notification panel ​

A right drawer with temporary opens from an icon in the header, shows the list and closes on a click on the overlay. It takes no place in the layout, so the main content is not rebuilt when it opens.

API ​

Props

NameTypeDefaultDescription
bgColorstring | undefined—Background color of the component
borderboolean | undefinedfalseAdds borders between the sections (prepend/append).
captureFocusboolean | undefinedtrueReturns the focus back into the content if it has left it — for example on Tab from the end of the page. A mouse click does not steal the focus.
colorstring | undefined—Component color
disableResizeWatcherboolean | undefinedfalseDoes not sync v-model with the screen width. By default a regular drawer closes when the screen narrows and it becomes a sliding one, and opens back on a wide screen.
fixedboolean | undefinedfalseApplies position: fixed.
fixedSlotsboolean | undefinedfalseUses an inner scroll for the content section.
heightstring | number | undefined—Component height
imagestring | undefined—Background image of the drawer (URL). The image slot is available for custom background markup.
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minifiedboolean | undefinedfalseMinified look (icons only) until the mouse hovers over it.
minWidthstring | number | undefined—Minimum component width
modelValueboolean | null | undefinednullShows/hides the drawer (v-model). Without it a regular drawer is open on a wide screen, and a sliding one is closed.
permanentboolean | undefinedfalseAlways visible, regardless of the screen size.
persistentboolean | undefinedfalseA click on the scrim and the Esc key do not close the drawer, only v-model does. For drawers with a form where an accidental close loses the input.
retainFocusboolean | undefinedtrueTraps Tab navigation inside the content: from the last focusable element the focus moves to the first one and back.
rightboolean | undefinedfalsePositions the drawer on the right.
scrimstring | boolean | undefinedtrueBackdrop under the drawer while it covers the content. false removes it entirely: the content stays clickable and the drawer closes only with Esc or through v-model; a string sets its color.
tagstring | JSXComponent<any> | undefined'aside'Custom HTML tag or component to render
temporaryboolean | undefinedfalseTemporary drawer: slides out over the content at any screen width, opens through v-model and closes on the overlay. On a narrow screen any non-permanent drawer behaves this way.
themestring | undefined—Component theme
touchlessboolean | undefinedfalseDisables gestures: a sliding drawer neither opens with a swipe from the screen edge nor closes with a swipe.
widthstring | number | undefined240The drawer width, px. It also goes into the layout: the content shifts by exactly this width.

Events

NameTypeDescription
closed[value: boolean]The drawer has closed.
opened[value: boolean]The drawer has opened.
update:modelValue[value: boolean]The v-model value has changed.

Slots

NameTypeDescription
appendanyContent after the navigation.
defaultanyNavigation items (CdsList).
image{ image: string | undefined; }Custom drawer background instead of CdsImage from the image prop; stretches under the content.
prependanyContent before the navigation.

Exposed

NameTypeDescription
drawerRefHTMLElement | undefinedRef to the root DOM element of the drawer.