FUNSTACK UI

HomeWhyGetting startedConceptsComponentsRoadmap
GitHub

FUNSTACK UI is in beta. Part of the FUNSTACK family with FUNSTACK Router and FUNSTACK Static, which build this site.

Introduction

  • Why FUNSTACK UI
  • Overview
  • Getting started

Concepts

  • Action props
  • Pending & optimistic state
  • Transitions & ViewTransition
  • Suspense
  • Browser-owned state
  • Server Components

Guides

  • Replacing the element (render)
  • Direction and locales
  • Experimental features
  • Next.js App Router
  • React Router framework mode
  • Content Security Policy
  • Using with AI agents

Components

  • Buttons
    • Button
    • Toggle
    • ToggleGroup
    • Toolbar
  • Disclosure
    • Tabs
    • Accordion
    • Collapsible
    • NavigationMenu
  • Overlays
    • Tooltip
    • HoverCard
    • Popover
    • Dialog
    • AlertDialog
    • Drawer
    • Menu
    • Context menu (Menu)
    • Menubar (Menu)
    • Toast
  • Forms
    • Field and Form
    • Checkbox
    • CheckboxGroup
    • RadioGroup
    • Switch
    • Select
    • Combobox
    • MultiSelect
    • Slider
    • NumberField
    • OTPField
    • TextField
  • Output
    • Progress
    • Meter
    • Avatar
  • Layout
    • Separator
    • Scroll areas (recipe)

Resources

  • Roadmap & changelog
  • GitHub ↗

Transitions & ViewTransition

Every state change the library makes is a React transition. That is what lets React keep old content on screen, and it is also what lets <ViewTransition> animate the change.

Terms

Commit
The moment React applies a finished render to the DOM. One user interaction can lead to several commits: the synchronous one that shows the optimistic value, and the transition commit that ends the action.
View transition
The browser's View Transition API: it snapshots the page before and after a DOM change and animates between the two. React starts one for a transition commit when a <ViewTransition> boundary in the tree is affected.
Transition type
A string attached to a transition with React's addTransitionType. A <ViewTransition> can pick its animation by type, and CSS can match it with :active-view-transition-type().

The transition prop

Each part whose mount, unmount or content is driven by library state has a transition prop. When you pass it, the part renders a <ViewTransition> as the outermost node of its output; without it, the part renders no boundary at all. The value has exactly React's type: "auto", "none", a View Transition class, or a map from transition type to class. A string and a map do different things:

`transition`What animates
a class ("fade", "auto")this instance's own changes that the library dispatched (its open and close, its switch, its item opening, its action ending), and its own mount and unmount, whatever caused them, when the part is the top of what mounts or unmounts (Mount and unmount). Nothing else: not an unrelated transition, not another part of the same kind, not content that changes inside it
"none"nothing; the boundary stays, so you can switch to a class without a remount
a type mapReact's rules, unchanged: each entry animates every commit that carries its type, on every part that has the map and that the commit reaches (Type maps)

Under the hood the string is a type map keyed on an internal type that only this instance's dispatch adds. You never write that type, and its text is not API, but you may see it (fsui-i-…) in :active-view-transition-type() or in React's view transition events.

Treat transition as static. Changing it between undefined and a value remounts the part (development warns); switching between "none" and a class does not. Any value, "none" and a type map that does not match included, has a cost: when the part mounts or is revealed in a transition (a tab switch with keepMounted false or true, a part inside a dialog that opens), React starts a document view transition. The browser then cross-fades the whole page for 250 ms, and the next transition commit waits for it. A closed popup is the exception: it mounts in two steps and starts none (Closed popups).

Example: Tabs

Tabs.Panel takes transition, which animates the swap from one panel to the next. A class animates every switch of this Tabs; a type map picks a slide direction from the Tabs transition types (what else such a map names: Type maps):

<Tabs.Panel value="billing" transition="fade">...</Tabs.Panel>

<Tabs.Panel
  value="billing"
  transition={{ "fsui-tabs-next": "slide-left", "fsui-tabs-prev": "slide-right", default: "none" }}
