forked from mirrors/homebox
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:
parent
0de6c2338d
commit
97e137c411
4 changed files with 124 additions and 33 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