Update EditModal component to handle Escape key press
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
let modal: HTMLDialogElement;
|
let modal: HTMLDialogElement;
|
||||||
|
|
||||||
|
let originalName = editName;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
||||||
if (modal) {
|
if (modal) {
|
||||||
@@ -27,11 +29,19 @@
|
|||||||
function close() {
|
function close() {
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<dialog id="my_modal_1" class="modal" >
|
<dialog id="my_modal_1" class="modal" >
|
||||||
<div class="modal-box">
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
<h3 class="font-bold text-lg">Edit Adventure {editName}</h3>
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||||
|
<div class="modal-box" role="dialog" on:keydown={handleKeydown} tabindex="0">
|
||||||
|
<h3 class="font-bold text-lg">Edit Adventure {originalName}</h3>
|
||||||
<p class="py-4">Press ESC key or click the button below to close</p>
|
<p class="py-4">Press ESC key or click the button below to close</p>
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<form method="dialog">
|
<form method="dialog">
|
||||||
|
|||||||
Reference in New Issue
Block a user