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}