Stack
gap picks one of four steps. condensed, normal and spacious come from the stack.gap-condensed, stack.gap and stack.gap-spacious tokens, so they follow the density; none is no space. The default is normal.
On this page
Server Components can import it from @tounsoo/todae/stack. That entry has no 'use client' and no hooks; the main @tounsoo/todae entry is a client module.
import { Button, Stack, Text } from '@tounsoo/todae';
export default function StackButtons() {
return (
<Stack.Root>
<Text.Root>Stacked label</Text.Root>
<Button.Root>Primary</Button.Root>
<Button.Root variant="secondary">Secondary</Button.Root>
</Stack.Root>
);
}
Stacked label
Gap
import { Badge, Stack, Text } from '@tounsoo/todae';
export default function StackGaps() {
return (
<Stack.Root gap="spacious">
{(['none', 'condensed', 'normal', 'spacious'] as const).map((gap) => (
<Stack.Root key={gap} gap="condensed">
<Text.Root>{gap}</Text.Root>
<Stack.Root direction="row" gap={gap}>
<Badge.Root>One</Badge.Root>
<Badge.Root>Two</Badge.Root>
<Badge.Root>Three</Badge.Root>
</Stack.Root>
</Stack.Root>
))}
</Stack.Root>
);
}
none
condensed
normal
spacious
Alignment and wrapping
align sets the cross axis and justify the main axis; between pushes the first and last items to the edges. wrap lets items run onto more lines when the row is full.
import { Badge, Stack, Text } from '@tounsoo/todae';
export default function StackSpread() {
return (
<Stack.Root direction="row" justify="between" align="center" wrap style={{ inlineSize: '100%' }}>
<Text.Root weight="bold">Billing</Text.Root>
<Stack.Root as="ul" direction="row" gap="condensed" aria-label="Plan features">
<li>
<Badge.Root>Monthly</Badge.Root>
</li>
<li>
<Badge.Root>Invoices</Badge.Root>
</li>
</Stack.Root>
</Stack.Root>
);
}
Billing
- Monthly
- Invoices
Accessible composition
Todae handles: Layout only. Stack.Root renders a div with no role unless as picks another element. As a ul or ol it drops the bullets and indent and sets role="list", since Safari drops list semantics from a list without bullets otherwise. direction is row or column, never reversed, and justify and align only move items within that order, so items show in DOM order and reading and Tab order follow what is drawn. Every other prop, ref, role and aria-* included, reaches the element; a role you pass replaces the list role.
You supply: The semantics. Buttons that act on one thing and need a shared name take role="group" and aria-label; Button.Group sets role="group" itself. A row of tools that should be one Tab stop moved through with arrow keys is a Toolbar, not a Stack.Root. Items that form a list go in as="ul" or as="ol", each child an li. A nav is a navigation landmark: give each one an aria-label when a page has more than one. A section becomes a region landmark only when it has a name.
Watch for: row-reverse, column-reverse or order set through className or style: items move on screen but not in reading or Tab order. To show a primary button last, put it last in the DOM.
When to use
When: A flex row or column spaced by one of the gap steps. Spacing between fields or buttons, a list of links, a header row with items at both ends.
When not: Label-to-control gap → Field.Group (field.label.gap). A gap that is not one of the steps → your own CSS. Attached button row → Button.Group.
Props
| Name | Type | Description |
|---|---|---|
direction | "row" | "column" | Flex direction. Default: "column" |
gap | "none"| "condensed"| "normal"| "spacious" | Space between items. `condensed`, `normal` and `spacious` follow the density; `none` is no space. Default: "normal" |
wrap | boolean | Lets items wrap onto more lines. Default: false |
align | "start"| "center"| "end"| "baseline"| "stretch" | Cross-axis alignment. Omitted, items stretch. |
justify | "start" | "center" | "end" | "between" | Main-axis distribution. Omitted, items pack at the start. |
as | "div"| "ul"| "ol"| "nav"| "section"| "header"| "footer" | The element to render. A `ul` or `ol` loses its bullets and indent and keeps `role="list"`. Default: "div" |
children | React.ReactNode | Laid-out children. |