Skip to content

Commit 00190f5

Browse files
committed
Fix TodoItem deletion animation
- Improve exit animation timing to prevent jumping - Remove y-axis animation from exit to reduce jarring motion - Add staggered animation timing (opacity, scale, then height) - Add layout transition configuration for smooth repositioning - Change AnimatePresence mode for better list animations - Ensure remaining items smoothly move up after deletion
1 parent a4ddd97 commit 00190f5

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export default function Home() {
298298

299299
<main className="sf-main-content w-full mx-auto flex-1 p-[0_16px_40px_16px]">
300300
<div className="sf-todo-list space-y-2 mx-auto w-full max-w-sjofn">
301-
<AnimatePresence mode="popLayout">
301+
<AnimatePresence initial={false}>
302302
{todos.map((todo) => (
303303
<TodoItem
304304
key={todo.id}

components/TodoItem.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,24 @@ const TodoItem = React.forwardRef<HTMLDivElement, TodoItemProps>(
187187
animate={{ opacity: 1, y: 0, scale: 1 }}
188188
exit={{
189189
opacity: 0,
190-
y: -20,
191190
scale: 0.95,
192191
height: 0,
193192
marginTop: 0,
194193
marginBottom: 0,
194+
transition: {
195+
duration: 0.3,
196+
ease: "easeInOut",
197+
height: { duration: 0.2, delay: 0.1 },
198+
opacity: { duration: 0.15 },
199+
scale: { duration: 0.15 },
200+
},
195201
}}
196202
transition={{
197203
type: "spring",
198204
stiffness: 500,
199205
damping: 30,
200206
mass: 1,
207+
layout: { duration: 0.3, ease: "easeInOut" },
201208
}}
202209
layout
203210
onMouseEnter={() => setIsHovered(true)}
@@ -270,6 +277,7 @@ const TodoItem = React.forwardRef<HTMLDivElement, TodoItemProps>(
270277
<div className="bg-sf-fg-soft h-[0.5px] ml-[calc(12px+8px)]"></div>
271278
</motion.div>
272279
);
273-
});
280+
}
281+
);
274282

275283
export default TodoItem;

0 commit comments

Comments
 (0)