Every component that owns state keeps three values for it. Knowing which part of the component shows which value is the key to styling FUNSTACK UI.
These words are used throughout the documentation. A part is one element-rendering piece of a component, such as Tabs.Tab.
Root; a single-element component (a Toggle, a Switch) owns its own state.Trigger; the concept is wider than that name.Panel.useDeferredValue, so new content that suspends keeps the old content on screen whether the change was a transition or an urgent write.useOptimistic over the committed value, set at the start of the action.useFormStatus) instead.Triggers render the optimistic value, so the user sees their click land at once. Content regions render the committed value. This rule follows from how React works, not from taste. An optimistic update renders synchronously, and a synchronous render that suspends shows the nearest Suspense fallback. If a content region followed the optimistic value, choosing content that loads data would flash a fallback. Because content regions follow the committed value, the old content stays on screen while the new one loads, the trigger already shows the new choice, and the state owner and the trigger are marked pending. When the data is ready, the content swaps in one commit.
Example: Tabs
In Tabs, Tabs.Tab and Tabs.Indicator are triggers and show the optimistic selection (aria-selected, data-selected); Tabs.Panel is the content region and shows the committed selection; Tabs.Root is the state owner. In the tabs below, switching waits for an 800 ms save. The indicator and the tab colour move at once (optimistic); the panel changes when the save resolves (committed). Every third save fails and everything rolls back.
The profile settings.
"use client";
import { Tabs } from "@funstack/ui/tabs";
import { DemoErrorBoundary } from "./DemoErrorBoundary.js";
import { fakeSave } from "./fake-api.js";
let saves = 0;
// Manual activation with an awaited save: arrow keys only move focus, Enter / Space / click
// select. The panel switches when the save resolves; every third save rejects, the selection
// rolls back and the error reaches the Error Boundary. Panels slide by DOM direction through
// the library's fsui-tabs-next / fsui-tabs-prev transition types.
export function TabsSaved() {
return (
<DemoErrorBoundary>
<Tabs.Root
className="demo-tabs"
defaultValue="profile"
activationMode="manual"
valueChangeAction={async (next) => {
await fakeSave(`tab "${next}"`, { fail: ++saves % 3 === 0 });
}}
>
<Tabs.List className="demo-tabs-list" aria-label="Account settings">
<Tabs.Tab value="profile" className="demo-tab">
Profile
</Tabs.Tab>
<Tabs.Tab value="billing" className="demo-tab">
Billing
</Tabs.Tab>
<Tabs.Tab value="danger" className="demo-tab" disabled>
Danger zone
</Tabs.Tab>
<Tabs.Tab value="team" className="demo-tab">
Team
</Tabs.Tab>
<Tabs.Indicator className="demo-tabs-indicator" />
</Tabs.List>
{["profile", "billing", "danger", "team"].map((value) => (
<Tabs.Panel
key={value}
value={value}
className="demo-tab-panel"
transition={{
"fsui-tabs-next": "demo-slide-next",
"fsui-tabs-prev": "demo-slide-prev",
default: "none",
}}
>
<p>The {value} settings.</p>
</Tabs.Panel>
))}
</Tabs.Root>
</DemoErrorBoundary>
);
}/* Tabs: optimistic selection on tabs and the indicator, committed selection on panels. */
.demo-tabs-list {
/* The Indicator is absolutely positioned against the Tabs (its anchors) inside the list. */
position: relative;
display: flex;
gap: 4px;
border-bottom: 1px solid var(--color-border);
}
.demo-tab {
display: inline-flex;
align-items: center;
gap: 0.4em;
padding: 0.5em 0.9em;
border: none;
background: none;
color: var(--color-text-secondary);
font: inherit;
cursor: pointer;
transition: color 120ms;
}
.demo-tab[data-selected] {
color: var(--color-primary);
}
.demo-tab[data-pending] {
cursor: progress;
}
.demo-tab[aria-disabled="true"] {
opacity: 0.4;
cursor: not-allowed;
}
.demo-tab:focus-visible {
outline: 2px solid var(--color-primary);
outline-offset: -2px;
}
/* CSS Anchor Positioning places the indicator under the optimistic tab; a CSS transition
slides it. */
.demo-tabs-indicator {
position: absolute;
bottom: -1px;
left: anchor(left);
width: anchor-size(width);
height: 3px;
border-radius: 2px;
background: var(--color-primary);
transition:
left 200ms ease-out,
width 200ms ease-out;
}
.demo-tab-panel {
padding: 12px 4px 0;
}
.demo-tab-panel :is(p, ul) {
margin: 0 0 12px;
}
/* The old panel stays while the next one loads; dim it after a short delay. */
.demo-tabs[data-pending] .demo-tab-panel {
opacity: 0.5;
transition: opacity 150ms 150ms;
}
/* ViewTransition classes used by the `transition` prop on Tabs.Panel. */
::view-transition-old(.demo-slide-next) {
animation: 180ms ease-in both demo-out-left;
}
::view-transition-new(.demo-slide-next) {
animation: 180ms ease-out both demo-in-right;
}
::view-transition-old(.demo-slide-prev) {
animation: 180ms ease-in both demo-out-right;
}
::view-transition-new(.demo-slide-prev) {
animation: 180ms ease-out both demo-in-left;
}
@keyframes demo-out-left {
to {
opacity: 0;
translate: -2rem 0;
}
}
@keyframes demo-in-right {
from {
opacity: 0;
translate: 2rem 0;
}
}
@keyframes demo-out-right {
to {
opacity: 0;
translate: 2rem 0;
}
}
@keyframes demo-in-left {
from {
opacity: 0;
translate: -2rem 0;
}
}
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation: none !important;
}
.demo-tabs-indicator,
.demo-tab {
transition: none;
}
}Two consequences for triggers:
children function) must not suspend, or must have its own Suspense boundary.transition on the data attribute (see What animates when).Each component page lists which of its parts show which value in its Optimistic and pending section and its data attributes table.
data-pending landsDialog.Close, Popover.Close, Drawer.Close, an AlertDialog Cancel or Action, a closing Menu.Item): from the click until that close has committed, with or without an action of its own. The Trigger may be out of sight under a modal backdrop. Without an action the part is never aria-disabled: nothing of its own is ignored.on* handler and is not awaited, so nothing is pending for it: the popup, data-open and the committed state all change at once (Requests and facts).The same names exist in the function props (className, style, children as a function of state): state.pending, and the state's own name such as state.pressed, state.selected or state.open.
Example: Tabs
data-pending is on Tabs.Root and on the Tabs.Tab that is the optimistic selection; Tabs.Indicator mirrors the Root. The panels never get it, so the CSS selects through the Root:
.tabs[data-pending] .panel { opacity: 0.6; transition: opacity 150ms 150ms; }
.tab[data-pending]::after { content: ""; /* spinner */ }<Tabs.Tab value="billing">
{({ pending }) => <>Billing{pending && <Spinner />}</>}
</Tabs.Tab>A trigger that changes state takes every click: a second click on a pending trigger is a new intent, the optimistic value follows it, and the latest intent wins (see Overlapping actions). A pure trigger has no value to protect, so what a second click, Enter or Space does while its own action is pending is its whilePending prop:
"run": the activation runs the action again, in the same transition. The part shows data-pending until every run has settled, and is not aria-disabled: it still acts."ignore": the activation starts nothing and its default action (a link's navigation, a form submission, a command) is cancelled. The part renders aria-disabled="true" for as long as it shows data-pending, so a screen-reader user who presses again hears that it is unavailable.The default follows who owns the action. Where the action is yours alone (a Button), every click runs, as with React's own useTransition: only you know whether two overlapping runs are a bug (Save) or the point (a counter). Where the library acts after your action (a Dialog.Close or Popover.Close closes its overlay, a Menu.Item closes its menu, a Toast.Action closes its toast), a second activation is ignored: the first one already ends in that close. Switch the library's close off (closeOnActivate={false}) and the item or action becomes yours, so it runs every activation again. Either way the prop overrides the default, and no part is ever natively disabled, so focus stays where it is. A closing part in "run" mode closes once, when its last run has settled, and only if the latest run resolved: a rejection leaves the overlay, menu or toast open, as it does in "ignore" mode.
Example: Button
A counter wants every click; a Save must not run twice. Opt the Save in to "ignore":
<Button action={async () => { await incrementOnServer(); }}>+1</Button> // every click runs
<Button action={save} whilePending="ignore">Save</Button> // one save at a timeIn "run" mode the runs overlap, and their errors follow the usual rule: the latest run's rejection reaches the Error Boundary, an older run's goes to reportError. For runs that must happen one after another, each seeing the previous result, use useActionState and call its dispatch from the action.
If the action rejects, or a controlled parent does not adopt the new value, the optimistic value falls back to the committed one when the transition ends. Nothing has to be undone by hand: uncontrolled state is only written after success.
ARIA state on a trigger (aria-pressed, aria-selected, a native input's checked state) follows the optimistic value, so screen reader users get the same immediate feedback as sighted users. Where HTML gives the state to a native element that cannot carry the ARIA attribute, assistive technology hears the committed state and the optimistic data attribute is visual only; the component page says so when that applies (for example Accordion). The same holds for the trigger of a popup and for the Combobox input: assistive technology hears whether the popup is shown, and data-open is the optimistic state (see Triggers of a popup).
A trigger whose label depends on pending changes its accessible name while the action runs. A query by role and name then stops matching halfway through the test: the button named "Close" is named "Closing…" while it is pending, so an assertion on its data-pending waits for an element the query no longer finds. Playwright locators run their query again on every use, so they hit this every time. A Testing Library query returns the element itself, so an element you queried before the click stays usable.
Two ways to keep the name stable:
aria-hidden spinner while pending.aria-label that does not change, and match that name in the test.For example, the second way on a Popover's Close button, tested with Playwright:
// The name stays "Close" while the label reads "Closing…".
<Popover.Close aria-label="Close" action={save}>
{({ pending }) => (pending ? "Closing…" : "Close")}
</Popover.Close>
const close = page.getByRole("button", { name: "Close", exact: true });
await close.click();
await expect(close).toHaveAttribute("data-pending");