Skip to content

Commit

Permalink
feat: esc key event added to side sheet component (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
roger-in-kiva authored Jan 22, 2025
1 parent 3e9d271 commit 66f901f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions @kiva/kv-components/src/vue/KvSideSheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default {
const open = ref(false);
const initialStyles = ref({});
const modalStyles = ref({});
let onKeyUp = null;
const avoidBodyScroll = () => {
const bodyClasses = 'tw-overflow-hidden';
Expand All @@ -145,14 +146,24 @@ export default {
setTimeout(() => {
emit('side-sheet-closed');
}, '700');
document.removeEventListener('keyup', onKeyUp);
};
const goToLink = () => {
emit('go-to-link');
};
onKeyUp = (e) => {
if (!!e && e.key === 'Escape') {
closeSideSheet();
}
};
watch(visible, () => {
if (visible.value) {
document.addEventListener('keyup', onKeyUp);
setTimeout(() => {
open.value = true;
avoidBodyScroll();
Expand Down

0 comments on commit 66f901f

Please sign in to comment.