Skip to content

Commit

Permalink
fix: removeItem() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed May 28, 2024
1 parent 48ee77b commit 8024a3f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions editor.planx.uk/src/@planx/components/List/Public/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ export const ListProvider: React.FC<ListProviderProps> = ({
const editItem = (index: number) => setActiveIndex(index);

const removeItem = (index: number) => {
// If item is currently in Edit mode, exit Edit mode
if (index === activeIndex || index === 0) {
cancelEditItem();
}
// If item is before currently active card, retain active card
if (activeIndex && index < activeIndex) {
// If item is before currently active card, retain active card
setActiveIndex((prev) => (prev === undefined ? 0 : prev - 1));
} else if (index === activeIndex || index === 0) {
// If item is currently in Edit mode, exit Edit mode
cancelEditItem();
}

// Remove item from userData
Expand Down

0 comments on commit 8024a3f

Please sign in to comment.