From a9e4d5fb50681eea6728e3e808097587e56e62b3 Mon Sep 17 00:00:00 2001 From: june Date: Fri, 15 Aug 2025 15:21:48 +1200 Subject: [PATCH] Enter key navigation for ingredient fields, great for mobile --- src/script/newRecipe.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/script/newRecipe.ts b/src/script/newRecipe.ts index b860a1a..dcbbd16 100644 --- a/src/script/newRecipe.ts +++ b/src/script/newRecipe.ts @@ -29,12 +29,26 @@ document.addEventListener('DOMContentLoaded', function() { // show plus button once the user types in the text fields ingredientFields.forEach(f => { f.addEventListener('input', showAddIngredientButton) - f.addEventListener('keyup', showAddIngredientButton) + f.addEventListener('keydown', showAddIngredientButton) }) // onclick for add button document.querySelector('#add-ingredient-btn')?.addEventListener('click', addIngredient); - // for pressing enter to reset cursor - ingredientFields[2].addEventListener('keyup', e => {if (e.key === 'Enter') addIngredient()} ) + + // Enter key navigation for ingredient fields + ingredientFields[0].addEventListener('keydown', e => { + if (e.key === 'Enter') { + ingredientFields[1].focus() // Move from qty to unit + } + }) + + ingredientFields[1].addEventListener('keydown', e => { + if (e.key === 'Enter') { + ingredientFields[2].focus() // Move from unit to name + } + }) + + // for pressing enter to add ingredient (on the last field) + ingredientFields[2].addEventListener('keydown', e => {if (e.key === 'Enter') addIngredient()} ) // Initial check for button state showAddIngredientButton() @@ -92,7 +106,7 @@ function renderSteps() { const newStep = document.createElement('div') // times like this i regret using astro newStep.innerHTML = ` -
+

Step ${displayIndex + 1}

@@ -102,6 +116,7 @@ function renderSteps() {
+