The Drawer component is a panel that slides out from the edge of the screen. It can be useful when you need users to complete a task or view some details without leaving the current page.
import {
CDrawer,
CDrawerBody,
CDrawerFooter,
CDrawerHeader,
CDrawerOverlay,
CDrawerContent,
CDrawerCloseButton,
} from '@chakra-ui/vue';
The Drawer can appear from any edge of the screen. Pass the placement prop and
set it to top, right, bottom, or left.
<template>
<div>
<c-radio-group
is-inline
:spacing="5"
mb="6"
:default-value="placement"
@change="setPlacement"
>
<c-radio value="top">Top</c-radio>
<c-radio value="right">Right</c-radio>
<c-radio value="bottom">Bottom</c-radio>
<c-radio value="left">Left</c-radio>
</c-radio-group>
<c-button @click="isOpen =true">Open</c-button>
<c-drawer :placement="placement" :on-close="close" :isOpen="isOpen">
<c-drawer-overlay />
<c-drawer-content>
<c-drawer-header borderBottomWidth="1px">Basic Drawer</c-drawer-header>
<c-drawer-body>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</c-drawer-body>
</c-drawer-content>
</c-drawer>
</div>
</template>
<script>
export default {
data () {
return {
isOpen: false,
placement: 'right'
}
},
methods: {
setPlacement(value) {
this.placement = value
},
close () {
this.isOpen = false
}
}
}
</script>
When a form is in the drawer, you might need to set focus on a specific element
when the drawer opens. Pass the initialFocusRef prop.
Without the
initialFocusRefprop, the drawer will set focus on the first focusable element when it opens.
CDrawer.initialFocusRef prop is passed, the drawer sets focus on the element with
the assigned ref.CDrawer closes, it'll return focus to the element that triggered it.CDrawer Props#
CDrawercomposes theCModalcomponent with these extra props. So all Modal props apply here. See Modal component for list of props
| Name | Type | Default | Description |
|---|---|---|---|
isFullHeight | boolean | false | If true and placement is set to top or bottom, the drawer fills the height of the viewport. |
placement | left, right, top, bottom | right | The ref to the initial element to receive focus when the drawer opens. |
CDrawerOverlay, CDrawerFooter, CDrawerHeader and CDrawerBody composes CBox componentCDrawerCloseButton composes CCloseButtonCaught a mistake or want to contribute to the documentation? Edit this page on GitHub!