The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Document controlled and uncontrolled UI state (#26062)
Raphaël Bosi0de4040d62ab
diff --git a/packages/twenty-docs/ui/primitives/input/checkbox.mdx b/packages/twenty-docs/ui/primitives/input/checkbox.mdxindex 173dda45ece..8cfb65e1b51 100644--- a/packages/twenty-docs/ui/primitives/input/checkbox.mdx+++ b/packages/twenty-docs/ui/primitives/input/checkbox.mdx@@ -17,6 +17,8 @@ Use `Checkbox` when each option can be selected independently. For a mutually ex## Uncontrolled state+Use `defaultChecked` to set the initial checked state. The checkbox owns subsequent changes.+```tsximport { Checkbox } from 'twenty-ui/primitives/input';@@ -30,7 +32,34 @@ export const EmailPreference = () => (A checked, named checkbox contributes its value to a form. Set `uncheckedValue` if the form should also submit a value when it is unchecked.-## Controlled and indeterminate states+## Controlled state++Pass `checked` and update it with `onCheckedChange` to own the same preference in React state. The callback receives the next boolean and event details.++```tsx+import { useState } from 'react';+import { Checkbox } from 'twenty-ui/primitives/input';++export const EmailPreference = () => {+ const [checked, setChecked] = useState(true);++ return (+ <label>+ <Checkbox+ name="updates"+ value="email"+ checked={checked}+ onCheckedChange={setChecked}+ />+ Receive product updates+ </label>+ );+};+```++## Indeterminate state++An indeterminate checkbox represents a partial selection. Derive it from the child options independently of the checkbox's checked state.```tsximport { useState } from 'react';@@ -67,8 +96,6 @@ export const ColumnSelection = () => {};```-The indeterminate state represents a partial selection; the application derives it from the child options. `onCheckedChange` receives the next boolean and event details.-## Appearance and interaction| Prop | Values | Default |diff --git a/packages/twenty-docs/ui/primitives/input/input.mdx b/packages/twenty-docs/ui/primitives/input/input.mdxindex 18933f92bc9..df4952a154e 100644--- a/packages/twenty-docs/ui/primitives/input/input.mdx+++ b/packages/twenty-docs/ui/primitives/input/input.mdx@@ -15,7 +15,9 @@ import InputReference from '/snippets/ui/generated/input/input.mdx';height={240}/>-## Label an input+## Uncontrolled state++Use `defaultValue` to set the initial email address. The input owns subsequent changes.```tsximport { Field, Input } from 'twenty-ui/primitives/input';@@ -23,29 +25,40 @@ import { Field, Input } from 'twenty-ui/primitives/input';export const EmailField = () => (<Field.Root><Field.Label>Email</Field.Label>- <Input name="email" type="email" autoComplete="email" />+ <Input+ name="email"+ type="email"+ autoComplete="email"+ defaultValue="[email protected]"+ /><Field.Description>Use your work email address.</Field.Description></Field.Root>);```-## Control the value+## Controlled state-`onValueChange` receives the next string value and event details. For an uncontrolled input, use `defaultValue` instead of `value`.+Pass `value` and update it with `onValueChange` to own the same email address in React state. The callback receives the next string value and event details.```tsximport { useState } from 'react';-import { Input } from 'twenty-ui/primitives/input';+import { Field, Input } from 'twenty-ui/primitives/input';-export const SearchField = () => {- const [query, setQuery] = useState('');+export const EmailField = () => {+ const [email, setEmail] = useState('[email protected]');return (- <Input- aria-label="Search contacts"- value={query}- onValueChange={setQuery}- />+ <Field.Root>+ <Field.Label>Email</Field.Label>+ <Input+ name="email"+ type="email"+ autoComplete="email"+ value={email}+ onValueChange={setEmail}+ />+ <Field.Description>Use your work email address.</Field.Description>+ </Field.Root>);};```diff --git a/packages/twenty-docs/ui/primitives/input/radio-group.mdx b/packages/twenty-docs/ui/primitives/input/radio-group.mdxindex 19cfd5638ab..904ca1f1e70 100644--- a/packages/twenty-docs/ui/primitives/input/radio-group.mdx+++ b/packages/twenty-docs/ui/primitives/input/radio-group.mdx@@ -15,7 +15,9 @@ import RadioGroupReference from '/snippets/ui/generated/input/radio-group.mdx';height={240}/>-## Default selection+## Uncontrolled state++Use `defaultValue` to set the initial billing frequency. The group owns subsequent changes.```tsximport { useId } from 'react';@@ -46,32 +48,39 @@ export const BillingFrequency = () => {};```-Use `defaultValue` for an uncontrolled group. Its `name` identifies the selected value in form submission. Give the group an accessible name as well as labeling each radio.+The group's `name` identifies the selected value in form submission. Give the group an accessible name as well as labeling each radio.## Controlled state+Pass `value` and update it with `onValueChange` to own the same billing frequency in React state. Selection belongs to the group, not to individual radio controls.+```tsx-import { useState } from 'react';+import { useId, useState } from 'react';import { Radio, RadioGroup } from 'twenty-ui/primitives/input';-export const DisplayDensity = () => {- const [density, setDensity] = useState('comfortable');+export const BillingFrequency = () => {+ const labelId = useId();+ const [billingFrequency, setBillingFrequency] = useState('monthly');return (- <RadioGroup- value={density}- onValueChange={setDensity}- aria-label="Display density"- >- <label>- <Radio value="compact" />- Compact- </label>- <label>- <Radio value="comfortable" />- Comfortable- </label>- </RadioGroup>+ <fieldset>+ <legend id={labelId}>Billing frequency</legend>+ <RadioGroup+ name="billingFrequency"+ value={billingFrequency}+ onValueChange={setBillingFrequency}+ aria-labelledby={labelId}+ >+ <label>+ <Radio value="monthly" />+ Monthly+ </label>+ <label>+ <Radio value="yearly" />+ Yearly+ </label>+ </RadioGroup>+ </fieldset>);};```diff --git a/packages/twenty-docs/ui/primitives/input/radio.mdx b/packages/twenty-docs/ui/primitives/input/radio.mdxindex 02a84bd0813..6eb20cfd92e 100644--- a/packages/twenty-docs/ui/primitives/input/radio.mdx+++ b/packages/twenty-docs/ui/primitives/input/radio.mdx@@ -46,7 +46,7 @@ The `size` prop accepts `sm` or `md` and defaults to `sm`. Use the same size for## Keyboard and selection-Tab enters or leaves the group. Arrow keys move between enabled options and select the focused option. Space selects the focused radio. Selection and change handlers belong on `RadioGroup`; see its [controlled example](/ui/primitives/input/radio-group#controlled-state).+Tab enters or leaves the group. Arrow keys move between enabled options and select the focused option. Space selects the focused radio. Selection and change handlers belong on `RadioGroup`; see its [uncontrolled example](/ui/primitives/input/radio-group#uncontrolled-state) and [controlled example](/ui/primitives/input/radio-group#controlled-state).`Radio` is generic over the value type. Keep that type consistent with its group. Native attributes such as `aria-describedby` can associate an option with additional help text.diff --git a/packages/twenty-docs/ui/primitives/input/select.mdx b/packages/twenty-docs/ui/primitives/input/select.mdxindex 76a1a98ef77..cc23a912fca 100644--- a/packages/twenty-docs/ui/primitives/input/select.mdx+++ b/packages/twenty-docs/ui/primitives/input/select.mdx@@ -15,7 +15,9 @@ Use `Select` for a form value chosen from a list. Use [Menu](/ui/primitives/surfheight={400}/>-## Single selection+## Uncontrolled state++Use `defaultValue` to set the initial priority. The select owns subsequent selection changes.```tsximport { Select } from 'twenty-ui/primitives/input';@@ -42,7 +44,46 @@ export const PrioritySelect = () => ();```-Supply `items` on `Root` so `Value` renders the selected item's label; without it, the trigger shows the raw value. `defaultValue` initializes uncontrolled state; use `value` and `onValueChange` for controlled state. The selected value can be `null` when nothing is selected.+Supply `items` on `Root` so `Value` renders the selected item's label; without it, the trigger shows the raw value. The selected value can be `null` when nothing is selected.++## Controlled state++Pass `value` and update it with `onValueChange` to own the same priority in React state. The callback receives the next value and event details.++```tsx+import { useState } from 'react';+import { Select } from 'twenty-ui/primitives/input';++const PRIORITIES = [+ { value: 'low', label: 'Low' },+ { value: 'normal', label: 'Normal' },+ { value: 'high', label: 'High' },+];++export const PrioritySelect = () => {+ const [priority, setPriority] = useState<string | null>('normal');++ return (+ <Select.Root+ name="priority"+ value={priority}+ onValueChange={setPriority}+ items={PRIORITIES}+ >+ <Select.Trigger aria-label="Priority">+ <Select.Value placeholder="Choose a priority" />+ </Select.Trigger>+ <Select.Popup>+ {PRIORITIES.map(({ value, label }) => (+ <Select.Item key={value} value={value}>+ {label}+ </Select.Item>+ ))}+ </Select.Popup>+ </Select.Root>+ );+};+```## Multiple selection@@ -81,7 +122,49 @@ export const LanguageSelect = () => {};```-With `multiple`, the value is an array. The generic root types represent the option value and whether multiple selection is enabled.+With `multiple`, the value is an array. Use `defaultValue={['en']}` instead of `value` and `onValueChange` for an uncontrolled multiple selection. The generic root types represent the option value and whether multiple selection is enabled.++## Open state++Selection and popup visibility are independent. The examples above leave popup visibility uncontrolled. Selecting a single value closes the popup; multiple selection keeps it open. Use `defaultOpen` to set its initial visibility; it defaults to `false`.++Pass `open` and update it with `onOpenChange` to control visibility. This example controls the popup while leaving the selected priority uncontrolled.++```tsx+import { useState } from 'react';+import { Select } from 'twenty-ui/primitives/input';++const PRIORITIES = [+ { value: 'low', label: 'Low' },+ { value: 'normal', label: 'Normal' },+ { value: 'high', label: 'High' },+];++export const PrioritySelect = () => {+ const [open, setOpen] = useState(false);++ return (+ <Select.Root+ name="priority"+ defaultValue="normal"+ items={PRIORITIES}+ open={open}+ onOpenChange={setOpen}+ >+ <Select.Trigger aria-label="Priority">+ <Select.Value placeholder="Choose a priority" />+ </Select.Trigger>+ <Select.Popup>+ {PRIORITIES.map(({ value, label }) => (+ <Select.Item key={value} value={value}>+ {label}+ </Select.Item>+ ))}+ </Select.Popup>+ </Select.Root>+ );+};+```## Parts and placementdiff --git a/packages/twenty-docs/ui/primitives/input/slider.mdx b/packages/twenty-docs/ui/primitives/input/slider.mdxindex 52d8bd3a801..3bcb5c0aeaf 100644--- a/packages/twenty-docs/ui/primitives/input/slider.mdx+++ b/packages/twenty-docs/ui/primitives/input/slider.mdx@@ -15,7 +15,9 @@ import SliderReference from '/snippets/ui/generated/input/slider.mdx';height={240}/>-## Single value+## Uncontrolled state++Use `defaultValue` to set the initial volume. The slider owns subsequent changes.```tsximport { Slider } from 'twenty-ui/primitives/input';@@ -34,7 +36,40 @@ export const VolumeSlider = () => ();```-Use `value` and `onValueChange` for controlled state. `onValueCommitted` handles the value when an interaction finishes. Set `color="success"` for the alternative palette; the default is `accent`.+## Controlled state++Pass `value` and update it with `onValueChange` to own the same volume in React state. The callback receives the next value and event details.++```tsx+import { useState } from 'react';+import { Slider } from 'twenty-ui/primitives/input';++export const VolumeSlider = () => {+ const [volume, setVolume] = useState(40);++ return (+ <Slider.Root+ name="volume"+ value={volume}+ onValueChange={setVolume}+ min={0}+ max={100}+ step={1}+ >+ <Slider.Label>Volume</Slider.Label>+ <Slider.Value />+ <Slider.Control>+ <Slider.Track>+ <Slider.Indicator />+ <Slider.Thumb />+ </Slider.Track>+ </Slider.Control>+ </Slider.Root>+ );+};+```++Use `onValueChange` to keep the controlled value current during an interaction. `onValueCommitted` handles the final value when the interaction finishes, for example to save it. Both callbacks are also available in uncontrolled mode without taking ownership of the value.## Range@@ -63,6 +98,8 @@ export const PriceRange = () => (Give range thumbs distinct accessible names and an `index` corresponding to their value. `minStepsBetweenValues` sets the minimum gap in steps. The root's generic value type is a number or a readonly array of numbers.+To control a range, store the array in React state and pass it through `value` and `onValueChange`, just as for a single value.+## Parts and keyboard| Part | Purpose |@@ -77,6 +114,8 @@ Give range thumbs distinct accessible names and an `index` corresponding to theiArrow keys adjust a focused thumb by a step. Home and End move it toward the bounds while respecting range constraints. `orientation="vertical"` changes the layout and keyboard direction. Use `disabled` on `Root` to prevent changes.+Set `color="success"` for the alternative palette; the default is `accent`.+## PropsThe reference is generated from the public component types. Native attributes, including accessible names and event handlers, are also accepted on parts that render elements.diff --git a/packages/twenty-docs/ui/primitives/input/switch.mdx b/packages/twenty-docs/ui/primitives/input/switch.mdxindex e4bfcb066d7..f664ae3e513 100644--- a/packages/twenty-docs/ui/primitives/input/switch.mdx+++ b/packages/twenty-docs/ui/primitives/input/switch.mdx@@ -17,6 +17,8 @@ Use `Switch` for an on or off preference. Give the control a visible label or an## Uncontrolled state+Use `defaultChecked` to set the initial checked state. The switch owns subsequent changes.+```tsximport { Switch } from 'twenty-ui/primitives/input';@@ -30,16 +32,22 @@ export const NotificationsPreference = () => (## Controlled state+Pass `checked` and update it with `onCheckedChange` to own the same preference in React state.+```tsximport { useState } from 'react';import { Switch } from 'twenty-ui/primitives/input';export const NotificationsPreference = () => {- const [checked, setChecked] = useState(false);+ const [checked, setChecked] = useState(true);return (<label>- <Switch checked={checked} onCheckedChange={setChecked} />+ <Switch+ name="notifications"+ checked={checked}+ onCheckedChange={setChecked}+ />Email notifications</label>);diff --git a/packages/twenty-docs/ui/primitives/input/textarea.mdx b/packages/twenty-docs/ui/primitives/input/textarea.mdxindex 895617d15a8..f61eea6502a 100644--- a/packages/twenty-docs/ui/primitives/input/textarea.mdx+++ b/packages/twenty-docs/ui/primitives/input/textarea.mdx@@ -15,7 +15,9 @@ Use `Textarea` for notes, descriptions, and other multiline values. It integrateheight={240}/>-## Basic textarea+## Uncontrolled state++Use `defaultValue` to set the initial notes. The textarea owns subsequent changes.```tsximport { Field, Textarea } from 'twenty-ui/primitives/input';@@ -31,7 +33,30 @@ export const NotesField = () => (Native textarea attributes such as `rows`, `maxLength`, `required`, and `readOnly` are available. `size` accepts `sm` or `md` and defaults to `md`.-## Controlled value and automatic resizing+## Controlled state++Pass `value` and update it with `onValueChange` to own the same notes in React state. The callback receives the next string value and event details; native `onChange` is also available.++```tsx+import { useState } from 'react';+import { Field, Textarea } from 'twenty-ui/primitives/input';++export const NotesField = () => {+ const [notes, setNotes] = useState('Follow up next week.');++ return (+ <Field.Root name="notes">+ <Field.Label>Notes</Field.Label>+ <Textarea rows={4} value={notes} onValueChange={setNotes} />+ <Field.Description>Add context for your team.</Field.Description>+ </Field.Root>+ );+};+```++## Automatic resizing++Automatic resizing works in either state mode. This example also uses the controlled value for a character count.```tsximport { useState } from 'react';@@ -59,7 +84,7 @@ export const DescriptionField = () => {};```-`autoResize` adjusts the textarea's height as its content changes. Use `maxRows` to cap the height. `onValueChange` receives the next string and event details; native `onChange` is also available. Keep keyboard focus on the textarea while the user types and use helper text for limits.+`autoResize` adjusts the textarea's height as its content changes. Use `maxRows` to cap the height. Keep keyboard focus on the textarea while the user types and use helper text for limits.## Propsdiff --git a/packages/twenty-docs/ui/primitives/navigation/tabs.mdx b/packages/twenty-docs/ui/primitives/navigation/tabs.mdxindex 8f5340e8b5e..bd3102871b6 100644--- a/packages/twenty-docs/ui/primitives/navigation/tabs.mdx+++ b/packages/twenty-docs/ui/primitives/navigation/tabs.mdx@@ -15,7 +15,9 @@ import TabsReference from '/snippets/ui/generated/navigation/tabs.mdx';height={240}/>-## Tab panels+## Uncontrolled state++Use `defaultValue` to set the initial active tab. The tabs own subsequent selection changes.```tsximport { Tabs } from 'twenty-ui/primitives/navigation';@@ -36,7 +38,35 @@ export const RecordTabs = () => (`Tabs.Tab` accepts `startIcon`, `badge`, and a `size` of `sm` or `md` (default `sm`). The active indicator is included in `Tabs.List`.-## Controlled state and manual activation+## Controlled state++Pass `value` and update it with `onValueChange` to own the same active tab in React state. The callback receives the next value and event details.++```tsx+import { useState } from 'react';+import { Tabs } from 'twenty-ui/primitives/navigation';++export const RecordTabs = () => {+ const [tab, setTab] = useState<string | number | null>('overview');++ return (+ <Tabs.Root value={tab} onValueChange={setTab}>+ <Tabs.List aria-label="Record details">+ <Tabs.Tab value="overview">Overview</Tabs.Tab>+ <Tabs.Tab value="activity" badge={3}>+ Activity+ </Tabs.Tab>+ </Tabs.List>+ <Tabs.Panel value="overview">Company and contact details.</Tabs.Panel>+ <Tabs.Panel value="activity">Recent calls and emails.</Tabs.Panel>+ </Tabs.Root>+ );+};+```++## Manual activation++Keyboard activation is independent of state ownership. Use `activateOnFocus={false}` with either controlled or uncontrolled tabs.```tsximport { useState } from 'react';diff --git a/packages/twenty-docs/ui/primitives/overview.mdx b/packages/twenty-docs/ui/primitives/overview.mdxindex c115225ab17..ee5245085e9 100644--- a/packages/twenty-docs/ui/primitives/overview.mdx+++ b/packages/twenty-docs/ui/primitives/overview.mdx@@ -10,6 +10,24 @@ Import primitives from a family entry point, such as `twenty-ui/primitives/inputAll existing UI controls belong to the primitives layer, including controls still being migrated to the new API. [Components](/ui/components/overview) are reserved for larger, reusable app building blocks composed from these primitives.+## State ownership++Use uncontrolled state when a component can manage its own interactions. A default prop supplies the initial state. Use controlled state when the application needs to coordinate that state with other controls, navigation, or application data.++| State | Uncontrolled initial state | Controlled state | Change callback |+| ------------------------------- | -------------------------- | ---------------- | ----------------- |+| Input, selection, or active tab | `defaultValue` | `value` | `onValueChange` |+| Checkbox or switch | `defaultChecked` | `checked` | `onCheckedChange` |+| Popup visibility | `defaultOpen` | `open` | `onOpenChange` |++In controlled mode, pass the current state and update it in the change callback. In uncontrolled mode, you can still listen to changes without taking ownership of the state. Adding a callback alone does not make a component controlled.++Choose a mode for each state and keep it for the lifetime of the component. Default props initialize state; changing them later does not replace the current state. Avoid passing both the default and controlled prop for the same state.++Some components have more than one independent state. For example, [Select](/ui/primitives/input/select#open-state) can have a controlled value and uncontrolled popup visibility. [Menu](/ui/primitives/surfaces/menu#selection-and-submenus) can manage its own visibility while the application controls checkbox and radio selections.++State belongs to the part that manages the interaction. Configure radio selection on [RadioGroup](/ui/primitives/input/radio-group), not on each Radio. Display components such as Text do not have a controlled or uncontrolled mode. [Toast](/ui/primitives/feedback/toast) delegates its visibility and removal to the application.+## Browse primitivesEach page includes usage examples, interaction guidance, and a generated API reference.diff --git a/packages/twenty-docs/ui/primitives/surfaces/alert-dialog.mdx b/packages/twenty-docs/ui/primitives/surfaces/alert-dialog.mdxindex 1f6fcb2de9b..7159ca410cd 100644--- a/packages/twenty-docs/ui/primitives/surfaces/alert-dialog.mdx+++ b/packages/twenty-docs/ui/primitives/surfaces/alert-dialog.mdx@@ -15,7 +15,39 @@ Use `AlertDialog` for a decision that interrupts the current workflow, such as cheight={440}/>-## Confirmation+## Uncontrolled state++Use `defaultOpen` to set the initial visibility. The dialog owns subsequent changes from its trigger, close controls, and dismissal interactions.++```tsx+import { AlertDialog } from 'twenty-ui/primitives/surfaces';++type DeleteConfirmationProps = { onDelete: () => void };++export const DeleteConfirmation = ({ onDelete }: DeleteConfirmationProps) => (+ <AlertDialog.Root defaultOpen={false}>+ <AlertDialog.Trigger>Delete record</AlertDialog.Trigger>+ <AlertDialog.Popup>+ <AlertDialog.Header>+ <AlertDialog.Title>Delete this record?</AlertDialog.Title>+ <AlertDialog.Description>+ This action cannot be undone.+ </AlertDialog.Description>+ </AlertDialog.Header>+ <AlertDialog.Footer>+ <AlertDialog.Close>Cancel</AlertDialog.Close>+ <AlertDialog.Close onClick={onDelete}>Delete</AlertDialog.Close>+ </AlertDialog.Footer>+ </AlertDialog.Popup>+ </AlertDialog.Root>+);+```++`defaultOpen` defaults to `false`, so it can be omitted. This example uses a synchronous confirmation callback and closes after the action runs.++## Controlled state++Pass `open` and update it with `onOpenChange` to own the same dialog's visibility in React state. The callback receives the next boolean and event details, including changes requested by the trigger and close controls.```tsximport { useState } from 'react';@@ -38,15 +70,7 @@ export const DeleteConfirmation = ({ onDelete }: DeleteConfirmationProps) => {</AlertDialog.Header><AlertDialog.Footer><AlertDialog.Close>Cancel</AlertDialog.Close>- <button- type="button"- onClick={() => {- onDelete();- setOpen(false);- }}- >- Delete- </button>+ <AlertDialog.Close onClick={onDelete}>Delete</AlertDialog.Close></AlertDialog.Footer></AlertDialog.Popup></AlertDialog.Root>@@ -54,7 +78,7 @@ export const DeleteConfirmation = ({ onDelete }: DeleteConfirmationProps) => {};```-`Root` owns open state. Run the confirmed action in its event handler and close the dialog when it completes. For asynchronous actions, keep it open while pending and show an error if the action fails.+For asynchronous confirmation, use a `Button` with your action handler instead of `AlertDialog.Close`. Keep `open` true while the action is pending, call `setOpen(false)` after it succeeds, and show an error inside the dialog if it fails.## Parts and sizing@@ -67,7 +91,7 @@ export const DeleteConfirmation = ({ onDelete }: DeleteConfirmationProps) => {| `Header` | Groups the title and description. || `Body` | Holds optional additional content. || `Footer` | Groups confirmation and cancellation actions. |-| `Close` | Closes the dialog without running the confirmation action. |+| `Close` | Closes the dialog; `onClick` can run a synchronous action. |`Popup.size` defaults to `md`; see the reference for supported sizes. Use `container` to override the theme's portal container and `keepMounted` to retain mounted content when closed.diff --git a/packages/twenty-docs/ui/primitives/surfaces/menu.mdx b/packages/twenty-docs/ui/primitives/surfaces/menu.mdxindex 2591abd7632..d0b85ec4f14 100644--- a/packages/twenty-docs/ui/primitives/surfaces/menu.mdx+++ b/packages/twenty-docs/ui/primitives/surfaces/menu.mdx@@ -15,7 +15,9 @@ Use `Menu` for actions opened from a trigger. Its items supply keyboard navigatiheight={440}/>-## Action menu+## Uncontrolled state++Use `defaultOpen` to set the initial visibility. The menu owns subsequent changes from its trigger, item selection, and dismissal interactions.```tsximport { IconCopy, IconTrash } from 'twenty-ui/icon';@@ -24,7 +26,7 @@ import { Menu } from 'twenty-ui/primitives/surfaces';type RecordMenuProps = { onDuplicate: () => void; onDelete: () => void };export const RecordMenu = ({ onDuplicate, onDelete }: RecordMenuProps) => (- <Menu.Root>+ <Menu.Root defaultOpen={false}><Menu.Trigger>Record actions</Menu.Trigger><Menu.Popup><Menu.Item startIcon={<IconCopy />} onClick={onDuplicate}>@@ -39,10 +41,76 @@ export const RecordMenu = ({ onDuplicate, onDelete }: RecordMenuProps) => ();```-Action items close the menu when selected by default. `disabled` prevents selection. `hotkeys` displays shortcut hints; register shortcut handlers in your application.+`defaultOpen` defaults to `false`, so it can be omitted. Action items close the menu when selected by default. `disabled` prevents selection. `hotkeys` displays shortcut hints; register shortcut handlers in your application.++## Controlled state++Pass `open` and update it with `onOpenChange` to own the same menu's visibility in React state. The callback receives the next boolean and event details, including dismissal and item selection.++```tsx+import { useState } from 'react';+import { IconCopy, IconTrash } from 'twenty-ui/icon';+import { Menu } from 'twenty-ui/primitives/surfaces';++type RecordMenuProps = { onDuplicate: () => void; onDelete: () => void };++export const RecordMenu = ({ onDuplicate, onDelete }: RecordMenuProps) => {+ const [open, setOpen] = useState(false);++ return (+ <Menu.Root open={open} onOpenChange={setOpen}>+ <Menu.Trigger>Record actions</Menu.Trigger>+ <Menu.Popup>+ <Menu.Item startIcon={<IconCopy />} onClick={onDuplicate}>+ Duplicate+ </Menu.Item>+ <Menu.Separator />+ <Menu.Item startIcon={<IconTrash />} color="danger" onClick={onDelete}>+ Delete+ </Menu.Item>+ </Menu.Popup>+ </Menu.Root>+ );+};+```## Selection and submenus+Item selection is independent of popup visibility. Checkbox items use `defaultChecked` or `checked` with `onCheckedChange`. Radio groups use `defaultValue` or `value` with `onValueChange`.++### Uncontrolled item state++Each checkbox item and radio group owns its selection. Both the menu and submenu also manage their own visibility.++```tsx+import { Menu } from 'twenty-ui/primitives/surfaces';++export const ViewMenu = () => (+ <Menu.Root>+ <Menu.Trigger>View options</Menu.Trigger>+ <Menu.Popup>+ <Menu.CheckboxItem defaultChecked={false}>+ Show archived records+ </Menu.CheckboxItem>+ <Menu.Separator />+ <Menu.SubmenuRoot>+ <Menu.SubmenuTrigger>Layout</Menu.SubmenuTrigger>+ <Menu.Popup>+ <Menu.RadioGroup defaultValue="list">+ <Menu.RadioItem value="list">List</Menu.RadioItem>+ <Menu.RadioItem value="board">Board</Menu.RadioItem>+ </Menu.RadioGroup>+ </Menu.Popup>+ </Menu.SubmenuRoot>+ </Menu.Popup>+ </Menu.Root>+);+```++### Controlled item state++The application owns the same selections in React state. Popup visibility remains uncontrolled because neither root receives `open`.+```tsximport { useState } from 'react';import { Menu } from 'twenty-ui/primitives/surfaces';@@ -77,7 +145,7 @@ export const ViewMenu = () => {};```-Checkbox and radio items keep the popup open by default so users can adjust options. Use `closeOnClick` to change that behavior. Nest a `SubmenuRoot`, `SubmenuTrigger`, and `Popup` inside a parent popup for submenus.+Checkbox and radio items keep the popup open by default so users can adjust options. Use `closeOnClick` to change that behavior. Nest a `SubmenuRoot`, `SubmenuTrigger`, and `Popup` inside a parent popup for submenus. Each `SubmenuRoot` has its own `defaultOpen`, `open`, and `onOpenChange` props, independent of the parent menu.## Parts and interaction@@ -100,7 +168,7 @@ Arrow keys move through the items, including disabled ones, which receive focus| Top-level menu | `bottom` | `start` | `8` | `0` || Submenu | `inline-end` | `start` | `0` | `-4` |-It uses the [theme's portal container](/ui/theming) by default. Control open state with `Root.open` and `Root.onOpenChange`.+It uses the [theme's portal container](/ui/theming) by default.## Propsdiff --git a/packages/twenty-docs/ui/primitives/surfaces/popover.mdx b/packages/twenty-docs/ui/primitives/surfaces/popover.mdxindex 7c404f7f927..423d7d5021e 100644--- a/packages/twenty-docs/ui/primitives/surfaces/popover.mdx+++ b/packages/twenty-docs/ui/primitives/surfaces/popover.mdx@@ -15,13 +15,15 @@ Use `Popover` for contextual information or lightweight controls. `Popup` includheight={440}/>-## Contextual content+## Uncontrolled state++Use `defaultOpen` to set the initial visibility. The popover owns subsequent changes from its trigger, close controls, and dismissal interactions.```tsximport { Popover } from 'twenty-ui/primitives/surfaces';export const ImportHelp = () => (- <Popover.Root>+ <Popover.Root defaultOpen={false}><Popover.Trigger>Import help</Popover.Trigger><Popover.Popup arrow><Popover.Title>Import a CSV file</Popover.Title>@@ -34,37 +36,35 @@ export const ImportHelp = () => ();```-Use `Title` and `Description` to identify the popup. The trigger renders a button by default; `render` lets you supply a compatible element.+`defaultOpen` defaults to `false`, so it can be omitted. Use `Title` and `Description` to identify the popup. The trigger renders a button by default; `render` lets you supply a compatible element.## Controlled state+Pass `open` and update it with `onOpenChange` to own the same popover's visibility in React state.+```tsximport { useState } from 'react';import { Popover } from 'twenty-ui/primitives/surfaces';-export const FilterPopover = () => {+export const ImportHelp = () => {const [open, setOpen] = useState(false);return (<Popover.Root open={open} onOpenChange={setOpen}>- <Popover.Trigger>Filters</Popover.Trigger>- <Popover.Popup align="start">- <Popover.Title>Record filters</Popover.Title>+ <Popover.Trigger>Import help</Popover.Trigger>+ <Popover.Popup arrow>+ <Popover.Title>Import a CSV file</Popover.Title><Popover.Description>- Choose which records to display.+ Use a header row to identify your columns.</Popover.Description>- <label>- <input type="checkbox" />- Only my records- </label>- <Popover.Close>Done</Popover.Close>+ <Popover.Close>Got it</Popover.Close></Popover.Popup></Popover.Root>);};```-`onOpenChange` receives the next boolean and event details. Use `defaultOpen` for uncontrolled initial state.+`onOpenChange` receives the next boolean and event details, including changes requested by the trigger, close controls, Escape, and outside interaction.## Parts and placementdiff --git a/packages/twenty-ui/README.md b/packages/twenty-ui/README.mdindex ea2b09f2d48..a37f9826b13 100644--- a/packages/twenty-ui/README.md+++ b/packages/twenty-ui/README.md@@ -77,6 +77,10 @@ import { Button } from 'twenty-ui/primitives/input';# Development+Component guides belong in `packages/twenty-docs/ui/primitives`. For each stateful API that supports both modes, include separate **Uncontrolled state** and **Controlled state** examples with the same scenario, labels, and initial state. Keep each example complete, with public imports and one exported example component.++Explain state ownership before advanced behavior such as indeterminate selection or manual tab activation. Document independent states, such as selection and popup visibility, separately. For components that delegate state to a parent or group, explain that ownership and link to the relevant examples.+Component interaction and behavior tests belong in Storybook stories (`*.stories.tsx`) using `play` functions. Component unit tests are reserved for conformance (native props, refs, class names, rendering, and prop types). Keep non-interactive utility, hook, and token tests in the Vitest unit project; avoid duplicating story coverage there.```bash