>
  ...
</Tabs.Panel>
::view-transition-old(.slide-left) { animation: 160ms ease-in both slide-out-left; }
::view-transition-new(.slide-left) { animation: 160ms ease-out both slide-in-right; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

Every animation comes from your stylesheet, so reduced motion is yours to handle: when you write an animation (a view transition or plain CSS), add a prefers-reduced-motion rule like the one above.

If you want only your own named animations, you can opt out of the page cross-fade with the CSS below. It is optional and applies to every view transition on the page, including your router's. The last rule keeps clicks working, in Firefox, on content that is not animating (Input during a view transition).

::view-transition-old(root),
::view-transition-new(root) { animation: none; }
/* or: :root { view-transition-name: none; } */

::view-transition { pointer-events: none; }

Mount and unmount

"Its own mount and unmount" follows React's rule for enter and exit. In a transition commit, React plays a boundary's enter or exit only when the boundary is the top of the content that is inserted or removed: no DOM element of that content sits above it. Components that render no element of their own (a function component, a Fragment) do not count. So a part with a string animates its own mount and unmount when it is inserted or removed itself, and not when a DOM element around it is inserted or removed in the same commit. To animate that, put your own <ViewTransition> around the outermost element that is inserted or removed. Like any boundary, it starts a document view transition when it mounts in a transition (the cost above).

Closed popups mount in two steps

A popup is usually placed long before it opens: a row's AlertDialog in a table that a Suspense boundary reveals, a Popover on a page a navigation mounts, a nested Dialog in the content of another. If its Popup has transition, its boundary would be placed in that transition and start a document view transition with nothing visible to animate. So the Popup of a Dialog, AlertDialog, Drawer, Popover, HoverCard, Menu (a submenu's too), Combobox and MultiSelect that is closed when it mounts on the client renders nothing in its mount commit, and its element inside the boundary in a synchronous commit right after, before the browser paints. React starts no view transition for that commit. The element is created once; every open after that is an update and animates as usual.

What you can see: the Popup's ref is still null in the layout effects and mount effects (useEffect(…, [])) of the component that renders it, and document.getElementById finds no popup there. Read the ref when you use it (in an event handler), or use a callback ref, which is called with the element once it exists. Not affected: a Popup that is open when it mounts (its mount is its enter and animates), a hydrated Popup, a Popup without transition, and JS-free mode. Still affected: a mounted Popup that a Suspense boundary hides behind its fallback and reveals again, or that an <Activity> hides and reveals: that reveal starts a view transition, unless a DOM element around the popup is revealed with it.

Example: Button

A Button with transition="fade" whose action removes it. The removal must commit in the action's transition: close sets the state before any await, or wraps it in startTransition after one (After an await); an urgent removal plays nothing.

{/* The Button is the top of what is removed: its exit plays. */}
{open && <Button transition="fade" action={close}>Close issue</Button>}

{/* The <div> is the top of what is removed: nothing plays. */}
{open && (
  <div className="close-row">
    <Button transition="fade" action={close}>Close issue</Button>
  </div>
)}

{/* Your boundary is the top: the whole row fades out. */}
{open && (
  <ViewTransition exit="fade" default="none">
    <div className="close-row">
      <Button action={close}>Close issue</Button>
    </div>
  </ViewTransition>
)}

A controlled part changed by your own transition

A string answers only the library's own dispatches, so a change you make yourself, a controlled open or value set in your own startTransition (a keyboard shortcut, a route), does not update the part through it, even if you add a type. A part that mounts, unmounts or is revealed by the change still animates through the string, when it is the top of what changes (above): a Tabs.Panel with the default keepMounted on a controlled switch, a part you render conditionally. For an update (every Popup, an Accordion.Item, a Collapsible.Root), pass a map keyed on the public type of the change and name the cause in your transition with addTransitionType. The map also matches the library's own dispatches, which carry the same types:

