feat: add support for create + add more for all create modals and support k… (#526)

* add support for create + add more for all create modals and support keyboard bindings

* listen for esc to close modals

Former-commit-id: 22bbaae08f
This commit is contained in:
Hayden 2023-07-31 09:53:26 -08:00 committed by GitHub
parent 0de6c2338d
commit 97e137c411
4 changed files with 124 additions and 33 deletions

View file

@ -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>