mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 16:20:27 +00:00
listen for esc to close modals
This commit is contained in:
parent
b9a255914b
commit
da2e0103c3
1 changed files with 14 additions and 0 deletions
|
@ -32,6 +32,12 @@
|
|||
},
|
||||
});
|
||||
|
||||
function escClose(e: KeyboardEvent) {
|
||||
if (e.key === "Escape") {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (props.readonly) {
|
||||
emit("cancel");
|
||||
|
@ -42,4 +48,12 @@
|
|||
|
||||
const modalId = useId();
|
||||
const modal = useVModel(props, "modelValue", emit);
|
||||
|
||||
watchEffect(() => {
|
||||
if (modal.value) {
|
||||
document.addEventListener("keydown", escClose);
|
||||
} else {
|
||||
document.removeEventListener("keydown", escClose);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue