From ee3fff1dab1042098b6d15d8f28dcbe18b6ad5cf Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 26 Oct 2026 21:50:37 +0100 Subject: [PATCH] fix(packing): Enter on the first item keeps the typing going in the add field A new list starts with a '...' placeholder row. Typing the first item there and pressing Enter saved it but left the cursor nowhere, while the "Add item" field puts it straight back for the next item. Enter on a filled placeholder row now opens the category's add field and focuses it. A blur still just saves, so clicking elsewhere does not pull the focus back. Closes #2825 --- .../PackingListPanelCategoryGroup.test.tsx | 11 +++++++++++ .../Packing/PackingListPanelCategoryGroup.tsx | 5 +++-- .../Packing/PackingListPanelItemRow.test.tsx | 17 +++++++++++++++++ .../Packing/PackingListPanelItemRow.tsx | 15 ++++++++++----- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/client/src/components/Packing/PackingListPanelCategoryGroup.test.tsx b/client/src/components/Packing/PackingListPanelCategoryGroup.test.tsx index 3bffc1810..f1bb65211 100644 --- a/client/src/components/Packing/PackingListPanelCategoryGroup.test.tsx +++ b/client/src/components/Packing/PackingListPanelCategoryGroup.test.tsx @@ -485,6 +485,17 @@ describe('KategorieGruppe — inline add item', () => { expect(onAddItem).not.toHaveBeenCalled() }) + it('FE-W5CAT-028a: Enter on the first item typed into the placeholder row opens the add field (#2825)', async () => { + server.use(http.put('/api/trips/1/packing/1', () => HttpResponse.json({ item: buildPackingItem({ id: 1, name: 'Tent', category: 'Gear' }) }))) + setup({ items: [buildPackingItem({ id: 1, name: '...', category: 'Gear' })] }) + + fireEvent.click(screen.getByText('...')) + fireEvent.change(screen.getByPlaceholderText('...'), { target: { value: 'Tent' } }) + fireEvent.keyDown(screen.getByPlaceholderText('...'), { key: 'Enter' }) + + await waitFor(() => expect(screen.getByPlaceholderText('Item name...')).toHaveFocus()) + }) + it('FE-W5CAT-028: the confirm button adds the item, and stays inert while empty', () => { const onAddItem = vi.fn(async () => {}) const { container } = setup({ onAddItem }) diff --git a/client/src/components/Packing/PackingListPanelCategoryGroup.tsx b/client/src/components/Packing/PackingListPanelCategoryGroup.tsx index d3f635538..479ce46f6 100644 --- a/client/src/components/Packing/PackingListPanelCategoryGroup.tsx +++ b/client/src/components/Packing/PackingListPanelCategoryGroup.tsx @@ -86,6 +86,7 @@ export function KategorieGruppe({ kategorie, items, tripId, allCategories, onRen const [showAddItem, setShowAddItem] = useState(false) const [newItemName, setNewItemName] = useState('') const addItemRef = useRef(null) + const openAddItem = () => { setShowAddItem(true); setTimeout(() => addItemRef.current?.focus(), 30) } const menuBtnRef = useRef(null) const assigneeDropdownRef = useRef(null) const { togglePackingItem } = useTripStore() @@ -292,7 +293,7 @@ export function KategorieGruppe({ kategorie, items, tripId, allCategories, onRen const contributions = contribFor(item.id) return ( - {}} onDelete={onDeleteItem} bagTrackingEnabled={bagTrackingEnabled} bags={bags} onCreateBag={onCreateBag} canEdit={canEdit} divider={index > 0} + {}} onDelete={onDeleteItem} onPlaceholderFilled={openAddItem} bagTrackingEnabled={bagTrackingEnabled} bags={bags} onCreateBag={onCreateBag} canEdit={canEdit} divider={index > 0} tripMembers={tripMembers} currentUserId={currentUserId} onSetSharing={onSetSharing} onClone={onClone} onJoin={onJoin} onLeave={onLeave} drag={canEdit && reorderable ? { isDragging: dragId === item.id, @@ -343,7 +344,7 @@ export function KategorieGruppe({ kategorie, items, tripId, allCategories, onRen // A row of its own on a faint tint, so it closes the card instead // of trailing off: a dashed box in the checkbox column (past the drag // grip's width) and the label where an item's name sits. -