Drawer
Examples
Interaction
Read this handy introduction to HTML attributes and DOM properties
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eu dignissim nisi, gravida pharetra elit. Etiam eu urna orci. Nulla et lorem eleifend, ultrices massa id, molestie urna. Nulla nec quam in turpis fermentum dictum vitae ac nibh. Suspendisse lacus nisi, sollicitudin in commodo quis, euismod id enim. Donec semper nunc et tellus convallis, tristique varius turpis gravida. Quisque hendrerit magna ac bibendum molestie. Nullam scelerisque libero vitae lorem dignissim ullamcorper. Integer mollis auctor enim vel molestie. Etiam id vestibulum augue, vitae dapibus quam. Nunc tincidunt aliquet lacus nec malesuada. Donec ultricies augue non lorem eleifend, eget ullamcorper lacus elementum. Donec condimentum enim nec justo auctor, nec bibendum ipsum dapibus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eu dignissim nisi, gravida pharetra elit. Etiam eu urna orci. Nulla et lorem eleifend, ultrices massa id, molestie urna. Nulla nec quam in turpis fermentum dictum vitae ac nibh. Suspendisse lacus nisi, sollicitudin in commodo quis, euismod id enim. Donec semper nunc et tellus convallis, tristique varius turpis gravida. Quisque hendrerit magna ac bibendum molestie. Nullam scelerisque libero vitae lorem dignissim ullamcorper. Integer mollis auctor enim vel molestie. Etiam id vestibulum augue, vitae dapibus quam. Nunc tincidunt aliquet lacus nec malesuada. Donec ultricies augue non lorem eleifend, eget ullamcorper lacus elementum. Donec condimentum enim nec justo auctor, nec bibendum ipsum dapibus.
active
attribute or property to make the drawer show or hide. chi-drawer
also supports three public methods to change its visibility: show()
, hide()
,
toggle()
.<!-- Trigger -->
<chi-button id="drawer-trigger" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer" position="left" backdrop no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer');
var drawerTrigger = document.getElementById('drawer-trigger');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
active
property to make the drawer show or hide. ChiDrawer
also supports three public methods to change its visibility: show()
, hide()
,
toggle()
.<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="left"
:active="this.drawerActive"
:noHeader="true"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
Use the function
chi.drawer(elem)
to instantiate a new drawer component in the DOM
element passed as a parameter. You must use the trigger element as the parameter.<!-- Trigger -->
<button id="drawer-trigger-1" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-1" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div class="chi-backdrop -closed">
<div class="chi-backdrop__wrapper">
<div id="drawer-1" class="chi-drawer -left">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-1'));</script>
Position
<!-- Trigger -->
<chi-button id="drawer-trigger-2" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-2" position="left" no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-2');
var drawerTrigger = document.getElementById('drawer-trigger-2');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="left"
:active="this.drawerActive"
:noHeader="true"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-3" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-3" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div id="drawer-3" class="chi-drawer -left">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-3'));</script>
<!-- Trigger -->
<chi-button id="drawer-trigger-4" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-4" position="right" no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-4');
var drawerTrigger = document.getElementById('drawer-trigger-4');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="right"
:active="this.drawerActive"
:noHeader="true"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-5" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-5" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div id="drawer-5" class="chi-drawer -right">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-5'));</script>
<!-- Trigger -->
<chi-button id="drawer-trigger-6" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-6" position="top" no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-6');
var drawerTrigger = document.getElementById('drawer-trigger-6');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="top"
:active="this.drawerActive"
:noHeader="true"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-7" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-7" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div id="drawer-7" class="chi-drawer -top">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-7'));</script>
<!-- Trigger -->
<chi-button id="drawer-trigger-8" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-8" position="bottom" no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-8');
var drawerTrigger = document.getElementById('drawer-trigger-8');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="bottom"
:active="this.drawerActive"
:noHeader="true"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-9" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-9" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div id="drawer-9" class="chi-drawer -bottom">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-9'));</script>
Backdrop
An optional backdrop can be added to focus the user's attention on drawer content.
<!-- Trigger -->
<chi-button id="drawer-trigger-10" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-10" position="bottom" backdrop no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-10');
var drawerTrigger = document.getElementById('drawer-trigger-10');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="bottom"
:active="this.drawerActive"
:noHeader="true"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-11" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-11" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div class="chi-backdrop -closed">
<div class="chi-backdrop__wrapper">
<div id="drawer-11" class="chi-drawer -bottom">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-11'));</script>
Titled
<!-- Trigger -->
<chi-button id="drawer-trigger-12" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-12" position="left" title="Drawer title here" backdrop>
<div class="-p--2 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-12');
var drawerTrigger = document.getElementById('drawer-trigger-12');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="left"
:active="this.drawerActive"
title="Drawer title here"
backdrop
>
<div class="-p--2 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-13" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-13" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div class="chi-backdrop -closed">
<div class="chi-backdrop__wrapper">
<div id="drawer-13" class="chi-drawer -left">
<div class="chi-drawer__header">
<span class="chi-drawer__title">
Drawer title here
</span>
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
</div>
<div class="chi-drawer__content">
<div class="-p--2 -text">Drawer content here</div>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-13'));</script>
Close button
Close buttons provide users with a consistent way to exit Drawers. For special cases, such as requiring users to perform a task that auto-closes the Drawer when complete, a close button may be removed.
<!-- Trigger -->
<chi-button id="drawer-trigger-14" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-14" position="left" backdrop no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-14');
var drawerTrigger = document.getElementById('drawer-trigger-14');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
active
.
Chi Vue Drawer component does not automatically hide when the close button is clicked as prop mutation is an anti-pattern in Vue.
Use the events chiDrawerHide
and chiDrawerClickOutside
to set active
to false and hide the Drawer.<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="left"
:active="this.drawerActive"
@chiDrawerHide="() => (this.drawerActive = false)"
@chiDrawerClickOutside="() => (this.drawerActive = false)"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-15" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-15" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div class="chi-backdrop -closed">
<div class="chi-backdrop__wrapper">
<div id="drawer-15" class="chi-drawer -left">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-15'));</script>
non-closable
attribute to render Drawer without a close button<!-- Trigger -->
<chi-button id="drawer-trigger-16" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-16" position="left" backdrop non-closable no-header>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-16');
var drawerTrigger = document.getElementById('drawer-trigger-16');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
nonClosable
to render Drawer without a close button<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="left"
:active="this.drawerActive"
:nonClosable="true"
:noHeader="true"
backdrop
>
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-17" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-17" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div class="chi-backdrop -closed">
<div class="chi-backdrop__wrapper">
<div id="drawer-17" class="chi-drawer -left">
<div class="chi-drawer__content">
<div class="-p--2 -pt--6 -text">Drawer content here</div>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-17'));</script>
Header
Header markup is optional. Remove it to make the content fill the drawer.
<!-- Trigger -->
<chi-button id="drawer-trigger-18" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-18" title="Drawer title here" position="bottom" backdrop>
<div class="-p--2 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-18');
var drawerTrigger = document.getElementById('drawer-trigger-18');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="bottom"
:active="this.drawerActive"
title="Drawer title here"
backdrop
>
<div class="-p--2 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-19" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-19" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div class="chi-backdrop -closed">
<div class="chi-backdrop__wrapper">
<div id="drawer-19" class="chi-drawer -bottom">
<div class="chi-drawer__header">
<span class="chi-drawer__title">
Drawer title here
</span>
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
</div>
<div class="chi-drawer__content">
<div class="-p--2 -text">Drawer content here</div>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-19'));</script>
<!-- Trigger -->
<chi-button id="drawer-trigger-20" variant="flat" type="icon">
<chi-icon icon="menu" size="sm--2"></chi-icon>
</chi-button>
<!-- Drawer -->
<chi-drawer id="interactive-drawer-20" position="bottom" backdrop no-header>
<div class="-p--2 -text">Drawer content here</div>
</chi-drawer>
<!-- JavaScript -->
<script>
var drawer = document.getElementById('interactive-drawer-20');
var drawerTrigger = document.getElementById('drawer-trigger-20');
drawerTrigger.addEventListener('click', function(){
drawer.toggle();
// or drawer.active = !drawer.active;
});
</script>
<!-- Trigger -->
<button class="chi-button -flat -icon" @click="() => toggleDrawer()">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</button>
<!-- Vue component -->
<ChiDrawer
position="bottom"
:active="this.drawerActive"
:noHeader="true"
backdrop
>
<div class="-p--2 -text">Drawer content here</div>
</ChiDrawer>
<!-- Data and Methods -->
data: {
drawerActive : false;
},
methods: {
toggleDrawer() {
this.drawerActive = !this.drawerActive;
}
}
<!-- Trigger -->
<button id="drawer-trigger-21" class="chi-button -flat -icon chi-drawer__trigger" data-target="#drawer-21" aria-label="Toggle navigation">
<div class="chi-button__content">
<i class="chi-icon -sm--2 icon-menu" aria-hidden="true"></i>
</div>
</button>
<!-- Drawer -->
<div class="chi-backdrop -closed">
<div class="chi-backdrop__wrapper">
<div id="drawer-21" class="chi-drawer -bottom">
<button class="chi-button -icon -close" aria-label="Close">
<div class="chi-button__content">
<i class="chi-icon icon-x" aria-hidden="true"></i>
</div>
</button>
<div class="chi-drawer__content">
<div class="-p--2 -text">Drawer content here</div>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>chi.drawer(document.getElementById('drawer-trigger-21'));</script>
Web Component
Properties
Events
Methods
Chi Vue
Props
Events
Methods
JavaScript
This component accepts options to configure its behavior.
Methods
Method | Description | Returns |
---|---|---|
hide() => void | Hides the drawer | Type: void |
show() => void | Shows the drawer | Type: void |
toggle() => void | Toggles active state (show/hide) | Type: void |
Events
Event | Description |
---|---|
chiDrawerShow | Drawer show has been triggered, but the showing animation has not started yet. |
chiDrawerHide | Drawer hide has been triggered, but the closing animation has not started yet. |
chiDrawerShown | Drawer has been shown to the user and is fully visible. The animation has completed. |
chiDrawerHidden | Drawer has been hidden to the user. The animation has completed. |
Preventing memory leaks
Drawer components have a dispose function to free all resources attached to the element, such as event listeners and object data. You should call this method when you want to remove the component.
var elem = document.getElementById('drawer-1');
var drawer = chi.drawer(elem);
// do stuff
drawer.dispose();
It is safe to call the drawer
method more than once, as it will return any previously created drawer component
associated with the trigger.
var elem = document.getElementById('drawer-2');
var drawer = chi.drawer(elem);
var elem2 = document.getElementById('drawer-2');
var drawer2 = chi.drawer(elem2);
drawer === drawer2; // returns true
drawer.dispose(); // Only have to do it once.