<Dialog.Popup transition={{ "fsui-dialog-open": "fade", "fsui-dialog-close": "fade", default: "none" }} />

startTransition(() => {
  addTransitionType("fsui-dialog-open");
  setOpen(true);
});

Each component page lists its types in its Transition types section; they are public API for this. A type name of your own works too. A change with no transition to put a type in (a useDeferredValue render) needs a map with a default entry and its cost (below).

A controlled part changed by an urgent update

React starts a view transition only for a transition commit (What animates when). A controlled open or value that changes in an urgent update changes the trigger in a synchronous commit, which never animates, and the content region (a Panel, a Popup) in the deferred render that follows, and a pending action holds neither. That deferred commit carries no transition types, so a string transition does not animate it; a type map with a class on default does. (An uncontrolled part with no action prop also writes urgently, but it adds its types to its deferred commit, so it animates as in a transition: An uncontrolled component with no action prop.) Your own startTransition makes the update a transition only when the state lives in React. State read with useSyncExternalStore (a store outside React) stays urgent: React's documentation says that mutations to such a store cannot be marked as non-blocking transition updates. A router that keeps its state in such a store renders every navigation urgently, so a part controlled by the URL animates a change that comes from the router only through its deferred commit, which carries no reliable types.

Worked example: TanStack Router

TanStack Router (1.170, client-side rendering) reads its location, search params and matches through useSyncExternalStore. A Tabs controlled by a search param (Controlled by a router), with a type map on its Panels, behaves like this in Chromium and Firefox (measured with a router of the same shape: a useSyncExternalStore store that navigate writes, and a write outside any event for Back):

  • The Tab moves in a synchronous commit, and the Panel switches 20 to 60 ms later, in the deferred render that follows. That deferred commit starts a view transition around the switch.
  • Back and Forward: that view transition carries no types. A class on the map's default animates the switch; a map keyed only on fsui-tabs-next / -prev animates nothing (and the view transition still has every cost of Input during a view transition).
  • A click or an arrow key runs valueChangeAction, which calls navigate. The direction type may or may not reach the switch: with nothing else pending the view transition carried none, and while another action was pending it carried fsui-tabs-next. Do not rely on it.
  • A pending action elsewhere does not hold the Panel switch, in either case.
  • Wrapping navigate in your own startTransition changes none of this.

To animate the switch, mirror the search param into React state, let the Tabs read that state, and copy each new value into it in a transition that names the direction. Clicks, arrow keys, Back and Forward then all slide:

const order = ["overview", "comments", "activity"];
const { tab = "overview" } = route.useSearch();
const [shown, setShown] = useState(tab);
useEffect(() => {
  if (tab === shown) return;
  startTransition(() => {
    addTransitionType(order.indexOf(tab) > order.indexOf(shown) ? "fsui-tabs-next" : "fsui-tabs-prev");
    setShown(tab);
  });
}, [tab]);

<Tabs.Root value={shown} valueChangeAction={(next) => navigate({ search: { tab: next } })}>
  ...
  <Tabs.Panel value="comments" transition={{ "fsui-tabs-next": "slide-left", "fsui-tabs-prev": "slide-right", default: "none" }}>

The switch is then a transition like any other: a pending action holds it, and the Panel shows the old tab until it commits. Without the mirror, leave transition off Panels that the router controls: it buys a view transition per click and animates nothing useful.

The router's own viewTransition option (defaultViewTransition on the router, with types) calls document.startViewTransition around the navigation itself; the transition prop and the fsui-* types play no part in it. Together with a Panel that has transition, a click starts two view transitions, and in Chromium the Panel's one can skip the router's (measured once in two clicks). Do not combine them.

Moving the siblings: the Accordion recipe

Because a string names only its own instance, the items below an Accordion item that opens are not part of its animation: they cross-fade to their new place with the page's root cross-fade, or jump if you switched that off. To make them slide, name every Item with a map that uses "auto" (the browser's move and resize, no class of yours) and keep the string on the Panel, which animates only the item that changed:

