fix: ensure edit modals close properly on Enter and Escape
All checks were successful
CI / update (push) Successful in 1m12s
All checks were successful
CI / update (push) Successful in 1m12s
- Add setTimeout to defer modal.close() to next tick for proper Svelte binding updates - Add HTMLDialogElement type casting with null checks for modal elements - Add cancel event handlers to reset state when Escape is pressed - Ensures modals close reliably when Enter is pressed to submit - Prevents orphaned state when modals are dismissed with Escape
This commit is contained in:
@@ -180,6 +180,17 @@ export function edit_subheading_and_close_modal(){
|
|||||||
el.close()
|
el.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleIngredientModalCancel() {
|
||||||
|
// Reset reference adding state when modal is cancelled (Escape key)
|
||||||
|
addingToReference = {
|
||||||
|
active: false,
|
||||||
|
list_index: -1,
|
||||||
|
position: 'before',
|
||||||
|
editing: false,
|
||||||
|
item_index: -1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function add_new_ingredient(){
|
export function add_new_ingredient(){
|
||||||
if(!new_ingredient.name){
|
if(!new_ingredient.name){
|
||||||
return
|
return
|
||||||
@@ -230,8 +241,10 @@ export function edit_ingredient_and_close_modal(){
|
|||||||
editing: false,
|
editing: false,
|
||||||
item_index: -1
|
item_index: -1
|
||||||
};
|
};
|
||||||
const modal_el = document.querySelector("#edit_ingredient_modal");
|
const modal_el = document.querySelector("#edit_ingredient_modal") as HTMLDialogElement;
|
||||||
modal_el.close();
|
if (modal_el) {
|
||||||
|
setTimeout(() => modal_el.close(), 0);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,8 +281,11 @@ export function edit_ingredient_and_close_modal(){
|
|||||||
}
|
}
|
||||||
ingredients[edit_ingredient.list_index].name = edit_ingredient.sublist
|
ingredients[edit_ingredient.list_index].name = edit_ingredient.sublist
|
||||||
}
|
}
|
||||||
const modal_el = document.querySelector("#edit_ingredient_modal");
|
const modal_el = document.querySelector("#edit_ingredient_modal") as HTMLDialogElement;
|
||||||
modal_el.close();
|
if (modal_el) {
|
||||||
|
// Defer closing to next tick to ensure all bindings are updated
|
||||||
|
setTimeout(() => modal_el.close(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export function update_list_position(list_index, direction){
|
export function update_list_position(list_index, direction){
|
||||||
if(direction == 1){
|
if(direction == 1){
|
||||||
@@ -811,7 +827,7 @@ h3{
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<dialog id=edit_ingredient_modal>
|
<dialog id=edit_ingredient_modal on:cancel={handleIngredientModalCancel}>
|
||||||
<h2>Zutat verändern</h2>
|
<h2>Zutat verändern</h2>
|
||||||
<div class=adder>
|
<div class=adder>
|
||||||
<input class=category type="text" bind:value={edit_ingredient.sublist} placeholder="Kategorie (optional)">
|
<input class=category type="text" bind:value={edit_ingredient.sublist} placeholder="Kategorie (optional)">
|
||||||
|
|||||||
@@ -210,8 +210,10 @@ export function edit_step_and_close_modal(){
|
|||||||
editing: false,
|
editing: false,
|
||||||
step_index: -1
|
step_index: -1
|
||||||
};
|
};
|
||||||
const modal_el = document.querySelector("#edit_step_modal");
|
const modal_el = document.querySelector("#edit_step_modal") as HTMLDialogElement;
|
||||||
modal_el.close();
|
if (modal_el) {
|
||||||
|
setTimeout(() => modal_el.close(), 0);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,8 +239,11 @@ export function edit_step_and_close_modal(){
|
|||||||
// Normal edit behavior
|
// Normal edit behavior
|
||||||
instructions[edit_step.list_index].steps[edit_step.step_index] = edit_step.step
|
instructions[edit_step.list_index].steps[edit_step.step_index] = edit_step.step
|
||||||
}
|
}
|
||||||
const modal_el = document.querySelector("#edit_step_modal");
|
const modal_el = document.querySelector("#edit_step_modal") as HTMLDialogElement;
|
||||||
modal_el.close();
|
if (modal_el) {
|
||||||
|
// Defer closing to next tick to ensure all bindings are updated
|
||||||
|
setTimeout(() => modal_el.close(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function show_modal_edit_subheading_step(list_index){
|
export function show_modal_edit_subheading_step(list_index){
|
||||||
@@ -254,6 +259,17 @@ export function edit_subheading_steps_and_close_modal(){
|
|||||||
modal_el.close();
|
modal_el.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleStepModalCancel() {
|
||||||
|
// Reset reference adding state when modal is cancelled (Escape key)
|
||||||
|
addingToReference = {
|
||||||
|
active: false,
|
||||||
|
list_index: -1,
|
||||||
|
position: 'before',
|
||||||
|
editing: false,
|
||||||
|
step_index: -1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function clear_step(){
|
export function clear_step(){
|
||||||
const el = document.querySelector("#step")
|
const el = document.querySelector("#step")
|
||||||
@@ -850,7 +866,7 @@ h3{
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<dialog id=edit_step_modal>
|
<dialog id=edit_step_modal on:cancel={handleStepModalCancel}>
|
||||||
<h2>Schritt verändern</h2>
|
<h2>Schritt verändern</h2>
|
||||||
<div class=adder>
|
<div class=adder>
|
||||||
<input class=category type="text" bind:value={edit_step.name} placeholder="Unterkategorie (optional)" on:keydown={(event) => do_on_key(event, 'Enter', false , edit_step_and_close_modal)}>
|
<input class=category type="text" bind:value={edit_step.name} placeholder="Unterkategorie (optional)" on:keydown={(event) => do_on_key(event, 'Enter', false , edit_step_and_close_modal)}>
|
||||||
|
|||||||
Reference in New Issue
Block a user