Skip to content

Commit

Permalink
Added close on esc button
Browse files Browse the repository at this point in the history
  • Loading branch information
elizachi committed Jul 20, 2024
1 parent 382694b commit 1a8764f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion codex-ui/src/vue/components/popup/Popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { ref, onMounted, onUnmounted } from 'vue';
import Icon from '../icon/Icon.vue';
import { usePopup } from './usePopup';
import { onClickOutside } from '@vueuse/core';
Expand All @@ -45,6 +45,18 @@ const {
*/
onClickOutside(popupEl, hidePopup);
/**
* Close the popup when esc was pressed
*
* @param event - the event object representing the keyboard event
* @param event.key - the property of the event object that holds the value of the pressed key
*/
const closeOnEsc = (event: { key: string }) => {
if (event.key === 'Escape') {
hidePopup();
}
};
withDefaults(
defineProps<{
/**
Expand All @@ -57,6 +69,14 @@ withDefaults(
}
);
onMounted(() => {
document.addEventListener('keydown', closeOnEsc);
});
onUnmounted(() => {
document.removeEventListener('keydown', closeOnEsc);
});
</script>

<style module>
Expand Down

0 comments on commit 1a8764f

Please sign in to comment.