Table
Table.Root는 table contract 토큰으로 스타일을 정한 네이티브 <table>입니다. 파트로 표를 만드세요. Table.Caption, Table.Head, Table.Body, Table.Foot, Table.Row, Table.HeaderCell, Table.Cell은 각각 <caption>, <thead>, <tbody>, <tfoot>, <tr>, <th>, <td>를 렌더링하므로, 표는 브라우저가 주는 의미를 그대로 유지합니다. 숫자는 고정폭 숫자를 써서 자릿수의 폭이 같습니다. 숫자 열에 text-align: end를 주면 값이 오른쪽으로 맞춰집니다.
이 페이지의 내용
import { Table } from '@tounsoo/todae/table';
export default function TableOfInvoices() {
return (
<Table.Root>
<Table.Caption>Invoices this quarter</Table.Caption>
<Table.Head>
<Table.Row>
<Table.HeaderCell scope="col">Invoice</Table.HeaderCell>
<Table.HeaderCell scope="col">Date</Table.HeaderCell>
<Table.HeaderCell scope="col" style={{ textAlign: 'end' }}>
Amount
</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
<Table.Row>
<Table.HeaderCell scope="row">INV-1042</Table.HeaderCell>
<Table.Cell>2026-07-03</Table.Cell>
<Table.Cell style={{ textAlign: 'end' }}>$1,200.00</Table.Cell>
</Table.Row>
<Table.Row>
<Table.HeaderCell scope="row">INV-1043</Table.HeaderCell>
<Table.Cell>2026-08-01</Table.Cell>
<Table.Cell style={{ textAlign: 'end' }}>$980.00</Table.Cell>
</Table.Row>
<Table.Row>
<Table.HeaderCell scope="row">INV-1044</Table.HeaderCell>
<Table.Cell>2026-09-02</Table.Cell>
<Table.Cell style={{ textAlign: 'end' }}>$1,450.00</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Root>
);
}
| Invoice | Date | Amount |
|---|---|---|
| INV-1042 | 2026-07-03 | $1,200.00 |
| INV-1043 | 2026-08-01 | $980.00 |
| INV-1044 | 2026-09-02 | $1,450.00 |
Server Components는 @tounsoo/todae/table에서 가져올 수 있습니다. 모든 열 머리글에는 scope="col"을, 모든 행 머리글에는 scope="row"를 주세요. Table.Caption은 스크린 리더에 표의 이름을 알려 줍니다. table.border, table.rule.thickness, table.header.*, table.caption.fg, table.cell.padding.*로 스타일을 바꾸세요. 패딩은 밀도를 따릅니다.
정렬
정렬할 수 있는 열의 Table.HeaderCell에 sort를 'ascending', 'descending', 'none' 중 하나로 주고, 그 안에 열의 레이블을 children으로 한 Table.SortButton을 넣으세요. 셀에는 data-sort가 붙고, 정렬된 열에만 aria-sort가 붙습니다. 'none'은 aria-sort를 붙이지 않으므로 data-sort만이 그 열이 정렬 가능하다고 표시합니다. Todae는 행을 정렬하지 않습니다. 메모리에서든 요청으로든 직접 정렬하고, onClick에서 각 셀의 sort를 설정하세요.
import { Table, type TableSort } from '@tounsoo/todae';
import { useState } from 'react';
const INVOICES = [
{ id: 'INV-1042', status: 'Paid', amount: 1200 },
{ id: 'INV-1043', status: 'Overdue', amount: 980 },
{ id: 'INV-1044', status: 'Paid', amount: 1450 },
{ id: 'INV-1045', status: 'Draft', amount: 310 },
];
type Column = 'id' | 'amount';
type Sorted = { column: Column; direction: 'ascending' | 'descending' };
const dollars = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });
export default function SortableTable() {
const [sorted, setSorted] = useState<Sorted>({ column: 'id', direction: 'ascending' });
const rows = [...INVOICES].sort((a, b) => {
const order = sorted.column === 'id' ? a.id.localeCompare(b.id) : a.amount - b.amount;
return sorted.direction === 'ascending' ? order : -order;
});
const sortOf = (column: Column): TableSort => (sorted.column === column ? sorted.direction : 'none');
const sortBy = (column: Column) =>
setSorted({
column,
direction: sorted.column === column && sorted.direction === 'ascending' ? 'descending' : 'ascending',
});
return (
<Table.Root>
<Table.Caption>Invoices this quarter</Table.Caption>
<Table.Head>
<Table.Row>
<Table.HeaderCell scope="col" sort={sortOf('id')}>
<Table.SortButton onClick={() => sortBy('id')}>Invoice</Table.SortButton>
</Table.HeaderCell>
<Table.HeaderCell scope="col">Status</Table.HeaderCell>
<Table.HeaderCell scope="col" sort={sortOf('amount')} style={{ textAlign: 'end' }}>
<Table.SortButton onClick={() => sortBy('amount')}>Amount</Table.SortButton>
</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{rows.map((row) => (
<Table.Row key={row.id}>
<Table.HeaderCell scope="row">{row.id}</Table.HeaderCell>
<Table.Cell>{row.status}</Table.Cell>
<Table.Cell style={{ textAlign: 'end' }}>{dollars.format(row.amount)}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
);
}
| Status | ||
|---|---|---|
| INV-1042 | Paid | $1,200.00 |
| INV-1043 | Overdue | $980.00 |
| INV-1044 | Paid | $1,450.00 |
| INV-1045 | Draft | $310.00 |
Table.SortButton은 네이티브 <button>입니다. 레이블 뒤에 GlyphsProvider의 sort 글리프를 그리며, 기본은 위를 가리키는 화살표입니다. 정렬된 열에서는 보이고, 내림차순 열에서는 돌아갑니다. 정렬되지 않은 열에서는 터치스크린을 포함한 모든 화면에서 보이지 않지만 자리는 유지하므로, 정렬되어도 열 너비가 바뀌지 않습니다. 그 열에서는 키보드 포커스 때, 그리고 hover할 수 있는 포인터가 있는 기기에서는 hover 때 흐리게 보입니다. 모양은 헤더 셀의 data-sort를 따르므로 Table.HeaderCell을 감싼 래퍼도 계속 동작합니다. 클릭하면 사용자가 다음에 무언가를 누르거나 키를 입력하기 전까지(스크린 리더를 멈추는 Control처럼 수정 키만 누르는 것은 세지 않습니다), 코드가 어떻게 바꾸든 셀의 aria-sort나 data-sort가 바뀌기를 기다렸다가, 결과를 useAnnouncer로 한 번 알립니다. 열 이름은 버튼의 aria-label이나 텍스트이고, 문장은 StringsProvider의 sortedAscending, sortedDescending, sortCleared 문자열입니다. Table.SortButton은 훅이 필요하므로 @tounsoo/todae/table이 아니라 @tounsoo/todae에서 가져오며, 클라이언트 컴포넌트 안에 둡니다.
행 선택
선택 상태는 useSelection과 Checkbox.Root입니다. 훅이 선택된 키를 보관하고, 그 getter가 각 체크박스에 props를 줍니다. getSelectAllProps()로 만든 헤더 체크박스는 모든 행이 선택되면 체크되고, 일부만 선택되면 혼합 상태가 됩니다. Table.Row는 selected를 받는데, 이는 data-selected와 배경색만 설정합니다. 그리드가 아닌 표의 행에는 aria-selected가 맞지 않으므로 더하지 않으며, 보조 기술에는 행의 체크박스가 상태를 전합니다.
import { Checkbox, Table, useSelection, VisuallyHidden } from '@tounsoo/todae';
const PEOPLE = [
{ id: 1, name: 'Ada Lovelace', role: 'Analyst' },
{ id: 2, name: 'Grace Hopper', role: 'Engineer' },
{ id: 3, name: 'Alan Turing', role: 'Researcher' },
{ id: 4, name: 'Edsger Dijkstra', role: 'Engineer' },
{ id: 5, name: 'Barbara Liskov', role: 'Researcher' },
];
export default function SelectableTable() {
const selection = useSelection({ keys: PEOPLE.map((person) => person.id), defaultValue: [2] });
return (
<Table.Root>
<Table.Caption>Team</Table.Caption>
<Table.Head>
<Table.Row>
<Table.HeaderCell scope="col">
<Checkbox.Root {...selection.getSelectAllProps()}>
<VisuallyHidden.Root>Select all rows</VisuallyHidden.Root>
</Checkbox.Root>
</Table.HeaderCell>
<Table.HeaderCell scope="col">Name</Table.HeaderCell>
<Table.HeaderCell scope="col">Role</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{PEOPLE.map((person) => (
<Table.Row key={person.id} selected={selection.isSelected(person.id)}>
<Table.Cell>
<Checkbox.Root {...selection.getCheckboxProps(person.id)}>
<VisuallyHidden.Root>{`Select ${person.name}`}</VisuallyHidden.Root>
</Checkbox.Root>
</Table.Cell>
<Table.HeaderCell scope="row">{person.name}</Table.HeaderCell>
<Table.Cell>{person.role}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
);
}
| Name | Role | |
|---|---|---|
| Ada Lovelace | Analyst | |
| Grace Hopper | Engineer | |
| Alan Turing | Researcher | |
| Edsger Dijkstra | Engineer | |
| Barbara Liskov | Researcher |
행의 체크박스를 클릭하면서 Shift를 누르고 있으면, 또는 Shift를 누른 채 Space를 누르면, 마지막으로 토글한 행부터 이 행까지 모든 행이 선택되거나 해제됩니다. 배경색은 table.row.bg.selected로 바꾸세요.
접근성을 지키는 조합
Todae가 맡는 것: 파트가 렌더링하는 네이티브 <table>, <caption>, <th>, <td>는 의미를 그대로 유지하고, 스타일은 머리글 셀에 자체 굵기와 색을 주므로 배경색 없이도 눈에 띕니다. sort가 있는 Table.HeaderCell은 정렬된 열에 aria-sort를 설정합니다. Table.SortButton은 진짜 버튼이고, 포커스를 받으며, 포커스 링을 보여 주고, 자신이 클릭된 뒤 새 순서를 알립니다. Table.Row selected는 행의 스타일만 정하고 ARIA는 설정하지 않습니다.
직접 제공할 것: 표의 이름. Table.Caption이나 제목을 가리키는 aria-labelledby로 붙이세요. 위처럼 모든 머리글에 scope가 있는 Table.HeaderCell. 컨테이너보다 넓은 표라면, 키보드 사용자가 스크롤할 수 있도록 axis="inline", focusable, aria-label을 준 ScrollArea. 정렬 자체, 그리고 각 행의 체크박스에 어떤 행을 선택하는지 말하는 이름. 예를 들어 "Select Ada Lovelace"이고, 헤더의 체크박스에는 "Select all rows" 같은 이름입니다.
주의할 점: div로 그린 표. 보조 기술에는 행도 머리글도 없습니다. 머리글로 쓴 굵은 Table.Cell 셀. Table.Row에 onClick을 걸어 누를 수 있게 만든 행. 포커스를 받지 않으니 셀 안에 링크나 버튼을 넣으세요. 둘 이상의 열에 붙은 aria-sort. 정렬된 열에는 sort를 'ascending'이나 'descending'으로, 나머지에는 'none'으로 주세요. 헤더 셀 밖의 Table.SortButton. 글리프와 알림이 읽을 data-sort가 없습니다.
언제 쓰나요
쓸 때: 행과 열을 가로질러 비교하는 데이터. 데이터가 필요로 하면 열 정렬과 행 선택도 함께 씁니다. 검색, 일괄 작업, 페이지까지 함께 둘 때는 Data table 레시피에서 시작하세요.
쓰지 않을 때: 표 형식이 아닌 콘텐츠의 배치 → Stack이나 CSS grid. 열 크기 조절, 가상 스크롤, 셀 편집, 셀 사이의 화살표 키 이동 → Todae의 범위 밖인 데이터 그리드.
Props
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 먼저 Table.Caption, 그다음 행과 셀을 담은 Table.Head, Table.Body, Table.Foot. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 표에 담긴 내용. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 열 머리글을 담은 Table.Row 파트. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 데이터를 담은 Table.Row 파트. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 합계를 담은 Table.Row 파트. |
| 이름 | 타입 | 설명 |
|---|---|---|
selected | boolean | 행을 선택됨으로 표시합니다. data-selected와 table.row.bg.selected 토큰의 배경색을 설정합니다. ARIA는 설정하지 않으며, 상태는 행의 체크박스가 전합니다. |
children | React.ReactNode | Table.HeaderCell과 Table.Cell 파트. |
| 이름 | 타입 | 설명 |
|---|---|---|
scope | string | 어느 셀의 머리글인지: col, row, colgroup, rowgroup. Table.Head 안에서는 col, 본문 행의 첫 셀에는 row를 쓰세요. |
sort | "ascending" | "descending" | "none" | 열의 정렬 상태. data-sort를 설정하고, ascending과 descending이면 aria-sort도 설정합니다. none이면 aria-sort를 붙이지 않습니다. |
children | React.ReactNode | 머리글 텍스트. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 셀 내용. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 열 레이블. 버튼의 이름이 되며, 알림은 이 텍스트를, aria-label이 있으면 그것을 씁니다. |
onClick | (event: React.MouseEvent<HTMLButtonElement>) => void | 제품이 정렬하는 곳. 먼저 실행되며, preventDefault()를 호출하면 알림을 건너뜁니다. |