# Group-by Morph List

> A grouped list where switching the grouping moves rows into their new groups with shared-layout motion and rolling counts.

- Tier: Eased Pro
- Interaction: Select
- Page: https://eased.dev/components/group-by-list
- Installs: motion

## Install

Group-by Morph List ships with Eased Pro (https://eased.dev/#pricing). Members add the `@eased-pro` registry with their token (https://eased.dev/account), then run:

```bash
npx shadcn add @eased-pro/group-by-list
```

A grouped list whose rows travel into their new groups when the grouping changes, with headers that swap in place and counts that roll.

## When to use

- Issue, task or file lists with a "Group by" control (status, assignee, priority), where seeing rows move shows how the two groupings relate.
- Lists where one row changes group on its own, e.g. a status toggled inline, and should glide to its new section rather than vanish and reappear.
- Sections with live counts in their headers.

## When not to use

- Lists the person orders by hand: use a [Reorder List](/components/reorder-list).
- Tabular data sorted by a column: use a [Sortable Table](/components/sortable-table).
- Hundreds of rows: every row is rendered and animated; use a virtualised list.
- Rows that change height: rows move, they never resize.

## Usage

```tsx example.tsx
import { useState } from "react";
import { GroupedList, type Group } from "@/components/eased/group-by-list/group-by-list";

type Issue = { id: string; title: string; status: "todo" | "in_progress" | "done"; priority: "high" | "low" };

const ISSUES: Issue[] = [
  { id: "ENG-142", title: "Fix token refresh race", status: "in_progress", priority: "high" },
  { id: "ENG-147", title: "Flaky checkout e2e on Safari", status: "todo", priority: "high" },
  { id: "ENG-156", title: "Paginate audit log export", status: "todo", priority: "low" },
  { id: "ENG-128", title: "Contrast pass on settings page", status: "done", priority: "low" },
];

const GROUPINGS = {
  status: {
    by: (i: Issue) => i.status,
    groups: [
      { id: "todo", label: "Todo" },
      { id: "in_progress", label: "In progress" },
      { id: "done", label: "Done" },
    ] satisfies Group[],
  },
  priority: {
    by: (i: Issue) => i.priority,
    groups: [
      { id: "high", label: "High" },
      { id: "low", label: "Low" },
    ] satisfies Group[],
  },
};

export function Example() {
  const [grouping, setGrouping] = useState<keyof typeof GROUPINGS>("status");
  const { by, groups } = GROUPINGS[grouping];
  return (
    <>
      <button type="button" onClick={() => setGrouping(grouping === "status" ? "priority" : "status")}>
        Group by {grouping === "status" ? "priority" : "status"}
      </button>
      <GroupedList
        aria-label="Issues"
        items={ISSUES}
        groupBy={by}
        groups={groups}
        maxHeight={360}
        renderRow={(issue) => <div className="flex h-9 items-center px-2.5 text-ui-sm">{issue.title}</div>}
      />
    </>
  );
}
```

`items` and `groups` are compared by identity, so keep them in module scope, state or `useMemo`. Swap `groupBy` and `groups` together.

## Examples

### Empty groups

`showEmpty` keeps a header for groups with no rows; `emptyLabel` adds a muted line under it.

```tsx
<GroupedList
  items={issues}
  groupBy={(i) => i.status}
  groups={statusGroups}
  showEmpty
  emptyLabel="No issues"
  renderRow={(issue) => <IssueRow issue={issue} />}
/>
```

### Rows without an `id`

`getRowKey` is optional when items have a string `id` and required otherwise. The key must stay the same across groupings so each row keeps its DOM node and can travel.

```tsx
<GroupedList
  items={files}
  getRowKey={(file) => file.path}
  groupBy={(file) => file.owner}
  groups={owners}
  renderRow={(file) => <FileRow file={file} />}
/>
```

### Custom header

`renderHeader` replaces the icon, label and rolling count; the result is still wrapped in the heading element.

```tsx
<GroupedList
  items={issues}
  groupBy={(i) => i.status}
  groups={statusGroups}
  headingLevel={2}
  renderHeader={(group, count) => (
    <span className="px-2.5 text-ui-sm font-medium">
      {group.label} · {count}
    </span>
  )}
  renderRow={(issue) => <IssueRow issue={issue} />}
/>
```

## API reference

### GroupedList

| Prop | Type | Default | Description |
|---|---|---|---|
| `items` | `readonly T[]` | | The rows. A new array identity is read as a change, so memoise it. |
| `groupBy` | `(item: T) => string` | | The group id an item belongs to. Items whose id is not in `groups` are not rendered. |
| `groups` | `readonly Group[]` | | Groups in display order. Memoise it. |
| `renderRow` | `(item: T) => ReactNode` | | A row's content. Keep its height fixed. |
| `getRowKey` | `(item: T) => string` | `item.id` | A stable key per row. Required when `T` has no string `id`. |
| `renderHeader` | `(group: Group, count: number) => ReactNode` | | Replaces the default header (icon, label, rolling count). |
| `headingLevel` | `2 \| 3 \| 4 \| 5 \| 6` | `3` | The heading level of group headers, to fit the page's outline. |
| `showEmpty` | `boolean` | `false` | Render headers for groups with no items. |
| `emptyLabel` | `ReactNode` | | Muted text under an empty group's header when `showEmpty` is on. |
| `aria-label` | `string` | | Names the list. |
| `maxHeight` | `number \| string` | | Max height of the scroll root, in px or any CSS length. Past it the list scrolls, with fades at the edges that have more content. |
| `className` | `string` | `""` | Classes for the scroll root. Give it a height (`h-full`, `flex-1`) to scroll inside a fixed box. |

### Group

| Field | Type | Description |
|---|---|---|
| `id` | `string` | What `groupBy` returns. Must be unique across every grouping you switch between. |
| `label` | `string` | The header text. |
| `icon` | `ReactNode` | Drawn before the label. |

## Accessibility

- The list is a `<ul>` named by `aria-label`. Group headers are real headings at `headingLevel`, inside list items marked `role="presentation"`, so the list's item count is the rows (plus any empty-group lines).
- The default header reads "Todo, 3": an `sr-only` copy carries the label and count, and the animated label and rolling digits are `aria-hidden`. A custom `renderHeader` is read as you render it.
- The list adds no keyboard handling or tab stops of its own; interactive content in a row brings its own. Tab order follows the current grouping, since rows are reordered in the DOM, not only on screen.
- Regroups are not announced; announce them from the control that changes the grouping if that matters to your page.

## Motion

Headers and rows are one flat list, so every row keeps its key across groupings and its position animates as a FLIP on the `smooth` spring (0.4s, no overshoot). When a row has changed group, the move cascades top to bottom, 35ms per entry, compressed so the last one starts within 320ms however long the list. Headers are keyed by slot rather than by group: a group that survives keeps its header and its count rolls, and a new group takes over the header of one that left, so its label swaps in place (out up 3px, in from 4px below, 4px blur, on `snappy`) instead of the whole set blinking out and in. Counts are odometers: only the digits that change roll, up when the count grows and down when it shrinks. Rows and headers that appear fade in over 150ms and leave in 100ms; a plain refresh where no row changed group moves without the cascade. Reduced motion: no FLIP and no slide, everything cross-fades in 100ms.

## Notes for AI

Pick GroupedList when a list has a "Group by" switch or rows that move between sections, and the move itself helps people follow what changed. Keep `items` in state, define each grouping's `groupBy` and `groups` once outside render, and switch them together; give group ids that are unique across all groupings.

Do not wrap rows in your own `motion` elements with `layout`, do not add `AnimatePresence` around it, and do not key rows by index: the list already FLIPs, fades and staggers them by key. Do not let rows grow or shrink; put expandable detail somewhere else.

## Related

- [Reorder List](/components/reorder-list): rows the person drags into their own order.
- [Sortable Table](/components/sortable-table): rows ordered by a column.
- [Segmented](/components/segmented): a compact control to switch the grouping.
