From f7c135f49873f6731d139ffb0052cc1e34c551fe Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 9 Jun 2024 12:37:01 +0200 Subject: [PATCH] Added quick delete if the popover for one event is deployed --- components/calendar/CalendarEvent.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/calendar/CalendarEvent.vue b/components/calendar/CalendarEvent.vue index c0f0811..8abdc39 100644 --- a/components/calendar/CalendarEvent.vue +++ b/components/calendar/CalendarEvent.vue @@ -18,7 +18,6 @@ const isStartEvent = spansMultipleDays && areDatesIdentical(props.tileDate, prop const isEndEvent = spansMultipleDays && props.event.endDate && areDatesIdentical(props.tileDate, props.event.endDate) const titleCharLimit = 50; - const eventTitle = computed(() => props.event.title.length <= titleCharLimit ? props.event.title : `${props.event.title.slice(0, titleCharLimit)}…`) // Popover code @@ -39,6 +38,19 @@ function handleDelete() { function handleClosePopover() { isPopoverDetailsOpen.value = false } + +onMounted(() => { + // Listen for keydown events + window.addEventListener('keydown', (e: KeyboardEvent) => { + // If the popover isn't opened, this is not the event we're trying to delete, so return + if (!isPopoverDetailsOpen.value) return + + // If the key isn't the delete one, return + if (e.key !== 'Delete') return + + handleDelete() + }) +})