08Remove-item collapse — a removed row's height value shrinking to zero as rows below close the gap
Once a row is removed, its height value shrinks to zero while the rows below follow with a matching position value that closes the gap, and once that value reaches zero the row leaves the list.
Best forA cart list where items can be removed
collapseRoweaseInCubicSTOCK

<main class="stage">
<div class="cric is-demo" id="cric">
<ul class="cric__list" id="cricList">
<li class="cric__row" data-name="Sneakers"><span>Sneakers</span><b>$52</b>
<button class="cric__x" type="button" aria-label="Remove">×</button>
</li>
<li class="cric__row" data-name="Socks"><span>Socks</span><b>$9</b>
<button class="cric__x" type="button" aria-label="Remove">×</button>
</li>
<li class="cric__row" data-name="Insoles"><span>Insoles</span><b>$7</b>
<button class="cric__x" type="button" aria-label="Remove">×</button>
</li>
</ul>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 계산 겹: 삭제된 행의 실측 높이(px)에서 시작해 매 프레임 3제곱 이징으로 0 에 다가가는 값을
// 계산한다(collapseRow(), index.html) — CSS max-height 전환이 아니라 실측치 기반 보간이다.
$duration: $dur-base;
$easing: $ease-out;
$color: $subject-blue-deep;
@include stage($stage-paper);
.cric {
width: min(240px, 70vw);
}
.cric__list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: $sp-2;
}
.cric__row {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
gap: $sp-2;
padding: $sp-3;
border-radius: $r-control;
background: rgba(23, 20, 26, .06);
color: $subject-ink;
font-weight: 600;
font-size: 13px;
transform-origin: left center;
}
.cric__x {
border: 0;
border-radius: $r-pill;
width: 22px;
height: 22px;
flex: 0 0 auto;
background: $color;
color: $subject-cream;
font-family: inherit;
font-size: 13px;
line-height: 1;
display: grid;
place-items: center;
cursor: pointer;
}
@media (max-width: 340px) {
.cric { width: min(190px, 66vw); }
.cric__row { font-size: 12px; padding: $sp-2; }
}
@media (prefers-reduced-motion: reduce) {
.cric__row { transition: none !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffffff;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.cric {
width: min(240px, 70vw);
}
.cric__list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.cric__row {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 12px;
border-radius: 12px;
background: rgba(23, 20, 26, 0.06);
color: #17141a;
font-weight: 600;
font-size: 13px;
transform-origin: left center;
}
.cric__x {
border: 0;
border-radius: 999px;
width: 22px;
height: 22px;
flex: 0 0 auto;
background: #0a4fe8;
color: #fff7e6;
font-family: inherit;
font-size: 13px;
line-height: 1;
display: grid;
place-items: center;
cursor: pointer;
}
@media (max-width: 340px) {
.cric {
width: min(190px, 66vw);
}
.cric__row {
font-size: 12px;
padding: 8px;
}
}
@media (prefers-reduced-motion: reduce) {
.cric__row {
transition: none !important;
}
}(function () {
var root = document.getElementById('cric');
var list = document.getElementById('cricList');
// 계산 겹: 삭제된 행의 실제 높이(px)를 시작값으로 두고 매 프레임 지수 감쇠로 0에 다가가게
// 계산한다(collapseTo0()) — max-height 전환 곡선이 아니라 실측 높이에서 시작하는 보간이다.
var DUR_MS = 320;
function easeInCubic(p) { return p * p * p; }
function collapseRow(row) {
var h = row.getBoundingClientRect().height;
row.style.overflow = 'hidden';
row.style.height = h + 'px';
row.style.willChange = 'height, opacity, transform';
var start = performance.now();
function frame(now) {
var p = Math.min(1, (now - start) / DUR_MS);
var eased = easeInCubic(p);
row.style.height = (h * (1 - eased)) + 'px';
row.style.opacity = String(1 - eased);
row.style.transform = 'translateX(' + (-eased * 24) + 'px)';
if (p < 1) {
requestAnimationFrame(frame);
} else {
row.remove();
refillIfEmpty();
}
}
requestAnimationFrame(frame);
}
var STOCK = [
['Eco Bag', '$11'], ['Mug', '$13'], ['Card Wallet', '$22'],
['Umbrella', '$17'], ['Ball Cap', '$19']
];
var stockIndex = 0;
function addRow() {
var item = STOCK[stockIndex % STOCK.length];
stockIndex += 1;
var li = document.createElement('li');
li.className = 'cric__row';
li.innerHTML = '<span>' + item[0] + '</span><b>' + item[1] + '</b><button class="cric__x" type="button" aria-label="Remove">×</button>';
list.appendChild(li);
bindRow(li);
}
function refillIfEmpty() {
if (list.children.length < 2) {
addRow();
}
}
function bindRow(row) {
var btn = row.querySelector('.cric__x');
btn.addEventListener('click', function () {
root.classList.remove('is-demo');
stopAutoplay();
collapseRow(row);
});
}
Array.prototype.forEach.call(list.querySelectorAll('.cric__row'), bindRow);
var autoplayTimer = null;
function stopAutoplay() {
if (autoplayTimer) { clearInterval(autoplayTimer); autoplayTimer = null; }
}
function autoTick() {
var rows = list.querySelectorAll('.cric__row');
if (rows.length) {
collapseRow(rows[0]);
}
}
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (!reduce) {
autoplayTimer = setInterval(autoTick, 1100);
}
})();import { useEffect, useRef, useState } from "react";
import type { CSSProperties } from "react";
import styles from "./CartDrawerRemoveItemCollapse.module.scss";
export type CartDrawerRemoveItemCollapseProps = {
duration?: number;
color?: string;
};
type Row = { id: number; name: string; price: string };
const STOCK: [string, string][] = [
["에코백", "$11"], ["머그컵", "$13"], ["카드지갑", "$22"],
["우산", "$17"], ["볼캡", "$19"],
];
const DUR_MS = 320;
// 계산 겹: 삭제된 행의 실제 높이(px)를 시작값으로 두고 매 프레임 3제곱 이징으로 0 에 다가가게
// 계산한다(collapseRow()) — max-height 전환 곡선이 아니라 실측 높이에서 시작하는 보간이다.
function easeInCubic(p: number): number {
return p * p * p;
}
export default function CartDrawerRemoveItemCollapse({
color = "#0a4fe8",
}: CartDrawerRemoveItemCollapseProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
const listRef = useRef<HTMLUListElement | null>(null);
const [rows, setRows] = useState<Row[]>([
{ id: 0, name: "스니커즈", price: "$52" },
{ id: 1, name: "양말", price: "$9" },
{ id: 2, name: "깔창", price: "$7" },
]);
const stockIndexRef = useRef(0);
const nextIdRef = useRef(3);
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);
function refillIfEmpty(count: number) {
if (count < 2) {
const item = STOCK[(stockIndexRef.current ?? 0) % STOCK.length];
stockIndexRef.current = (stockIndexRef.current ?? 0) + 1;
const id = nextIdRef.current ?? 3;
nextIdRef.current = (nextIdRef.current ?? 3) + 1;
setRows((prev) => [...prev, { id, name: item[0], price: item[1] }]);
}
}
function collapseRow(id: number) {
const li = listRef.current?.querySelector<HTMLLIElement>(`[data-id="${id}"]`);
if (!li) return;
const h = li.getBoundingClientRect().height;
li.style.overflow = "hidden";
li.style.height = `${h}px`;
li.style.willChange = "height, opacity, transform";
const start = performance.now();
function frame(now: number) {
const p = Math.min(1, (now - start) / DUR_MS);
const eased = easeInCubic(p);
li!.style.height = `${h * (1 - eased)}px`;
li!.style.opacity = String(1 - eased);
li!.style.transform = `translateX(${-eased * 24}px)`;
if (p < 1) {
requestAnimationFrame(frame);
} else {
setRows((prev) => {
const next = prev.filter((r) => r.id !== id);
refillIfEmpty(next.length);
return next;
});
}
}
requestAnimationFrame(frame);
}
function stopAutoplay() {
if (timerRef.current) {
clearInterval(timerRef.current);
timerRef.current = null;
}
}
useEffect(() => {
function autoTick() {
const first = listRef.current?.querySelector<HTMLLIElement>(`.${styles.row}`);
const id = first?.getAttribute("data-id");
if (id != null) collapseRow(Number(id));
}
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (!reduce) {
timerRef.current = setInterval(autoTick, 1100);
}
return stopAutoplay;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<div ref={rootRef} className={`${styles.stage} ${styles.isDemo}`} style={{ "--color": color } as CSSProperties}>
<div className={styles.cric}>
<ul ref={listRef} className={styles.list}>
{rows.map((row) => (
<li key={row.id} data-id={row.id} className={styles.row}>
<span>{row.name}</span>
<b>{row.price}</b>
<button
className={styles.x}
type="button"
aria-label="삭제"
onClick={() => {
rootRef.current?.classList.remove(styles.isDemo);
stopAutoplay();
collapseRow(row.id);
}}
>
×
</button>
</li>
))}
</ul>
</div>
</div>
);
}08 Remove-item collapse — a removed row's height value shrinking to zero as rows below close the gap — Measured area 26.947% · moving frames 8/23Original by GODRICH · SCSS and React ship in the zip · Cart Drawer UI Patterns: 9 Motion Techniques
The post this demo lives in
Cart Drawer UI Patterns: 9 Motion TechniquesOne panel overshoots its open position before a spring curve settles it, one drag distance meets growing resistance past See all demos in this post
If you like this effect - similar demos
Transitions05 Row-delete and height values changing together — when a row's existence value ends, its height value shrinks to zero while the rows below fill the gap with their position valuesCollapsible Table Row: 9 UI Patterns
Transitions02 Chip remove collapse — a row recomputing container width from remaining chip count9 Filter UI Patterns (Panel Slide to Chip Remove)
Transitions06 Backdrop dismiss fade — the opacity value drops to zero once a click outside the menu is registeredContext Menu UI: 9 Right-Click Menu Patterns