const move = { "fsui-accordion-open": "auto", "fsui-accordion-close": "auto", default: "none" };

<Accordion.Item value="a" transition={move}>
  <Accordion.Trigger>Shipping</Accordion.Trigger>
  <Accordion.Panel transition="fade">...</Accordion.Panel>
</Accordion.Item>

Every Item is then named in every open and close of the Accordion: the ones that moved travel, the others show nothing, and all of them take no clicks while it runs.

Type maps

A map is passed to React as default unchanged, and React applies it to every part that has it and that the commit reaches. In react-dom 19.3 a commit reaches every boundary around something it changes, and every boundary that hangs off the changed path with no DOM element in between. So a Popup, a Collapsible.Root or a Button (their boundary is the top of the component) is reached by almost any commit near it, while a Tabs.Panel or an Accordion part (under the component's own element) is reached only by a change inside that element, or by one nested inside it:

  • A typed entry resolves in every commit that carries the type, on every reached part with the map, changed or not. React keeps the class on all of them once one of them changes size, so each plays it on two identical images: invisible for a fade, visible for a slide or a scale (the other items of one Accordion, a parent menu when its submenu opens, an outer Tabs around an inner one). Use a class with motion in a map only where no other commit of its kind reaches the part, or use "auto".
  • A default entry resolves in every other transition commit on the page, a useDeferredValue render and a Suspense retry included. { default: "fade" } on a mounted part, even a closed popup, turns every transition anywhere into a view transition of 250 ms or more, with the input costs below.
  • A map without a default entry falls back to React's "auto", which has the same cost. So a map ends with default: "none", and so does the map of your own <ViewTransition> around content inside a part.

Transition types

Each dispatch adds fsui-<component> and, where the change has a direction or kind, fsui-<component>-<change> through addTransitionType. They are public API: key your type maps on them, add them yourself for a controlled change, and match them in CSS. The types of the parts that take transition:

PartTypes of the change
Dialog.Popup, AlertDialog.Popupfsui-dialog-open, fsui-dialog-close
Drawer.Popupfsui-drawer-open, fsui-drawer-close
Popover.Popupfsui-popover-open, fsui-popover-close
HoverCard.Popupfsui-hover-card-open, fsui-hover-card-close
Menu.Popupfsui-menu-open, fsui-menu-close (a submenu's too: a map on a parent menu plays when its submenu opens; the string does not)
Combobox.Popupfsui-combobox-open, fsui-combobox-close (never fsui-combobox: every value dispatch carries it)
MultiSelect.Popupfsui-multi-select-open, fsui-multi-select-close
NavigationMenu.Popupfsui-navigation-menu-open, fsui-navigation-menu-close
Tabs.Panelfsui-tabs, fsui-tabs-next, fsui-tabs-prev (DOM order of the new tab relative to the committed one)
Accordion.Item, Accordion.Panelfsui-accordion-open, fsui-accordion-close
Collapsible.Root, Collapsible.Panelfsui-collapsible-open, fsui-collapsible-close
Buttonfsui-button (each action run)

Every component page lists its own types, or says that it has none, in its Transition types section. Components whose state never changes in a transition add none: their commits are urgent, or their state belongs to the browser.

Match them in CSS with :active-view-transition-type(fsui-tabs-next). Types you add yourself with addTransitionType in the synchronous part of an action join the same transition.

Types are attached only to the commit that ends a dispatched action. A rollback after a rejection, or a controlled parent snapping the value back, carries no fsui-* type: neither animates with a string, and a type map needs a default entry (with its cost) if rollbacks should animate.

Input during a view transition

A view transition costs more than its animation. Measured in Chromium and Firefox with react-dom 19.3:

  1. An element that is animating takes no pointer input, in every engine, whatever your CSS. It is painted as a snapshot for the length of the transition and is not hit-tested, nor is anything inside it: a click there lands on the pseudo-element, or with ::view-transition { pointer-events: none } on whatever lies behind it. This also holds for an element you named in CSS (.main { view-transition-name: main }): the browser captures it in every view transition on the page, React's included, so the whole region ignores clicks and drags each time. Do not put a view-transition-name on a region that holds controls.
  2. Content that is not animating gets clicks in Chromium. In Firefox the transition's overlay covers the viewport and a click is lost, not delayed; ::view-transition { pointer-events: none } restores it. That rule is needed for Firefox and does nothing for point 1.
  3. Every event in the frame in which React starts a view transition is lost. React switches its event handling off while it prepares a view transition and back on in the transition's update callback, about one frame later. An event the browser delivers in between calls no handler, yours or the library's, and is not replayed: a click is lost (Firefox delivers clicks there often; Chromium rarely), and a character typed then never reaches onChange, so the commit writes the old value back into a controlled input. Nothing in CSS prevents it, and a view transition in which nothing animates has the same window: do not start view transitions while the user acts (a string transition on a Combobox popup starts none after the open; a closed popup starts none when it mounts, Closed popups).
  4. While a view transition runs, every later transition commit waits for it.

So the mitigation is fewer and shorter view transitions: strings on the library's parts, maps that end with default: "none", no CSS view-transition-name on regions with controls, and short animations.

Background updates while the user types

The lost input (point 3) applies to every view transition, including one the user did not cause. React starts a document view transition for a transition commit when a boundary (your own <ViewTransition> or a part with transition):

  • mounts, or is revealed by <Activity>, at the top of the inserted content (Mount and unmount), whatever its classes resolve to, "none" included (a closed popup excepted: Closed popups);
  • is reached by the commit or unmounts, when its class for that commit is not "none" (Type maps).

Moving content to another parent (a card that a save moves to another column, a row re-sorted into another group) is an unmount and a mount, so a boundary at the top of the moved content starts one even when every class is "none". When a background completion commits such a change in a transition (a save that finishes, a refetch, a Suspense retry) while the user types in a text field elsewhere, for example in a modal dialog, the character typed in that frame is lost. Two ways to avoid it:

  • Commit the result of a background task the user is not waiting for as an urgent update: a setState outside startTransition. An urgent commit starts no view transition. The change does not animate, and if it suspends, the nearest Suspense fallback replaces the content. A data store read through useSyncExternalStore already commits this way (above), so its results start none.
  • While the dialog is open, render the content that background updates insert or move without boundaries at its top: neither your own <ViewTransition> nor a part with transition. Key this on the dialog's open state, the one you pass to its Root, not on focus events: closing a <dialog> in Firefox fires no focusout, so a switch keyed on focus happens late, on a later click, and its remount can close the menu that click opened. Adding or removing a boundary remounts the content under it (DOM and state are lost), in the commit that opens the dialog and again in the one that closes it. So keep the dialog's Trigger, and the element that has focus when it opens, outside that content; otherwise the dialog returns focus to a removed element and focus ends on <body>. Open the dialog in an urgent update (Open your own controlled overlay urgently): in a transition, a pending action would hold the open, and removing a boundary that has an exit class would play that exit over the whole region.

Upgrading: what a string no longer animates

Up to 0.1.0-beta.3 a string transition was passed to React as default, so it answered every transition commit that reached the part. It now answers this instance's own dispatches and its own mount and unmount only. Type maps behave exactly as before. With a string, these no longer animate:

  • A controlled change you make in your own transition that updates the part (a shortcut opening a dialog), with or without addTransitionType: use a map keyed on the public type plus addTransitionType (recipe). A part that mounts or is revealed by the change still animates.
  • Content that changes inside a shown part in a transition of its own: a content swap in an open Dialog or Popover, a Suspense reveal, Combobox results, a useDeferredValue render, a control inside an Accordion or Tabs panel. Wrap that content in your own <ViewTransition>, or use a map with a default entry and its cost.
  • Other parts of the same kind when one changes: the other items of an Accordion (they no longer slide; recipe), a parent Menu.Popup when its submenu opens, an outer Tabs or Accordion around a nested one.
  • A Button whose content changes for any reason other than the end of its own action (a parent's transition changing its label).
  • A rollback or a controlled snap-back: it carries no type. Use a map with a default entry if it should animate.

In return, a mounted part with a string (a closed command palette in the app shell) no longer turns every transition on the page into a view transition.

What animates when

React starts a view transition only for commits made entirely of transition lanes (a lane is React's priority class for an update; transitions have their own). The optimistic flip is a synchronous commit, so it never animates through <ViewTransition>. What to animate with depends on which value the part renders (see the three values):

The part rendersAnimate with
optimistic state only (a trigger, a value control): no transition propa CSS transition on the data attribute
committed state (a content region)the transition prop
the end of pending, or a rollbackthe end of pending: the transition prop of the part around it when that part's own dispatch ends; a rollback (no type): a type map with a default entry, or your own <ViewTransition>
browser-owned stateCSS: @starting-style, transition-behavior: allow-discrete

Example: Tabs

Tabs.Tab renders the optimistic selection: animate its colour with a CSS transition on [data-selected]. Tabs.Indicator follows the optimistic tab with CSS Anchor Positioning, so a plain CSS transition on its inset properties makes it slide on click and slide back on rollback. Tabs.Panel renders the committed selection: animate the swap with its transition prop. A Tab has no transition prop: a spinner rendered from its pending state disappears in the commit that ends the action, which your own <ViewTransition> around the Tab's content can animate.

A popup with a CSS exit and a view transition

A popup in the top layer can close two ways. A close the library performs (a part's close, a controlled open={false}) happens in a commit, so the popup's transition prop can animate it with a view transition in every engine (a controlled close with a map and the type, above). A dismissal happens in the browser before React hears about it, so only a CSS exit (@starting-style, transition-behavior: allow-discrete) can animate it; it is a fact, reported to onOpenChange in an urgent commit, which starts no view transition at all. Write both: the transition prop animates what the library does, CSS animates what the browser does, and the library's own show or hide never runs a CSS transition.

While a view transition runs, the library turns off the popup's CSS transitions for the moment of its own show or hide. Otherwise Chromium would keep a popup the library hides rendering through its CSS fade and capture it in the close's new snapshot as well as the old one (a double image), and the CSS enter would run under the view transition's enter. To do this, the library writes an inline transition: none !important on the popup for the length of that one call and then puts your inline transition back. A dismissal is never cut, so its CSS fade runs even when another view transition of the page starts during it (a dismissal while the library's own view transition runs fades inside that transition's new image). Only CSS transitions are cut: an exit written as a @keyframes animation on the closed state still runs during a library close, and Chromium captures it twice. Write the exit as a transition.

Example: Dialog

A Dialog with a CSS fade for Escape and a click outside, and a view transition for its Close parts:

<Dialog.Popup className="dialog" transition={{ "fsui-dialog-open": "pop", "fsui-dialog-close": "pop", default: "none" }}>
.dialog { opacity: 0; transition: opacity 150ms, display 150ms allow-discrete, overlay 150ms allow-discrete; }
.dialog:open { opacity: 1; }
@starting-style { .dialog:open { opacity: 0; } }
::view-transition-new(.pop) { animation: 180ms ease-out both pop-in; }
::view-transition-old(.pop) { animation: 140ms ease-in both pop-out; }

Rules the library follows for you

  • It never calls document.startViewTransition.
  • Only one place can make React skip one of your view transitions with flushSync: Enter on a closed Combobox. The value the form submits is committed with flushSync there, because the submission reads it in the same task, so a view transition that started in the frame before that key is skipped. The other writes that must reach the next paint (a popup's resolved data-side, a Field's error state after an edit) render in React's sync lane without flushSync, or skip flushSync while a view transition runs.
  • <ViewTransition> renders no DOM and is safe in server-rendered trees; hydration is not a transition, so nothing animates on first paint.
  • Content regions kept mounted while hidden (Tabs keepMounted) switch their <Activity> mode inside the library's transition, so nested <ViewTransition> boundaries get enter and exit animations.