Skip to content

The open alternative to Salesforce, designed for AI.

Add the shared Dropdown foundation (#26383)

Raphaël Bosi03cb0d9967d4
diff --git a/packages/twenty-agent-skills/references/design/front-component-ui.md b/packages/twenty-agent-skills/references/design/front-component-ui.md
index 217f9c41fa1..d62a720dc74 100644
--- a/packages/twenty-agent-skills/references/design/front-component-ui.md
+++ b/packages/twenty-agent-skills/references/design/front-component-ui.md
@@ -36,6 +36,18 @@ Use local inline styles for layout containers and custom data displays, but keep
Use Twenty UI icons before custom SVG. Use `themeCssVariables.icon.size.md` for default row and action icons, `themeCssVariables.icon.size.sm` for quiet chevrons, and `themeCssVariables.spacing[6]` for icon-only action targets.
+## Dropdowns
+
+Use `Dropdown` from `twenty-ui/components` for action menus, searchable pickers, and compact editor panels. Compose `Dropdown.Root`, `Dropdown.Trigger`, and `Dropdown.Content`; render a Twenty `Button` through the trigger's `render` prop and give the content an accessible label.
+
+Choose the root's `type` for the interaction:
+
+- `type="menu"`: use `Dropdown.ActionItem` for commands and `Dropdown.OptionItem` for selectable settings.
+- `type="picker"`: combine `Dropdown.Search` with `Dropdown.OptionItem`. Own the search and selection state in the component, filter the displayed options, and pass each option's `selected` and `onSelect` props. Set `multiple` on the root for multiple selections that keep the picker open.
+- `type="panel"`: compose form controls inside the content, with normal Tab navigation.
+
+Group rows with `Dropdown.Section` and `Dropdown.Separator`. Use `Dropdown.Loading` and `Dropdown.Empty` for loading and empty results. For navigation within the same popup, use `Dropdown.Page` with an `id`, an action item's matching `page` prop, and `Dropdown.Back`; a page can override `type`. For a nested popup, compose `Dropdown.Submenu`, `Dropdown.SubmenuTrigger`, and `Dropdown.Content`.
+
## Token-First Implementation
When turning a Figma observation into code, translate the visual target into a token:
diff --git a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
index c7907bc7fc4..c79a4395ce2 100644
--- a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
+++ b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
@@ -785,7 +785,7 @@ These entry points do not require `monaco-editor`.
| Subpath | What it exports |
| --- | --- |
-| `twenty-ui/components` | Shared presets, pickers, menu rows, toasts, and the JSON viewer |
+| `twenty-ui/components` | Shared presets, pickers, menu rows, dropdowns, toasts, and the JSON viewer |
| `twenty-ui/primitives/accessibility` | Hidden elements |
| `twenty-ui/primitives/data-display` | Avatars, chips, tags, color samples, and status indicators |
| `twenty-ui/primitives/feedback` | Banners, progress bars, and loaders |
@@ -797,6 +797,8 @@ These entry points do not require `monaco-editor`.
| `twenty-ui/icon` | `Icon*` components (e.g. `IconCheck`) |
| `twenty-ui/theme-constants` | `ThemeProvider`, `themeCssVariables` |
+Use [`Dropdown`](/ui/components/dropdown) for action menus, option pickers, and form panels.
+
```tsx
import { defineFrontComponent } from 'twenty-sdk/define';
import { Button } from 'twenty-ui/primitives/input';
diff --git a/packages/twenty-docs/docs.json b/packages/twenty-docs/docs.json
index 7fa836552af..78ded33cd8c 100644
--- a/packages/twenty-docs/docs.json
+++ b/packages/twenty-docs/docs.json
@@ -577,6 +577,7 @@
"ui/components/input/light-icon-button",
"ui/components/section",
"ui/components/settings-row",
+ "ui/components/dropdown",
"ui/components/tab-button",
"ui/components/code-editor",
"ui/components/toast"
diff --git a/packages/twenty-docs/navigation/base-structure.json b/packages/twenty-docs/navigation/base-structure.json
index 83a89cc92bb..1eeb6f64cf4 100644
--- a/packages/twenty-docs/navigation/base-structure.json
+++ b/packages/twenty-docs/navigation/base-structure.json
@@ -592,6 +592,7 @@
"ui/components/input/light-icon-button",
"ui/components/section",
"ui/components/settings-row",
+ "ui/components/dropdown",
"ui/components/tab-button",
"ui/components/code-editor",
"ui/components/toast"
diff --git a/packages/twenty-docs/scripts/ui/__tests__/documentation-defaults.spec.ts b/packages/twenty-docs/scripts/ui/__tests__/documentation-defaults.spec.ts
index f36d7162fc4..e51d7335f5e 100644
--- a/packages/twenty-docs/scripts/ui/__tests__/documentation-defaults.spec.ts
+++ b/packages/twenty-docs/scripts/ui/__tests__/documentation-defaults.spec.ts
@@ -1,9 +1,26 @@
+import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
import { normalizeDocumentationDefaultValue } from '../../../../twenty-ui/docs/normalizeDocumentationDefaultValue';
import { renderComponentReference } from '../render-component-reference';
describe('documentation defaults', () => {
+ it('documents render-dependent native button defaults on dropdown parts', () => {
+ const reference = readFileSync(
+ new URL(
+ '../../../snippets/ui/generated/components/dropdown.mdx',
+ import.meta.url,
+ ),
+ 'utf8',
+ );
+
+ for (const part of ['ActionItem', 'OptionItem', 'Back', 'SubmenuTrigger']) {
+ expect(reference).toContain(
+ `body="${part}.nativeButton" type="boolean" default="true when render is omitted; false otherwise"`,
+ );
+ }
+ });
+
it.each([
["'onSubmit'", 'onSubmit'],
['"horizontal"', 'horizontal'],
diff --git a/packages/twenty-docs/snippets/ui/generated/components/dropdown.mdx b/packages/twenty-docs/snippets/ui/generated/components/dropdown.mdx
new file mode 100644
index 00000000000..6a810aa67b8
--- /dev/null
+++ b/packages/twenty-docs/snippets/ui/generated/components/dropdown.mdx
@@ -0,0 +1,488 @@
+{/*
+ * _____ _
+ *|_ _|_ _____ _ __ | |_ _ _
+ * | | \ \ /\ / / _ \ '_ \| __| | | | Auto-generated file
+ * | | \ V V / __/ | | | |_| |_| | DO NOT EDIT - changes will be overwritten
+ * |_| \_/\_/ \___|_| |_|\__|\__, | Generated by: npx nx generate:ui twenty-docs
+ * |___/
+ *
+ * This file is generated from the documentation data in packages/twenty-ui/generated.
+ * To update it, edit the component prop types or design tokens in twenty-ui and run:
+ * npx nx generate:ui twenty-docs
+ */}
+
+### Dropdown.Root
+
+<ParamField body="Root.defaultOpen" type="boolean">
+
+</ParamField>
+
+<ParamField body="Root.defaultPage" type="string">
+
+</ParamField>
+
+<ParamField body="Root.multiple" type="boolean">
+
+</ParamField>
+
+<ParamField body="Root.onOpenChange" type="((open: boolean) =&gt; void)">
+
+</ParamField>
+
+<ParamField body="Root.open" type="boolean">
+
+</ParamField>
+
+<ParamField body="Root.type" type="&quot;menu&quot; | &quot;panel&quot; | &quot;picker&quot;" required>
+
+</ParamField>
+
+### Dropdown.Trigger
+
+<ParamField body="Trigger.className" type="string | ((state: PopoverTriggerState) =&gt; string | undefined)">
+ CSS class applied to the element, or a function that
+ returns a class based on the component's state.
+</ParamField>
+
+<ParamField body="Trigger.closeDelay" type="number" default="0">
+ How long to wait before closing the popover that was opened on hover.
+ Specified in milliseconds.
+
+ Requires the `openOnHover` prop.
+</ParamField>
+
+<ParamField body="Trigger.delay" type="number" default="300">
+ How long to wait before the popover may be opened on hover. Specified in milliseconds.
+
+ Requires the `openOnHover` prop.
+</ParamField>
+
+<ParamField body="Trigger.handle" type="PopoverHandle&lt;unknown&gt;">
+ A handle to associate the trigger with a popover.
+</ParamField>
+
+<ParamField body="Trigger.id" type="string">
+ ID of the trigger. In addition to being forwarded to the rendered element,
+ it is also used to specify the active trigger for the popover in controlled mode (with the PopoverRoot `triggerId` prop).
+</ParamField>
+
+<ParamField body="Trigger.nativeButton" type="boolean" default="true">
+ Whether the component renders a native `<button>` element when replacing it
+ via the `render` prop.
+ Set to `false` if the rendered element is not a button (e.g. `<div>`).
+</ParamField>
+
+<ParamField body="Trigger.openOnHover" type="boolean" default="false">
+ Whether the popover should also open when the trigger is hovered.
+</ParamField>
+
+<ParamField body="Trigger.payload" type="unknown">
+ A payload to pass to the popover when it is opened.
+</ParamField>
+
+<ParamField body="Trigger.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, PopoverTriggerState&gt;">
+ Allows you to replace the component's HTML element
+ with a different tag, or compose it with another component.
+
+ Accepts a `ReactElement` or a function that returns the element to render.
+</ParamField>
+
+<ParamField body="Trigger.style" type="CSSProperties | ((state: PopoverTriggerState) =&gt; CSSProperties | undefined)">
+ Style applied to the element, or a function that
+ returns a style object based on the component's state.
+</ParamField>
+
+### Dropdown.Content
+
+<ParamField body="Content.align" type="&quot;center&quot; | &quot;end&quot; | &quot;start&quot;" default="start">
+ Alignment of the popup along the anchor.
+</ParamField>
+
+<ParamField body="Content.alignOffset" type="number">
+ Offset in pixels along the alignment axis.
+</ParamField>
+
+<ParamField body="Content.anchor" type="Element | VirtualElement | RefObject&lt;Element | null&gt; | (() =&gt; Element | VirtualElement | null) | null">
+ Element or position the popup is anchored to. Defaults to the trigger.
+</ParamField>
+
+<ParamField body="Content.className" type="string | ((state: PopoverPopupState) =&gt; string | undefined)">
+ CSS class applied to the element, or a function that
+ returns a class based on the component's state.
+</ParamField>
+
+<ParamField body="Content.container" type="HTMLElement | ShadowRoot | RefObject&lt;HTMLElement | ShadowRoot | null&gt; | null">
+ Element the popup is portaled into. Defaults to the theme's portal
+ container.
+</ParamField>
+
+<ParamField body="Content.finalFocus" type="boolean | RefObject&lt;HTMLElement | null&gt; | ((closeType: InteractionType) =&gt; boolean | void | HTMLElement | null)">
+ Determines the element to focus when the popover is closed.
+
+ - `false`: Do not move focus.
+ - `true`: Move focus based on the default behavior (trigger or previously focused element).
+ - `RefObject`: Move focus to the ref element.
+ - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`).
+ Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing.
+</ParamField>
+
+<ParamField body="Content.initialFocus" type="boolean | RefObject&lt;HTMLElement | null&gt; | ((openType: InteractionType) =&gt; boolean | void | HTMLElement | null)">
+ Determines the element to focus when the popover is opened.
+ By default, focus moves to the first tabbable element inside the popup, except when the popover
+ is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard.
+
+ - `false`: Do not move focus.
+ - `true`: Move focus based on the default behavior (first tabbable element or popup).
+ - `RefObject`: Move focus to the ref element.
+ - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`).
+ Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing.
+</ParamField>
+
+<ParamField body="Content.keepMounted" type="boolean">
+ Keeps the popup mounted in the DOM while the popover is closed.
+</ParamField>
+
+<ParamField body="Content.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, PopoverPopupState&gt;">
+ Allows you to replace the component's HTML element
+ with a different tag, or compose it with another component.
+
+ Accepts a `ReactElement` or a function that returns the element to render.
+</ParamField>
+
+<ParamField body="Content.side" type="&quot;bottom&quot; | &quot;inline-end&quot; | &quot;inline-start&quot; | &quot;left&quot; | &quot;right&quot; | &quot;top&quot;">
+ Side of the anchor the popup is placed on.
+</ParamField>
+
+<ParamField body="Content.sideOffset" type="number" default="0">
+ Distance in pixels between the anchor and the popup.
+</ParamField>
+
+<ParamField body="Content.style" type="CSSProperties | ((state: PopoverPopupState) =&gt; CSSProperties | undefined)">
+ Style applied to the element, or a function that
+ returns a style object based on the component's state.
+</ParamField>
+
+<ParamField body="Content.width" type="Width&lt;string | number&gt;" default="200">
+
+</ParamField>
+
+### Dropdown.ActionItem
+
+<ParamField body="ActionItem.className" type="string">
+
+</ParamField>
+
+<ParamField body="ActionItem.closeOnClick" type="boolean" default="true">
+
+</ParamField>
+
+<ParamField body="ActionItem.color" type="&quot;danger&quot; | &quot;neutral&quot;">
+ Color of the text and icons. `danger` marks a destructive action.
+</ParamField>
+
+<ParamField body="ActionItem.description" type="ReactNode">
+ Supporting text, placed according to `descriptionPlacement`.
+</ParamField>
+
+<ParamField body="ActionItem.descriptionPlacement" type="&quot;end&quot; | &quot;inline&quot;">
+ Where the description renders: inline after the content or at the end of
+ the row.
+</ParamField>
+
+<ParamField body="ActionItem.endIcon" type="ReactNode">
+ Icon rendered after the content.
+</ParamField>
+
+<ParamField body="ActionItem.focusableWhenDisabled" type="boolean" default="false">
+ Whether the button should be focusable when disabled.
+</ParamField>
+
+<ParamField body="ActionItem.hasSubmenu" type="boolean">
+ Shows a chevron indicating that the item opens a submenu.
+</ParamField>
+
+<ParamField body="ActionItem.hotkeys" type="string[]">
+ Keyboard shortcut keys displayed at the end of the row. Registering the
+ shortcut is up to the application.
+</ParamField>
+
+<ParamField body="ActionItem.nativeButton" type="boolean" default="true when render is omitted; false otherwise">
+ Whether the component renders a native `<button>` element when replacing it
+ via the `render` prop.
+ Set to `false` if the rendered element is not a button (for example, `<div>`).
+</ParamField>
+
+<ParamField body="ActionItem.page" type="string">
+
+</ParamField>
+
+<ParamField body="ActionItem.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt;">
+
+</ParamField>
+
+<ParamField body="ActionItem.startIcon" type="ReactNode">
+ Icon rendered before the content.
+</ParamField>
+
+<ParamField body="ActionItem.style" type="CSSProperties">
+
+</ParamField>
+
+### Dropdown.OptionItem
+
+<ParamField body="OptionItem.className" type="string">
+
+</ParamField>
+
+<ParamField body="OptionItem.closeOnSelect" type="boolean">
+
+</ParamField>
+
+<ParamField body="OptionItem.color" type="&quot;danger&quot; | &quot;neutral&quot;">
+ Color of the text and icons. `danger` marks a destructive action.
+</ParamField>
+
+<ParamField body="OptionItem.description" type="ReactNode">
+ Supporting text, placed according to `descriptionPlacement`.
+</ParamField>
+
+<ParamField body="OptionItem.descriptionPlacement" type="&quot;end&quot; | &quot;inline&quot;">
+ Where the description renders: inline after the content or at the end of
+ the row.
+</ParamField>
+
+<ParamField body="OptionItem.endIcon" type="ReactNode">
+ Icon rendered after the content.
+</ParamField>
+
+<ParamField body="OptionItem.focusableWhenDisabled" type="boolean" default="false">
+ Whether the button should be focusable when disabled.
+</ParamField>
+
+<ParamField body="OptionItem.hasSubmenu" type="boolean">
+ Shows a chevron indicating that the item opens a submenu.
+</ParamField>
+
+<ParamField body="OptionItem.hotkeys" type="string[]">
+ Keyboard shortcut keys displayed at the end of the row. Registering the
+ shortcut is up to the application.
+</ParamField>
+
+<ParamField body="OptionItem.nativeButton" type="boolean" default="true when render is omitted; false otherwise">
+ Whether the component renders a native `<button>` element when replacing it
+ via the `render` prop.
+ Set to `false` if the rendered element is not a button (for example, `<div>`).
+</ParamField>
+
+<ParamField body="OptionItem.onSelect" type="(() =&gt; void)">
+
+</ParamField>
+
+<ParamField body="OptionItem.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt;">
+
+</ParamField>
+
+<ParamField body="OptionItem.selected" type="boolean" required>
+
+</ParamField>
+
+<ParamField body="OptionItem.startIcon" type="ReactNode">
+ Icon rendered before the content.
+</ParamField>
+
+<ParamField body="OptionItem.style" type="CSSProperties">
+
+</ParamField>
+
+### Dropdown.Search
+
+<ParamField body="Search.className" type="string | ((state: InputState) =&gt; string | undefined)">
+ CSS class applied to the element, or a function that
+ returns a class based on the component's state.
+</ParamField>
+
+<ParamField body="Search.defaultValue" type="string | number | readonly string[]">
+ The default value of the input. Use when uncontrolled.
+</ParamField>
+
+<ParamField body="Search.onValueChange" type="((value: string) =&gt; void)">
+
+</ParamField>
+
+<ParamField body="Search.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, InputState&gt;">
+ Allows you to replace the component's HTML element
+ with a different tag, or compose it with another component.
+
+ Accepts a `ReactElement` or a function that returns the element to render.
+</ParamField>
+
+<ParamField body="Search.style" type="CSSProperties | ((state: InputState) =&gt; CSSProperties | undefined)">
+ Style applied to the element, or a function that
+ returns a style object based on the component's state.
+</ParamField>
+
+<ParamField body="Search.value" type="string | number | readonly string[]">
+ The value of the input. Use when controlled.
+</ParamField>
+
+### Dropdown.Page
+
+<ParamField body="Page.id" type="string" required>
+
+</ParamField>
+
+<ParamField body="Page.type" type="&quot;menu&quot; | &quot;panel&quot; | &quot;picker&quot;">
+
+</ParamField>
+
+### Dropdown.Back
+
+<ParamField body="Back.className" type="string">
+
+</ParamField>
+
+<ParamField body="Back.color" type="&quot;danger&quot; | &quot;neutral&quot;">
+ Color of the text and icons. `danger` marks a destructive action.
+</ParamField>
+
+<ParamField body="Back.description" type="ReactNode">
+ Supporting text, placed according to `descriptionPlacement`.
+</ParamField>
+
+<ParamField body="Back.descriptionPlacement" type="&quot;end&quot; | &quot;inline&quot;">
+ Where the description renders: inline after the content or at the end of
+ the row.
+</ParamField>
+
+<ParamField body="Back.endIcon" type="ReactNode">
+ Icon rendered after the content.
+</ParamField>
+
+<ParamField body="Back.focusableWhenDisabled" type="boolean" default="false">
+ Whether the button should be focusable when disabled.
+</ParamField>
+
+<ParamField body="Back.hasSubmenu" type="boolean">
+ Shows a chevron indicating that the item opens a submenu.
+</ParamField>
+
+<ParamField body="Back.hotkeys" type="string[]">
+ Keyboard shortcut keys displayed at the end of the row. Registering the
+ shortcut is up to the application.
+</ParamField>
+
+<ParamField body="Back.nativeButton" type="boolean" default="true when render is omitted; false otherwise">
+ Whether the component renders a native `<button>` element when replacing it
+ via the `render` prop.
+ Set to `false` if the rendered element is not a button (for example, `<div>`).
+</ParamField>
+
+<ParamField body="Back.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt;">
+
+</ParamField>
+
+<ParamField body="Back.startIcon" type="ReactNode">
+ Icon rendered before the content.
+</ParamField>
+
+<ParamField body="Back.style" type="CSSProperties">
+
+</ParamField>
+
+### Dropdown.Submenu
+
+<ParamField body="Submenu.defaultOpen" type="boolean">
+
+</ParamField>
+
+<ParamField body="Submenu.defaultPage" type="string">
+
+</ParamField>
+
+<ParamField body="Submenu.multiple" type="boolean">
+
+</ParamField>
+
+<ParamField body="Submenu.onOpenChange" type="((open: boolean) =&gt; void)">
+
+</ParamField>
+
+<ParamField body="Submenu.open" type="boolean">
+
+</ParamField>
+
+<ParamField body="Submenu.type" type="&quot;menu&quot; | &quot;panel&quot; | &quot;picker&quot;" default="menu">
+
+</ParamField>
+
+### Dropdown.SubmenuTrigger
+
+<ParamField body="SubmenuTrigger.className" type="string">
+
+</ParamField>
+
+<ParamField body="SubmenuTrigger.closeDelay" type="number">
+
+</ParamField>
+
+<ParamField body="SubmenuTrigger.color" type="&quot;danger&quot; | &quot;neutral&quot;">
+ Color of the text and icons. `danger` marks a destructive action.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.delay" type="number">
+
+</ParamField>
+
+<ParamField body="SubmenuTrigger.description" type="ReactNode">
+ Supporting text, placed according to `descriptionPlacement`.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.descriptionPlacement" type="&quot;end&quot; | &quot;inline&quot;">
+ Where the description renders: inline after the content or at the end of
+ the row.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.endIcon" type="ReactNode">
+ Icon rendered after the content.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.focusableWhenDisabled" type="boolean" default="false">
+ Whether the button should be focusable when disabled.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.hasSubmenu" type="boolean" default="true">
+ Shows a chevron indicating that the item opens a submenu.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.hotkeys" type="string[]">
+ Keyboard shortcut keys displayed at the end of the row. Registering the
+ shortcut is up to the application.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.nativeButton" type="boolean" default="true when render is omitted; false otherwise">
+ Whether the component renders a native `<button>` element when replacing it
+ via the `render` prop.
+ Set to `false` if the rendered element is not a button (for example, `<div>`).
+</ParamField>
+
+<ParamField body="SubmenuTrigger.openOnHover" type="boolean" default="true">
+
+</ParamField>
+
+<ParamField body="SubmenuTrigger.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt;">
+
+</ParamField>
+
+<ParamField body="SubmenuTrigger.startIcon" type="ReactNode">
+ Icon rendered before the content.
+</ParamField>
+
+<ParamField body="SubmenuTrigger.style" type="CSSProperties">
+
+</ParamField>
+
+### Dropdown.Section
+
+<ParamField body="Section.label" type="ReactNode">
+
+</ParamField>
diff --git a/packages/twenty-docs/ui/components/dropdown.mdx b/packages/twenty-docs/ui/components/dropdown.mdx
new file mode 100644
index 00000000000..879d8168e9b
--- /dev/null
+++ b/packages/twenty-docs/ui/components/dropdown.mdx
@@ -0,0 +1,183 @@
+---
+title: Dropdown
+description: Action menus, searchable pickers, and form panels with shared presentation and interaction.
+---
+
+import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
+import DropdownReference from '/snippets/ui/generated/components/dropdown.mdx';
+
+`Dropdown` combines a positioned popup, visual rows, keyboard navigation, focus, and dismissal. Your application owns data, filtering, fetching, pagination, and selected values. Import it from `twenty-ui/components`.
+
+<StoryEmbed
+ storyId="ui-components-dropdown--documentation"
+ title="Dropdown actions"
+ height={380}
+/>
+
+## Choose an interaction type
+
+Set `type` on `Dropdown.Root` to match the popup's contents.
+
+| Type | Content | Interaction |
+| -------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------- |
+| `menu` | Commands and navigation links | Menu semantics with arrow navigation and typeahead. |
+| `picker` | Search, selectable values, and optional commands | A dialog containing a search field and selectable toggle buttons. Arrow keys navigate result rows. |
+| `panel` | Inputs, forms, and supporting actions | A dialog with native input behavior and Tab navigation. |
+
+Pickers allow creation actions and selectable values in the same list, in any order. Options expose their selected state with `aria-pressed`; commands keep their button semantics. Use a descriptive accessible name on `Content` and `Search`.
+
+The underlying [Menu](/ui/primitives/surfaces/menu), [Select](/ui/primitives/input/select), and [Popover](/ui/primitives/surfaces/popover) remain available for direct composition.
+
+## Anatomy
+
+```text
+Dropdown.Root
+├── Dropdown.Trigger
+└── Dropdown.Content
+ ├── Dropdown.Search
+ └── Dropdown.Section
+ ├── Dropdown.ActionItem
+ └── Dropdown.OptionItem
+```
+
+`Content` includes the portal and positioner. Use `width`, `side`, `align`, `sideOffset`, and `alignOffset` to control placement. `Section` groups rows with shared spacing, and `Separator` divides sections. Rows use [ListItem](/ui/primitives/navigation/list-item) for their appearance.
+
+```tsx
+import { Dropdown } from 'twenty-ui/components';
+import { IconCopy } from 'twenty-ui/icon';
+import { Button } from 'twenty-ui/primitives/input';
+
+export const RecordActions = ({ onDuplicate }: { onDuplicate: () => void }) => (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger render={<Button>Record actions</Button>} />
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Section>
+ <Dropdown.ActionItem startIcon={<IconCopy />} onClick={onDuplicate}>
+ Duplicate
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </Dropdown.Root>
+);
+```
+
+Pass custom trigger elements through `render` so the trigger remains one interactive element. Custom components must forward the supplied props and ref. `ActionItem` also accepts `render` for links.
+
+## Search and selection
+
+`Search` provides the input and navigation into the result rows. Pass `value` and `onValueChange`; compute or fetch matching results in your application. Render `Loading` while a request is pending and `Empty` when no results match. Both accept caller-provided status text.
+
+<StoryEmbed
+ storyId="ui-components-dropdown--picker"
+ title="Searchable picker with inline creation"
+ height={420}
+/>
+
+```tsx
+import { useState } from 'react';
+import { Dropdown } from 'twenty-ui/components';
+import { Button } from 'twenty-ui/primitives/input';
+
+export const PersonPicker = () => {
+ const [search, setSearch] = useState('');
+ const [selectedPerson, setSelectedPerson] = useState('');
+ const people = ['Ada Lovelace', 'Grace Hopper'].filter((person) =>
+ person.toLowerCase().includes(search.toLowerCase()),
+ );
+
+ return (
+ <Dropdown.Root type="picker">
+ <Dropdown.Trigger render={<Button>Choose person</Button>} />
+ <Dropdown.Content aria-label="Choose person">
+ <Dropdown.Search
+ aria-label="Search people"
+ value={search}
+ onValueChange={setSearch}
+ />
+ <Dropdown.Section>
+ {people.map((person) => (
+ <Dropdown.OptionItem
+ key={person}
+ selected={selectedPerson === person}
+ onSelect={() => setSelectedPerson(person)}
+ >
+ {person}
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
+```
+
+Actions and single selection close by default. Set `multiple` on the root to keep option selection open. The application still owns the selected values. `closeOnClick` on actions and `closeOnSelect` on options override those defaults, including repeated actions or asynchronous progress. Use `disabled` to prevent activation while retaining the row's appearance.
+
+<StoryEmbed
+ storyId="ui-components-dropdown--multiple-selection"
+ title="Multiple selection"
+ height={420}
+/>
+
+## Pages and submenus
+
+Use `Page` for navigation that replaces the contents of the same popup. Wrap the first page in `Page id="root"`, or choose another initial page with `defaultPage`. Set `page` on an action to navigate without closing. `Back` returns to the previous page and restores focus to its invoking row. Closing the dropdown resets its page history.
+
+A page can override the root's `type`. For example, an action menu can open a searchable picker page or a form panel. Search receives focus when entering a searchable page.
+
+<StoryEmbed
+ storyId="ui-components-dropdown--pages"
+ title="Menu to picker page navigation"
+ height={420}
+/>
+
+```tsx
+import { Dropdown } from 'twenty-ui/components';
+import { Button } from 'twenty-ui/primitives/input';
+
+export const FilterMenu = () => (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger render={<Button>Filters</Button>} />
+ <Dropdown.Content aria-label="Filters">
+ <Dropdown.Page id="root">
+ <Dropdown.Section>
+ <Dropdown.ActionItem page="status">Status</Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Page>
+ <Dropdown.Page id="status" type="picker">
+ <Dropdown.Back>Filters</Dropdown.Back>
+ <Dropdown.Section>
+ <Dropdown.OptionItem selected={false}>Active</Dropdown.OptionItem>
+ <Dropdown.OptionItem selected={false}>Archived</Dropdown.OptionItem>
+ </Dropdown.Section>
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>
+);
+```
+
+Use `Submenu` with `SubmenuTrigger` and a nested `Content` for a side-by-side menu. Arrow Right enters the submenu; Arrow Left returns to its parent. Selecting a closing action closes the whole dropdown.
+
+```text
+Dropdown.Content
+└── Dropdown.Submenu
+ ├── Dropdown.SubmenuTrigger
+ └── Dropdown.Content
+ └── Dropdown.ActionItem
+```
+
+## Panels and controlled state
+
+Use `type="panel"` for form inputs. Input interaction keeps the panel open; a save action can close it. Own `open` and `onOpenChange` when another component or a shortcut needs to open the dropdown. Keep that state with the feature that coordinates the interaction.
+
+<StoryEmbed
+ storyId="ui-components-dropdown--panel"
+ title="Controlled form panel"
+ height={380}
+/>
+
+Escape dismisses the popup and restores focus to its trigger. Outside interaction also dismisses it. `Content` accepts focus and portal options from Popover, including an explicit return-focus target for editor workflows.
+
+## Props
+
+<DropdownReference />
diff --git a/packages/twenty-docs/ui/components/overview.mdx b/packages/twenty-docs/ui/components/overview.mdx
index 45e742269ef..56ece78b7da 100644
--- a/packages/twenty-docs/ui/components/overview.mdx
+++ b/packages/twenty-docs/ui/components/overview.mdx
@@ -18,6 +18,7 @@ Import shared components from `twenty-ui/components`. The code editor has its ow
| [LightIconButton](/ui/components/input/light-icon-button) | Lightweight icon actions with standard or subtle emphasis. |
| [Section](/ui/components/section) | Related content with a heading, description, and optional action. |
| [SettingsRow](/ui/components/settings-row) | Labeled switches for settings and filters. |
+| [Dropdown](/ui/components/dropdown) | Action menus, searchable pickers, and form panels. |
| [TabButton](/ui/components/tab-button) | Route links and adjacent actions with the same appearance as tabs. |
| [CodeEditor](/ui/components/code-editor) | Code editing with Monaco, an optional header, and the Twenty theme. |
| [Toast](/ui/components/toast) | Notifications, queue management, and dismissal. |
diff --git a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx
index eebfc841339..133cb176ae4 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx
@@ -4,6 +4,7 @@ import { pickerListItemsTest } from '@/__stories__/twenty-ui-gallery/utils/picke
import { iconButtonElevatedTest } from '@/__stories__/twenty-ui-gallery/utils/iconButtonElevatedTest';
import { buttonControlsTest } from '@/__stories__/twenty-ui-gallery/utils/buttonControlsTest';
import { dialogTest } from '@/__stories__/twenty-ui-gallery/utils/dialogTest';
+import { dropdownSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest';
import { type Meta } from '@storybook/react-vite';
import {
@@ -302,6 +303,18 @@ export const MenuPreact: Story = createGalleryStory({
play: menuTest,
});
+export const DropdownReact: Story = createGalleryStory({
+ frontComponentBundleName: 'twenty-ui-dropdown',
+ runtime: 'react',
+ play: dropdownSandboxFailureTest,
+});
+
+export const DropdownPreact: Story = createGalleryStory({
+ frontComponentBundleName: 'twenty-ui-dropdown',
+ runtime: 'preact',
+ play: dropdownSandboxFailureTest,
+});
+
export const SelectReact: Story = createGalleryStory({
frontComponentBundleName: 'twenty-ui-select',
runtime: 'react',
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-dropdown.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-dropdown.front-component.tsx
new file mode 100644
index 00000000000..841987cc917
--- /dev/null
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-dropdown.front-component.tsx
@@ -0,0 +1,69 @@
+import { useState } from 'react';
+import { defineFrontComponent } from 'twenty-sdk/define';
+import { Dropdown } from 'twenty-ui/components';
+import { Button } from 'twenty-ui/primitives/input';
+import { Text } from 'twenty-ui/primitives/typography';
+
+import { TwentyUiGalleryCard } from '@/__stories__/shared/front-components/twenty-ui-gallery-card';
+
+const ASSIGNEES = ['Ada Lovelace', 'Grace Hopper'];
+
+const DropdownExample = () => {
+ const [open, setOpen] = useState(false);
+ const [query, setQuery] = useState('');
+ const [selection, setSelection] = useState('Unassigned');
+ const matchingAssignees = ASSIGNEES.filter((assignee) =>
+ assignee.toLowerCase().includes(query.toLowerCase()),
+ );
+
+ return (
+ <TwentyUiGalleryCard title="Dropdown">
+ <Dropdown.Root type="menu" open={open} onOpenChange={setOpen}>
+ <Dropdown.Trigger render={<Button>Choose assignee</Button>} />
+ <Dropdown.Content aria-label="Assignee actions">
+ <Dropdown.Page id="root">
+ <Dropdown.Section>
+ <Dropdown.ActionItem page="assignees">
+ Assign person
+ </Dropdown.ActionItem>
+ <Dropdown.ActionItem onClick={() => setSelection('Unassigned')}>
+ Remove assignee
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Page>
+ <Dropdown.Page id="assignees" type="picker">
+ <Dropdown.Back>People</Dropdown.Back>
+ <Dropdown.Search
+ aria-label="Search people"
+ value={query}
+ onValueChange={setQuery}
+ placeholder="Search people"
+ />
+ <Dropdown.Section>
+ {matchingAssignees.map((assignee) => (
+ <Dropdown.OptionItem
+ key={assignee}
+ selected={selection === assignee}
+ onSelect={() => setSelection(assignee)}
+ >
+ {assignee}
+ </Dropdown.OptionItem>
+ ))}
+ <Dropdown.ActionItem onClick={() => setSelection('New person')}>
+ Create person
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ <Text role="status">Assignee: {selection}</Text>
+ </TwentyUiGalleryCard>
+ );
+};
+
+export default defineFrontComponent({
+ universalIdentifier: '1c7c2c12-3775-47de-8e1e-d8c059b7f405',
+ name: 'twenty-ui-dropdown',
+ description: 'Dropdown page navigation and mixed picker rows in the sandbox',
+ component: DropdownExample,
+});
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest.ts
new file mode 100644
index 00000000000..2955029e105
--- /dev/null
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest.ts
@@ -0,0 +1,7 @@
+import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';
+import { createSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest';
+
+export const dropdownSandboxFailureTest = createSandboxFailureTest({
+ trigger: { type: 'click', role: 'button', name: 'Choose assignee' },
+ requiredErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH],
+});
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkDropdown.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkDropdown.tsx
new file mode 100644
index 00000000000..279f3b6a28d
--- /dev/null
+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkDropdown.tsx
@@ -0,0 +1,51 @@
+import { EditLinkDropdownForm } from '@/advanced-text-editor/components/EditLinkDropdownForm';
+import { type EditLinkEditor } from '@/advanced-text-editor/types/EditLinkEditor';
+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { Dropdown, LightIconButton } from 'twenty-ui/components';
+import { IconLink, IconPencil } from 'twenty-ui/icon';
+
+type EditLinkDropdownProps = {
+ dropdownId: string;
+ defaultValue: string | undefined;
+ editor: EditLinkEditor;
+};
+
+export const EditLinkDropdown = ({
+ dropdownId,
+ defaultValue = '',
+ editor,
+}: EditLinkDropdownProps) => {
+ const isActive = isNonEmptyString(defaultValue);
+ const { t } = useLingui();
+
+ return (
+ <DropdownRoot dropdownId={dropdownId} type="panel">
+ <Dropdown.Trigger
+ render={
+ <LightIconButton
+ aria-label={isActive ? t`Edit link` : t`Add link`}
+ aria-pressed={isActive}
+ emphasis={isActive ? 'standard' : 'subtle'}
+ size="sm"
+ >
+ {isActive ? <IconPencil /> : <IconLink />}
+ </LightIconButton>
+ }
+ />
+ <Dropdown.Content
+ sideOffset={0}
+ align="end"
+ finalFocus={(interaction) =>
+ interaction === 'keyboard' ? editor.view.dom : false
+ }
+ aria-label={isActive ? t`Edit link` : t`Add link`}
+ >
+ <Dropdown.Section>
+ <EditLinkDropdownForm defaultValue={defaultValue} editor={editor} />
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </DropdownRoot>
+ );
+};
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkDropdownForm.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkDropdownForm.tsx
new file mode 100644
index 00000000000..c2d6ddc74c0
--- /dev/null
+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkDropdownForm.tsx
@@ -0,0 +1,64 @@
+import { type EditLinkEditor } from '@/advanced-text-editor/types/EditLinkEditor';
+import { TextInput } from '@/ui/input/components/TextInput';
+import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
+import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { useState, type FocusEvent, type FormEvent } from 'react';
+import { getSafeUrl } from 'twenty-shared/utils';
+
+type EditLinkDropdownFormProps = {
+ defaultValue: string;
+ editor: Pick<EditLinkEditor, 'chain'>;
+};
+
+export const EditLinkDropdownForm = ({
+ defaultValue,
+ editor,
+}: EditLinkDropdownFormProps) => {
+ const { t } = useLingui();
+ const [value, setValue] = useState(defaultValue);
+ const isDropdownOpen = useAtomComponentStateValue(
+ isDropdownOpenComponentState,
+ );
+ const { closeDropdown } = useCloseDropdown();
+
+ const handleSubmit = (
+ event: FormEvent<HTMLFormElement> | FocusEvent<HTMLInputElement>,
+ ) => {
+ event.preventDefault();
+
+ if (!isDropdownOpen) {
+ return;
+ }
+
+ if (!isNonEmptyString(value)) {
+ closeDropdown();
+ editor.chain().focus().extendMarkRange('link').unsetLink().run();
+ return;
+ }
+
+ const href = getSafeUrl(value);
+
+ if (!isNonEmptyString(href)) {
+ return;
+ }
+
+ closeDropdown();
+ editor.chain().focus().extendMarkRange('link').setLink({ href }).run();
+ };
+
+ return (
+ <form onSubmit={handleSubmit}>
+ <TextInput
+ aria-label={t`Enter link`}
+ placeholder={t`Enter link`}
+ value={value}
+ onChange={setValue}
+ onBlur={handleSubmit}
+ autoFocus
+ />
+ </form>
+ );
+};
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkPopover.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkPopover.tsx
deleted file mode 100644
index 1a516d31899..00000000000
--- a/packages/twenty-front/src/modules/advanced-text-editor/components/EditLinkPopover.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import { BubbleMenuIconButton } from '@/advanced-text-editor/components/BubbleMenuIconButton';
-import { TextInput } from '@/ui/input/components/TextInput';
-import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
-import { useToggleDropdown } from '@/ui/layout/dropdown/hooks/useToggleDropdown';
-import { useLingui } from '@lingui/react/macro';
-import { isNonEmptyString } from '@sniptt/guards';
-import { type Editor } from '@tiptap/core';
-import { useId, useState, type FocusEvent, type FormEvent } from 'react';
-import { getSafeUrl, isDefined } from 'twenty-shared/utils';
-import { IconLink, IconPencil } from 'twenty-ui/icon';
-
-type EditLinkPopoverProps = {
- defaultValue: string | undefined;
- editor: Editor;
-};
-
-export const EditLinkPopover = ({
- defaultValue = '',
- editor,
-}: EditLinkPopoverProps) => {
- const instanceId = useId();
- const dropdownId = `edit-link-popover-${instanceId}`;
- const isActive = isNonEmptyString(defaultValue);
- const { t } = useLingui();
-
- const [value, setValue] = useState(defaultValue);
- const { toggleDropdown } = useToggleDropdown();
-
- const handleSubmit = (
- event: FormEvent<HTMLFormElement> | FocusEvent<HTMLInputElement>,
- ) => {
- event.preventDefault();
-
- if (!isDefined(value) || !isNonEmptyString(value)) {
- editor.chain().focus().extendMarkRange('link').unsetLink().run();
- } else {
- const href = getSafeUrl(value);
-
- if (!href) {
- return;
- }
-
- editor.chain().focus().extendMarkRange('link').setLink({ href }).run();
- }
-
- toggleDropdown({ dropdownComponentInstanceIdFromProps: dropdownId });
- };
-
- return (
- <Dropdown
- onOpen={() => {
- setValue(defaultValue);
- }}
- dropdownComponents={
- <DropdownContent>
- <DropdownMenuItemsContainer>
- <form onSubmit={handleSubmit}>
- <TextInput
- placeholder={t`Enter link`}
- value={value}
- onChange={setValue}
- onBlur={handleSubmit}
- />
- </form>
- </DropdownMenuItemsContainer>
- </DropdownContent>
- }
- dropdownId={dropdownId}
- isDropdownInModal={true}
- clickableComponent={
- <BubbleMenuIconButton
- label={isActive ? t`Edit link` : t`Add link`}
- isActive={isActive}
- Icon={isActive ? IconPencil : IconLink}
- />
- }
- />
- );
-};
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx
index 52ea12738eb..bb061f85838 100644
--- a/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx
+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx
@@ -1,8 +1,9 @@
import { t } from '@lingui/core/macro';
import { BubbleMenuIconButton } from '@/advanced-text-editor/components/BubbleMenuIconButton';
-import { EditLinkPopover } from '@/advanced-text-editor/components/EditLinkPopover';
+import { EditLinkDropdown } from '@/advanced-text-editor/components/EditLinkDropdown';
import { StyledBubbleMenuContainer } from '@/advanced-text-editor/components/StyledBubbleMenuContainer';
import { useLiveEditorState } from '@/advanced-text-editor/hooks/useLiveEditorState';
+import { getEditLinkDropdownId } from '@/advanced-text-editor/utils/getEditLinkDropdownId';
import { type Editor } from '@tiptap/core';
import { BubbleMenu } from '@tiptap/react/menus';
import { IconExternalLink, IconLinkOff } from 'twenty-ui/icon';
@@ -51,7 +52,14 @@ export const LinkBubbleMenu = ({ editor }: LinkBubbleMenuProps) => {
updateDelay={0}
>
<StyledBubbleMenuContainer>
- <EditLinkPopover defaultValue={state.linkHref} editor={editor} />
+ <EditLinkDropdown
+ dropdownId={getEditLinkDropdownId({
+ editorInstanceId: editor.instanceId,
+ bubbleMenuType: 'link',
+ })}
+ defaultValue={state.linkHref}
+ editor={editor}
+ />
{menuActions.map(({ label, Icon, onClick }) => {
return (
<BubbleMenuIconButton
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/TextBubbleMenu.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/TextBubbleMenu.tsx
index a82478c8b7d..8e536322ce3 100644
--- a/packages/twenty-front/src/modules/advanced-text-editor/components/TextBubbleMenu.tsx
+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/TextBubbleMenu.tsx
@@ -1,11 +1,12 @@
import { t } from '@lingui/core/macro';
import { StyledBubbleMenuContainer } from '@/advanced-text-editor/components/StyledBubbleMenuContainer';
import { BubbleMenuIconButton } from '@/advanced-text-editor/components/BubbleMenuIconButton';
-import { EditLinkPopover } from '@/advanced-text-editor/components/EditLinkPopover';
+import { EditLinkDropdown } from '@/advanced-text-editor/components/EditLinkDropdown';
import { TurnIntoBlockDropdown } from '@/advanced-text-editor/components/TurnIntoBlockDropdown';
import { useTextBubbleState } from '@/advanced-text-editor/hooks/useTextBubbleState';
import { hasEditorExtension } from '@/advanced-text-editor/utils/hasEditorExtension';
import { isTextSelected } from '@/advanced-text-editor/utils/isTextSelected';
+import { getEditLinkDropdownId } from '@/advanced-text-editor/utils/getEditLinkDropdownId';
import { type Editor } from '@tiptap/core';
import { NodeSelection } from '@tiptap/pm/state';
import { BubbleMenu } from '@tiptap/react/menus';
@@ -105,7 +106,14 @@ export const TextBubbleMenu = ({ editor }: TextBubbleMenuProps) => {
);
})}
{hasEditorExtension(editor, 'link') && (
- <EditLinkPopover defaultValue={state.linkHref} editor={editor} />
+ <EditLinkDropdown
+ dropdownId={getEditLinkDropdownId({
+ editorInstanceId: editor.instanceId,
+ bubbleMenuType: 'text',
+ })}
+ defaultValue={state.linkHref}
+ editor={editor}
+ />
)}
</StyledBubbleMenuContainer>
</BubbleMenu>
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/__tests__/EditLinkDropdown.test.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/__tests__/EditLinkDropdown.test.tsx
new file mode 100644
index 00000000000..72f41a6c8bd
--- /dev/null
+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/__tests__/EditLinkDropdown.test.tsx
@@ -0,0 +1,190 @@
+import { i18n } from '@lingui/core';
+import { I18nProvider } from '@lingui/react';
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { createStore, Provider } from 'jotai';
+import { type ReactNode } from 'react';
+
+import { EditLinkDropdown } from '@/advanced-text-editor/components/EditLinkDropdown';
+import { type EditLinkEditor } from '@/advanced-text-editor/types/EditLinkEditor';
+import { focusStackState } from '@/ui/utilities/focus/states/focusStackState';
+
+const renderWithStore = (children: ReactNode) => {
+ const store = createStore();
+
+ return {
+ ...render(children, {
+ wrapper: ({ children }) => (
+ <I18nProvider i18n={i18n}>
+ <Provider store={store}>{children}</Provider>
+ </I18nProvider>
+ ),
+ }),
+ store,
+ };
+};
+
+const createEditor = () => {
+ const commands: jest.Mocked<ReturnType<EditLinkEditor['chain']>> = {
+ focus: jest.fn().mockImplementation(() => {
+ setTimeout(
+ () => screen.getByRole('textbox', { name: 'Editor' }).focus(),
+ 0,
+ );
+ return commands;
+ }),
+ extendMarkRange: jest.fn().mockReturnThis(),
+ setLink: jest.fn().mockReturnThis(),
+ unsetLink: jest.fn().mockReturnThis(),
+ run: jest.fn().mockReturnValue(true),
+ };
+
+ const editor: EditLinkEditor = {
+ chain: () => commands,
+ get view() {
+ return { dom: screen.getByRole('textbox', { name: 'Editor' }) };
+ },
+ };
+
+ return { editor, commands };
+};
+
+describe('EditLinkDropdown', () => {
+ it('submits the link and preserves focus in the editor', async () => {
+ const user = userEvent.setup();
+ const { editor, commands } = createEditor();
+
+ const { store } = renderWithStore(
+ <>
+ <input aria-label="Editor" />
+ <EditLinkDropdown
+ dropdownId="edit-link-test"
+ editor={editor}
+ defaultValue=""
+ />
+ </>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Add link' }));
+ expect(store.get(focusStackState.atom)).toHaveLength(1);
+ expect(store.get(focusStackState.atom).at(-1)?.globalHotkeysConfig).toEqual(
+ {
+ enableGlobalHotkeysConflictingWithKeyboard: false,
+ enableGlobalHotkeysWithModifiers: false,
+ },
+ );
+ const input = screen.getByRole('textbox', { name: 'Enter link' });
+ await user.type(input, 'https://twenty.com{Enter}');
+
+ expect(store.get(focusStackState.atom)).toEqual([]);
+ expect(commands.setLink).toHaveBeenCalledWith({
+ href: 'https://twenty.com',
+ });
+ await waitFor(() =>
+ expect(screen.getByRole('textbox', { name: 'Editor' })).toHaveFocus(),
+ );
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+ expect(commands.setLink).toHaveBeenCalledTimes(1);
+ });
+
+ it('saves on blur without reopening the panel', async () => {
+ const user = userEvent.setup();
+ const { editor, commands } = createEditor();
+
+ const { store } = renderWithStore(
+ <>
+ <input aria-label="Editor" />
+ <button type="button">Outside</button>
+ <EditLinkDropdown
+ dropdownId="edit-link-test"
+ editor={editor}
+ defaultValue="https://old.example"
+ />
+ </>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Edit link' }));
+ expect(store.get(focusStackState.atom)).toHaveLength(1);
+ const input = screen.getByRole('textbox', { name: 'Enter link' });
+ await user.clear(input);
+ await user.type(input, 'https://new.example');
+ await user.click(screen.getByRole('button', { name: 'Outside' }));
+
+ expect(store.get(focusStackState.atom)).toEqual([]);
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ expect(commands.setLink).toHaveBeenCalledWith({
+ href: 'https://new.example',
+ });
+ expect(commands.setLink).toHaveBeenCalledTimes(1);
+ });
+
+ it('returns focus to the editor when dismissed with Escape', async () => {
+ const user = userEvent.setup();
+ const { editor } = createEditor();
+
+ renderWithStore(
+ <>
+ <input aria-label="Editor" />
+ <EditLinkDropdown
+ dropdownId="edit-link-test"
+ editor={editor}
+ defaultValue="https://twenty.com"
+ />
+ </>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Edit link' }));
+ await user.keyboard('{Escape}');
+
+ await waitFor(() =>
+ expect(screen.getByRole('textbox', { name: 'Editor' })).toHaveFocus(),
+ );
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+ });
+
+ it('removes an empty link and reloads the current link when reopened', async () => {
+ const user = userEvent.setup();
+ const { editor, commands } = createEditor();
+ const { rerender, store } = renderWithStore(
+ <>
+ <input aria-label="Editor" />
+ <EditLinkDropdown
+ dropdownId="edit-link-test"
+ editor={editor}
+ defaultValue="https://old.example"
+ />
+ </>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Edit link' }));
+ expect(store.get(focusStackState.atom)).toHaveLength(1);
+ await user.clear(screen.getByRole('textbox', { name: 'Enter link' }));
+ await user.keyboard('{Enter}');
+ expect(store.get(focusStackState.atom)).toEqual([]);
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ expect(commands.unsetLink).toHaveBeenCalled();
+ await waitFor(() =>
+ expect(screen.getByRole('textbox', { name: 'Editor' })).toHaveFocus(),
+ );
+
+ rerender(
+ <>
+ <input aria-label="Editor" />
+ <EditLinkDropdown
+ dropdownId="edit-link-test"
+ editor={editor}
+ defaultValue="https://new.example"
+ />
+ </>,
+ );
+ await user.click(screen.getByRole('button', { name: 'Edit link' }));
+ expect(store.get(focusStackState.atom)).toHaveLength(1);
+ expect(screen.getByRole('textbox', { name: 'Enter link' })).toHaveValue(
+ 'https://new.example',
+ );
+ });
+});
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/types/EditLinkEditor.ts b/packages/twenty-front/src/modules/advanced-text-editor/types/EditLinkEditor.ts
new file mode 100644
index 00000000000..363d812ed1b
--- /dev/null
+++ b/packages/twenty-front/src/modules/advanced-text-editor/types/EditLinkEditor.ts
@@ -0,0 +1,12 @@
+import { type ChainedCommands, type Editor } from '@tiptap/core';
+
+type EditLinkCommandChain = {
+ [CommandName in 'focus' | 'extendMarkRange' | 'setLink' | 'unsetLink']: (
+ ...args: Parameters<ChainedCommands[CommandName]>
+ ) => EditLinkCommandChain;
+} & Pick<ChainedCommands, 'run'>;
+
+export type EditLinkEditor = {
+ chain: () => EditLinkCommandChain;
+ view: Pick<Editor['view'], 'dom'>;
+};
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/utils/getEditLinkDropdownId.ts b/packages/twenty-front/src/modules/advanced-text-editor/utils/getEditLinkDropdownId.ts
new file mode 100644
index 00000000000..f6fceb9b7fb
--- /dev/null
+++ b/packages/twenty-front/src/modules/advanced-text-editor/utils/getEditLinkDropdownId.ts
@@ -0,0 +1,7 @@
+export const getEditLinkDropdownId = ({
+ editorInstanceId,
+ bubbleMenuType,
+}: {
+ editorInstanceId: string;
+ bubbleMenuType: 'text' | 'link';
+}) => `edit-link-dropdown-${bubbleMenuType}-${editorInstanceId}`;
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsx b/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsx
index 13188f96661..ac6508fae18 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsx
@@ -145,7 +145,7 @@ export const AiChatPageThreadHeader = ({
isArchived={Boolean(thread.deletedAt)}
surface={AI_CHAT_THREAD_ACTIONS_SURFACE.PAGE_HEADER}
onRenameRequested={startRename}
- clickableComponent={
+ trigger={
<IconButton
size="sm"
variant="outline"
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdown.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdown.tsx
index 487cb264559..5081b256248 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdown.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdown.tsx
@@ -1,14 +1,12 @@
import { useLingui } from '@lingui/react/macro';
-import { useState } from 'react';
-import { LightIconButton } from 'twenty-ui/components';
+import { Dropdown, LightIconButton } from 'twenty-ui/components';
import { IconFilter } from 'twenty-ui/icon';
import { AiChatThreadFilterDropdownContent } from '@/ai/components/AiChatThreadFilterDropdownContent';
import { AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE } from '@/ai/constants/AiChatThreadFilterDropdownPage';
import { type AiChatThreadActionsSurface } from '@/ai/types/AiChatThreadActionsSurface';
-import { type AiChatThreadFilterDropdownPage } from '@/ai/types/AiChatThreadFilterDropdownPage';
import { getAiChatThreadFilterDropdownId } from '@/ai/utils/getAiChatThreadFilterDropdownId';
-import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
type AiChatThreadFilterDropdownProps = {
surface: AiChatThreadActionsSurface;
@@ -18,35 +16,27 @@ export const AiChatThreadFilterDropdown = ({
surface,
}: AiChatThreadFilterDropdownProps) => {
const { t } = useLingui();
- const dropdownId = getAiChatThreadFilterDropdownId(surface);
- const [page, setPage] = useState<AiChatThreadFilterDropdownPage>(
- AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.ROOT,
- );
-
- const goToRoot = () => setPage(AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.ROOT);
return (
- <Dropdown
- dropdownId={dropdownId}
- dropdownPlacement="bottom-end"
- onClose={goToRoot}
- clickableComponent={
- <LightIconButton
- aria-label={t`Filter chats`}
- emphasis="subtle"
- size="sm"
- >
- <IconFilter />
- </LightIconButton>
- }
- dropdownComponents={
- <AiChatThreadFilterDropdownContent
- page={page}
- dropdownId={dropdownId}
- onSelectPage={setPage}
- onBack={goToRoot}
- />
- }
- />
+ <DropdownRoot
+ dropdownId={getAiChatThreadFilterDropdownId(surface)}
+ type="menu"
+ defaultPage={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.ROOT}
+ >
+ <Dropdown.Trigger
+ render={
+ <LightIconButton
+ aria-label={t`Filter chats`}
+ emphasis="subtle"
+ size="sm"
+ >
+ <IconFilter />
+ </LightIconButton>
+ }
+ />
+ <Dropdown.Content align="end" aria-label={t`Filter chats`}>
+ <AiChatThreadFilterDropdownContent />
+ </Dropdown.Content>
+ </DropdownRoot>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownContent.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownContent.tsx
index 48a48eea68d..4bd7f297dea 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownContent.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownContent.tsx
@@ -1,37 +1,33 @@
+import { Dropdown } from 'twenty-ui/components';
+
import { AiChatThreadFilterDropdownGroupByMenu } from '@/ai/components/AiChatThreadFilterDropdownGroupByMenu';
import { AiChatThreadFilterDropdownLastActivityMenu } from '@/ai/components/AiChatThreadFilterDropdownLastActivityMenu';
import { AiChatThreadFilterDropdownRootMenu } from '@/ai/components/AiChatThreadFilterDropdownRootMenu';
import { AiChatThreadFilterDropdownStatusMenu } from '@/ai/components/AiChatThreadFilterDropdownStatusMenu';
import { AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE } from '@/ai/constants/AiChatThreadFilterDropdownPage';
-import { type AiChatThreadFilterDropdownPage } from '@/ai/types/AiChatThreadFilterDropdownPage';
-
-type AiChatThreadFilterDropdownContentProps = {
- page: AiChatThreadFilterDropdownPage;
- dropdownId: string;
- onSelectPage: (page: AiChatThreadFilterDropdownPage) => void;
- onBack: () => void;
-};
-export const AiChatThreadFilterDropdownContent = ({
- page,
- dropdownId,
- onSelectPage,
- onBack,
-}: AiChatThreadFilterDropdownContentProps) => {
- switch (page) {
- case AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.STATUS:
- return <AiChatThreadFilterDropdownStatusMenu onBack={onBack} />;
- case AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.GROUP_BY:
- return <AiChatThreadFilterDropdownGroupByMenu onBack={onBack} />;
- case AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.LAST_ACTIVITY:
- return <AiChatThreadFilterDropdownLastActivityMenu onBack={onBack} />;
- case AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.ROOT:
- default:
- return (
- <AiChatThreadFilterDropdownRootMenu
- dropdownId={dropdownId}
- onSelectPage={onSelectPage}
- />
- );
- }
-};
+export const AiChatThreadFilterDropdownContent = () => (
+ <>
+ <Dropdown.Page id={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.ROOT} type="menu">
+ <AiChatThreadFilterDropdownRootMenu />
+ </Dropdown.Page>
+ <Dropdown.Page
+ id={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.STATUS}
+ type="picker"
+ >
+ <AiChatThreadFilterDropdownStatusMenu />
+ </Dropdown.Page>
+ <Dropdown.Page
+ id={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.GROUP_BY}
+ type="picker"
+ >
+ <AiChatThreadFilterDropdownGroupByMenu />
+ </Dropdown.Page>
+ <Dropdown.Page
+ id={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.LAST_ACTIVITY}
+ type="picker"
+ >
+ <AiChatThreadFilterDropdownLastActivityMenu />
+ </Dropdown.Page>
+ </>
+);
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownGroupByMenu.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownGroupByMenu.tsx
index 0d70e04fb89..1a0bc156d40 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownGroupByMenu.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownGroupByMenu.tsx
@@ -1,63 +1,38 @@
+import { useLingui } from '@lingui/react/macro';
+import { Dropdown } from 'twenty-ui/components';
+
import { AGENT_CHAT_THREAD_GROUP_BY } from '@/ai/constants/AgentChatThreadGroupBy';
import { AGENT_CHAT_THREAD_GROUP_BY_LABELS } from '@/ai/constants/AgentChatThreadGroupByLabels';
import { agentChatThreadGroupByState } from '@/ai/states/agentChatThreadGroupByState';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader/DropdownMenuHeader';
-import { DropdownMenuHeaderLeftComponent } from '@/ui/layout/dropdown/components/DropdownMenuHeader/internal/DropdownMenuHeaderLeftComponent';
-import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
-import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { useLingui } from '@lingui/react/macro';
-import { IconChevronLeft } from 'twenty-ui/icon';
-import { ListItem } from 'twenty-ui/primitives/navigation';
const AGENT_CHAT_THREAD_GROUP_BY_OPTIONS = [
AGENT_CHAT_THREAD_GROUP_BY.DATE,
AGENT_CHAT_THREAD_GROUP_BY.NONE,
] as const;
-type AiChatThreadFilterDropdownGroupByMenuProps = {
- onBack: () => void;
-};
-
-export const AiChatThreadFilterDropdownGroupByMenu = ({
- onBack,
-}: AiChatThreadFilterDropdownGroupByMenuProps) => {
+export const AiChatThreadFilterDropdownGroupByMenu = () => {
const { t } = useLingui();
- const { closeDropdown } = useCloseDropdown();
const [agentChatThreadGroupBy, setAgentChatThreadGroupBy] = useAtomState(
agentChatThreadGroupByState,
);
return (
- <DropdownContent>
- <DropdownMenuHeader
- StartComponent={
- <DropdownMenuHeaderLeftComponent
- onClick={onBack}
- Icon={IconChevronLeft}
- />
- }
- >
- {t`Group by`}
- </DropdownMenuHeader>
- <DropdownMenuItemsContainer>
+ <>
+ <Dropdown.Back>{t`Group by`}</Dropdown.Back>
+ <Dropdown.Section>
{AGENT_CHAT_THREAD_GROUP_BY_OPTIONS.map((option) => (
- <ListItem
+ <Dropdown.OptionItem
key={option}
- onClick={() => {
+ onSelect={() => {
setAgentChatThreadGroupBy(option);
- closeDropdown();
}}
- role="option"
- aria-selected={agentChatThreadGroupBy === option}
selected={agentChatThreadGroupBy === option}
- indicator="check"
>
{t(AGENT_CHAT_THREAD_GROUP_BY_LABELS[option])}
- </ListItem>
+ </Dropdown.OptionItem>
))}
- </DropdownMenuItemsContainer>
- </DropdownContent>
+ </Dropdown.Section>
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownLastActivityMenu.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownLastActivityMenu.tsx
index 6d180b19499..746ebed87b9 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownLastActivityMenu.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownLastActivityMenu.tsx
@@ -1,15 +1,10 @@
+import { useLingui } from '@lingui/react/macro';
+import { Dropdown } from 'twenty-ui/components';
+
import { AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER } from '@/ai/constants/AgentChatThreadLastActivityFilter';
import { AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER_LABELS } from '@/ai/constants/AgentChatThreadLastActivityFilterLabels';
import { agentChatThreadLastActivityFilterState } from '@/ai/states/agentChatThreadLastActivityFilterState';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader/DropdownMenuHeader';
-import { DropdownMenuHeaderLeftComponent } from '@/ui/layout/dropdown/components/DropdownMenuHeader/internal/DropdownMenuHeaderLeftComponent';
-import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
-import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { useLingui } from '@lingui/react/macro';
-import { IconChevronLeft } from 'twenty-ui/icon';
-import { ListItem } from 'twenty-ui/primitives/navigation';
const AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER_OPTIONS = [
AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER.ONE_DAY,
@@ -19,49 +14,29 @@ const AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER_OPTIONS = [
AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER.ALL,
] as const;
-type AiChatThreadFilterDropdownLastActivityMenuProps = {
- onBack: () => void;
-};
-
-export const AiChatThreadFilterDropdownLastActivityMenu = ({
- onBack,
-}: AiChatThreadFilterDropdownLastActivityMenuProps) => {
+export const AiChatThreadFilterDropdownLastActivityMenu = () => {
const { t } = useLingui();
- const { closeDropdown } = useCloseDropdown();
const [
agentChatThreadLastActivityFilter,
setAgentChatThreadLastActivityFilter,
] = useAtomState(agentChatThreadLastActivityFilterState);
return (
- <DropdownContent>
- <DropdownMenuHeader
- StartComponent={
- <DropdownMenuHeaderLeftComponent
- onClick={onBack}
- Icon={IconChevronLeft}
- />
- }
- >
- {t`Last activity`}
- </DropdownMenuHeader>
- <DropdownMenuItemsContainer>
+ <>
+ <Dropdown.Back>{t`Last activity`}</Dropdown.Back>
+ <Dropdown.Section>
{AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER_OPTIONS.map((option) => (
- <ListItem
+ <Dropdown.OptionItem
key={option}
- onClick={() => {
+ onSelect={() => {
setAgentChatThreadLastActivityFilter(option);
- closeDropdown();
}}
- role="option"
- aria-selected={agentChatThreadLastActivityFilter === option}
selected={agentChatThreadLastActivityFilter === option}
- indicator="check"
>
{t(AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER_LABELS[option])}
- </ListItem>
+ </Dropdown.OptionItem>
))}
- </DropdownMenuItemsContainer>
- </DropdownContent>
+ </Dropdown.Section>
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownRootMenu.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownRootMenu.tsx
index f4ccf73b187..af45c696396 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownRootMenu.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownRootMenu.tsx
@@ -1,4 +1,4 @@
-import { ListItem } from 'twenty-ui/primitives/navigation';
+import { Dropdown } from 'twenty-ui/components';
import { useLingui } from '@lingui/react/macro';
import {
IconClock,
@@ -14,27 +14,13 @@ import { AGENT_CHAT_THREAD_GROUP_BY_LABELS } from '@/ai/constants/AgentChatThrea
import { AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER } from '@/ai/constants/AgentChatThreadLastActivityFilter';
import { AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER_LABELS } from '@/ai/constants/AgentChatThreadLastActivityFilterLabels';
import { AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE } from '@/ai/constants/AiChatThreadFilterDropdownPage';
-import { type AiChatThreadFilterDropdownPage } from '@/ai/types/AiChatThreadFilterDropdownPage';
import { agentChatThreadFilterStatusState } from '@/ai/states/agentChatThreadFilterStatusState';
import { agentChatThreadGroupByState } from '@/ai/states/agentChatThreadGroupByState';
import { agentChatThreadLastActivityFilterState } from '@/ai/states/agentChatThreadLastActivityFilterState';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
-import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownMenuSeparator';
-import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-type AiChatThreadFilterDropdownRootMenuProps = {
- dropdownId: string;
- onSelectPage: (page: AiChatThreadFilterDropdownPage) => void;
-};
-
-export const AiChatThreadFilterDropdownRootMenu = ({
- dropdownId,
- onSelectPage,
-}: AiChatThreadFilterDropdownRootMenuProps) => {
+export const AiChatThreadFilterDropdownRootMenu = () => {
const { t } = useLingui();
- const { closeDropdown } = useCloseDropdown();
const [agentChatThreadFilterStatus, setAgentChatThreadFilterStatus] =
useAtomState(agentChatThreadFilterStatusState);
@@ -58,35 +44,30 @@ export const AiChatThreadFilterDropdownRootMenu = ({
setAgentChatThreadLastActivityFilter(
AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER.ALL,
);
- closeDropdown(dropdownId);
};
return (
- <DropdownContent>
- <DropdownMenuItemsContainer>
- <ListItem
+ <>
+ <Dropdown.Section>
+ <Dropdown.ActionItem
startIcon={<IconStatusChange />}
description={t(
AGENT_CHAT_THREAD_FILTER_STATUS_LABELS[agentChatThreadFilterStatus],
)}
descriptionPlacement="end"
hasSubmenu
- onClick={() =>
- onSelectPage(AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.STATUS)
- }
- >{t`Status`}</ListItem>
- <ListItem
+ page={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.STATUS}
+ >{t`Status`}</Dropdown.ActionItem>
+ <Dropdown.ActionItem
startIcon={<IconLayoutList />}
description={t(
AGENT_CHAT_THREAD_GROUP_BY_LABELS[agentChatThreadGroupBy],
)}
descriptionPlacement="end"
hasSubmenu
- onClick={() =>
- onSelectPage(AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.GROUP_BY)
- }
- >{t`Group by`}</ListItem>
- <ListItem
+ page={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.GROUP_BY}
+ >{t`Group by`}</Dropdown.ActionItem>
+ <Dropdown.ActionItem
startIcon={<IconClock />}
description={t(
AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER_LABELS[
@@ -95,21 +76,19 @@ export const AiChatThreadFilterDropdownRootMenu = ({
)}
descriptionPlacement="end"
hasSubmenu
- onClick={() =>
- onSelectPage(AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.LAST_ACTIVITY)
- }
- >{t`Last activity`}</ListItem>
+ page={AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE.LAST_ACTIVITY}
+ >{t`Last activity`}</Dropdown.ActionItem>
{!isAtDefaults && (
<>
- <DropdownMenuSeparator />
- <ListItem
+ <Dropdown.Separator />
+ <Dropdown.ActionItem
color="danger"
startIcon={<IconTrash />}
onClick={handleClearFilters}
- >{t`Clear filters`}</ListItem>
+ >{t`Clear filters`}</Dropdown.ActionItem>
</>
)}
- </DropdownMenuItemsContainer>
- </DropdownContent>
+ </Dropdown.Section>
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownStatusMenu.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownStatusMenu.tsx
index 1334452174e..659e3c1862a 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownStatusMenu.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadFilterDropdownStatusMenu.tsx
@@ -1,15 +1,10 @@
+import { useLingui } from '@lingui/react/macro';
+import { Dropdown } from 'twenty-ui/components';
+
import { AGENT_CHAT_THREAD_FILTER_STATUS } from '@/ai/constants/AgentChatThreadFilterStatus';
import { AGENT_CHAT_THREAD_FILTER_STATUS_LABELS } from '@/ai/constants/AgentChatThreadFilterStatusLabels';
import { agentChatThreadFilterStatusState } from '@/ai/states/agentChatThreadFilterStatusState';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader/DropdownMenuHeader';
-import { DropdownMenuHeaderLeftComponent } from '@/ui/layout/dropdown/components/DropdownMenuHeader/internal/DropdownMenuHeaderLeftComponent';
-import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
-import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { useLingui } from '@lingui/react/macro';
-import { IconChevronLeft } from 'twenty-ui/icon';
-import { ListItem } from 'twenty-ui/primitives/navigation';
const AGENT_CHAT_THREAD_FILTER_STATUS_OPTIONS = [
AGENT_CHAT_THREAD_FILTER_STATUS.ACTIVE,
@@ -17,47 +12,27 @@ const AGENT_CHAT_THREAD_FILTER_STATUS_OPTIONS = [
AGENT_CHAT_THREAD_FILTER_STATUS.ALL,
] as const;
-type AiChatThreadFilterDropdownStatusMenuProps = {
- onBack: () => void;
-};
-
-export const AiChatThreadFilterDropdownStatusMenu = ({
- onBack,
-}: AiChatThreadFilterDropdownStatusMenuProps) => {
+export const AiChatThreadFilterDropdownStatusMenu = () => {
const { t } = useLingui();
- const { closeDropdown } = useCloseDropdown();
const [agentChatThreadFilterStatus, setAgentChatThreadFilterStatus] =
useAtomState(agentChatThreadFilterStatusState);
return (
- <DropdownContent>
- <DropdownMenuHeader
- StartComponent={
- <DropdownMenuHeaderLeftComponent
- onClick={onBack}
- Icon={IconChevronLeft}
- />
- }
- >
- {t`Status`}
- </DropdownMenuHeader>
- <DropdownMenuItemsContainer>
+ <>
+ <Dropdown.Back>{t`Status`}</Dropdown.Back>
+ <Dropdown.Section>
{AGENT_CHAT_THREAD_FILTER_STATUS_OPTIONS.map((option) => (
- <ListItem
+ <Dropdown.OptionItem
key={option}
- onClick={() => {
+ onSelect={() => {
setAgentChatThreadFilterStatus(option);
- closeDropdown();
}}
- role="option"
- aria-selected={agentChatThreadFilterStatus === option}
selected={agentChatThreadFilterStatus === option}
- indicator="check"
>
{t(AGENT_CHAT_THREAD_FILTER_STATUS_LABELS[option])}
- </ListItem>
+ </Dropdown.OptionItem>
))}
- </DropdownMenuItemsContainer>
- </DropdownContent>
+ </Dropdown.Section>
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadItemMenu.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadItemMenu.tsx
index 24fcba37b27..1dc02ff68e0 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadItemMenu.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadItemMenu.tsx
@@ -1,6 +1,5 @@
-import { ListItem } from 'twenty-ui/primitives/navigation';
import { useLingui } from '@lingui/react/macro';
-import { type ReactNode } from 'react';
+import { type ReactElement } from 'react';
import {
IconArchive,
IconArchiveOff,
@@ -8,17 +7,14 @@ import {
IconPencil,
IconTrash,
} from 'twenty-ui/icon';
-import { LightIconButton } from 'twenty-ui/components';
+import { Dropdown, LightIconButton } from 'twenty-ui/components';
import { type AiChatThreadActionsSurface } from '@/ai/types/AiChatThreadActionsSurface';
import { useChatThreadArchiveActions } from '@/ai/hooks/useChatThreadArchiveActions';
import { aiChatThreadPendingDeleteFamilyState } from '@/ai/states/aiChatThreadPendingDeleteFamilyState';
import { getAiChatThreadDeleteModalId } from '@/ai/utils/getAiChatThreadDeleteModalId';
import { getAiChatThreadItemMenuDropdownId } from '@/ai/utils/getAiChatThreadItemMenuDropdownId';
-import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
-import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
import { useDialog } from '@/ui/layout/dialog/hooks/useDialog';
import { useSetAtomFamilyState } from '@/ui/utilities/state/jotai/hooks/useSetAtomFamilyState';
@@ -28,7 +24,7 @@ type AiChatThreadItemMenuProps = {
isArchived: boolean;
surface: AiChatThreadActionsSurface;
onRenameRequested: () => void;
- clickableComponent?: ReactNode;
+ trigger?: ReactElement;
};
export const AiChatThreadItemMenu = ({
@@ -37,11 +33,9 @@ export const AiChatThreadItemMenu = ({
isArchived,
surface,
onRenameRequested,
- clickableComponent,
+ trigger,
}: AiChatThreadItemMenuProps) => {
const { t } = useLingui();
- const dropdownId = getAiChatThreadItemMenuDropdownId(threadId, surface);
- const { closeDropdown } = useCloseDropdown();
const { openDialog } = useDialog();
const { archiveChatThread, unarchiveChatThread } =
useChatThreadArchiveActions();
@@ -52,59 +46,62 @@ export const AiChatThreadItemMenu = ({
const handleRename = (event: React.MouseEvent) => {
event.stopPropagation();
- closeDropdown(dropdownId);
onRenameRequested();
};
const handleArchive = async (event: React.MouseEvent) => {
event.stopPropagation();
- closeDropdown(dropdownId);
if (isArchived) {
await unarchiveChatThread(threadId);
- } else {
- await archiveChatThread(threadId);
+ return;
}
+
+ await archiveChatThread(threadId);
};
const handleDelete = (event: React.MouseEvent) => {
event.stopPropagation();
- closeDropdown(dropdownId);
setAiChatThreadPendingDelete({ threadId, threadTitle });
openDialog(getAiChatThreadDeleteModalId(surface));
};
return (
- <Dropdown
- dropdownId={dropdownId}
- dropdownPlacement="bottom-end"
- clickableComponent={
- clickableComponent ?? (
- <LightIconButton aria-label={t`Chat actions`} emphasis="subtle">
- <IconDotsVertical />
- </LightIconButton>
- )
- }
- dropdownComponents={
- <DropdownContent>
- <DropdownMenuItemsContainer>
- <ListItem
- startIcon={<IconPencil />}
- onClick={handleRename}
- >{t`Rename`}</ListItem>
- <ListItem
- startIcon={isArchived ? <IconArchiveOff /> : <IconArchive />}
- onClick={handleArchive}
- >
- {isArchived ? t`Unarchive` : t`Archive`}
- </ListItem>
- <ListItem
- color="danger"
- startIcon={<IconTrash />}
- onClick={handleDelete}
- >{t`Delete`}</ListItem>
- </DropdownMenuItemsContainer>
- </DropdownContent>
- }
- />
+ <DropdownRoot
+ dropdownId={getAiChatThreadItemMenuDropdownId({ threadId, surface })}
+ type="menu"
+ >
+ <Dropdown.Trigger
+ render={
+ trigger ?? (
+ <LightIconButton aria-label={t`Chat actions`} emphasis="subtle">
+ <IconDotsVertical />
+ </LightIconButton>
+ )
+ }
+ />
+ <Dropdown.Content align="end" aria-label={t`Chat actions`}>
+ <Dropdown.Section>
+ <Dropdown.ActionItem
+ startIcon={<IconPencil />}
+ onClick={handleRename}
+ >
+ {t`Rename`}
+ </Dropdown.ActionItem>
+ <Dropdown.ActionItem
+ startIcon={isArchived ? <IconArchiveOff /> : <IconArchive />}
+ onClick={handleArchive}
+ >
+ {isArchived ? t`Unarchive` : t`Archive`}
+ </Dropdown.ActionItem>
+ <Dropdown.ActionItem
+ color="danger"
+ startIcon={<IconTrash />}
+ onClick={handleDelete}
+ >
+ {t`Delete`}
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </DropdownRoot>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx
index 8f52274d151..1de8807f8d2 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatThreadListItem.tsx
@@ -100,15 +100,13 @@ export const AiChatThreadListItem = ({ thread }: AiChatThreadListItemProps) => {
const isArchived = Boolean(thread.deletedAt);
const ThreadIcon = isArchived ? IconArchive : IconSparkles;
const displayTitle = thread.title ?? t`Untitled`;
- const itemMenuDropdownId = getAiChatThreadItemMenuDropdownId(
- thread.id,
- AI_CHAT_THREAD_ACTIONS_SURFACE.SIDE_PANEL,
- );
const isDropdownOpen = useAtomComponentStateValue(
isDropdownOpenComponentState,
- itemMenuDropdownId,
+ getAiChatThreadItemMenuDropdownId({
+ threadId: thread.id,
+ surface: AI_CHAT_THREAD_ACTIONS_SURFACE.SIDE_PANEL,
+ }),
);
-
return (
<StyledThreadItem
onClick={() => {
diff --git a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsx b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsx
index bb19433b814..85f78871ca2 100644
--- a/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsx
+++ b/packages/twenty-front/src/modules/ai/components/NavigationDrawerAiChatThreadItem.tsx
@@ -7,9 +7,9 @@ import { AI_CHAT_THREAD_ACTIONS_SURFACE } from '@/ai/constants/AiChatThreadActio
import { useAiChatThreadRename } from '@/ai/hooks/useAiChatThreadRename';
import { getAiChatThreadItemMenuDropdownId } from '@/ai/utils/getAiChatThreadItemMenuDropdownId';
import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { NavigationDrawerInput } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerInput';
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
-import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { type AgentChatThread } from '~/generated-metadata/graphql';
type NavigationDrawerAiChatThreadItemProps = {
@@ -36,15 +36,13 @@ export const NavigationDrawerAiChatThreadItem = ({
const isArchived = Boolean(thread.deletedAt);
const displayLabel = thread.title || t`New chat`;
- const itemMenuDropdownId = getAiChatThreadItemMenuDropdownId(
- thread.id,
- AI_CHAT_THREAD_ACTIONS_SURFACE.NAV_DRAWER,
- );
const isDropdownOpen = useAtomComponentStateValue(
isDropdownOpenComponentState,
- itemMenuDropdownId,
+ getAiChatThreadItemMenuDropdownId({
+ threadId: thread.id,
+ surface: AI_CHAT_THREAD_ACTIONS_SURFACE.NAV_DRAWER,
+ }),
);
-
if (isRenaming && isExpanded) {
return (
<NavigationDrawerInput
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx
index a5ca7b847eb..dfb204c475b 100644
--- a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx
@@ -1,6 +1,6 @@
import { i18n } from '@lingui/core';
import { I18nProvider } from '@lingui/react';
-import { act, render, screen, within } from '@testing-library/react';
+import { act, render, screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Provider as JotaiProvider } from 'jotai';
import { type ReactNode } from 'react';
@@ -220,6 +220,7 @@ describe('AiChatPageHeader', () => {
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Rename'));
expect(screen.getByRole('textbox')).toHaveValue('Generated title');
+ await waitFor(() => expect(screen.getByRole('textbox')).toHaveFocus());
await user.keyboard('{Enter}');
expect(renameChatThread).not.toHaveBeenCalled();
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadFilterDropdown.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadFilterDropdown.test.tsx
new file mode 100644
index 00000000000..5f547359699
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadFilterDropdown.test.tsx
@@ -0,0 +1,88 @@
+import { i18n } from '@lingui/core';
+import { I18nProvider } from '@lingui/react';
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { createStore, Provider } from 'jotai';
+
+import { AiChatThreadFilterDropdown } from '@/ai/components/AiChatThreadFilterDropdown';
+import { AGENT_CHAT_THREAD_FILTER_STATUS } from '@/ai/constants/AgentChatThreadFilterStatus';
+import { AGENT_CHAT_THREAD_GROUP_BY } from '@/ai/constants/AgentChatThreadGroupBy';
+import { AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER } from '@/ai/constants/AgentChatThreadLastActivityFilter';
+import { AI_CHAT_THREAD_ACTIONS_SURFACE } from '@/ai/constants/AiChatThreadActionsSurface';
+import { agentChatThreadFilterStatusState } from '@/ai/states/agentChatThreadFilterStatusState';
+import { agentChatThreadGroupByState } from '@/ai/states/agentChatThreadGroupByState';
+import { agentChatThreadLastActivityFilterState } from '@/ai/states/agentChatThreadLastActivityFilterState';
+import { focusStackState } from '@/ui/utilities/focus/states/focusStackState';
+
+const renderFilterDropdown = () => {
+ const store = createStore();
+ store.set(
+ agentChatThreadFilterStatusState.atom,
+ AGENT_CHAT_THREAD_FILTER_STATUS.ACTIVE,
+ );
+ store.set(agentChatThreadGroupByState.atom, AGENT_CHAT_THREAD_GROUP_BY.DATE);
+ store.set(
+ agentChatThreadLastActivityFilterState.atom,
+ AGENT_CHAT_THREAD_LAST_ACTIVITY_FILTER.ALL,
+ );
+
+ render(
+ <I18nProvider i18n={i18n}>
+ <Provider store={store}>
+ <AiChatThreadFilterDropdown
+ surface={AI_CHAT_THREAD_ACTIONS_SURFACE.NAV_DRAWER}
+ />
+ </Provider>
+ </I18nProvider>,
+ );
+
+ return { store, user: userEvent.setup() };
+};
+
+describe('AiChatThreadFilterDropdown', () => {
+ it('applies a filter, restores the trigger, and reopens at the root page', async () => {
+ const { store, user } = renderFilterDropdown();
+ const trigger = screen.getByRole('button', { name: 'Filter chats' });
+
+ await user.click(trigger);
+ await user.click(await screen.findByRole('menuitem', { name: /Status/ }));
+ await user.click(await screen.findByRole('button', { name: 'Archived' }));
+
+ expect(store.get(agentChatThreadFilterStatusState.atom)).toBe('archived');
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ await waitFor(() => expect(trigger).toHaveFocus());
+ await waitFor(() => expect(store.get(focusStackState.atom)).toEqual([]));
+
+ await user.click(trigger);
+ expect(
+ await screen.findByRole('menuitem', { name: /Status Archived/ }),
+ ).toBeVisible();
+ await user.click(screen.getByRole('menuitem', { name: 'Clear filters' }));
+ expect(store.get(agentChatThreadFilterStatusState.atom)).toBe('active');
+ });
+
+ it('returns from a picker without changing its value and releases shortcut scope on dismissal', async () => {
+ const { store, user } = renderFilterDropdown();
+ await user.click(screen.getByRole('button', { name: 'Filter chats' }));
+ await user.click(await screen.findByRole('menuitem', { name: /Group by/ }));
+ expect(
+ await screen.findByRole('button', { name: 'Date', pressed: true }),
+ ).toBeVisible();
+ expect(store.get(focusStackState.atom).at(-1)?.globalHotkeysConfig).toEqual(
+ {
+ enableGlobalHotkeysConflictingWithKeyboard: false,
+ enableGlobalHotkeysWithModifiers: false,
+ },
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Group by' }));
+ expect(
+ await screen.findByRole('menuitem', { name: /Group by/ }),
+ ).toHaveFocus();
+ expect(store.get(agentChatThreadGroupByState.atom)).toBe('date');
+ await user.keyboard('{Escape}');
+ await waitFor(() => expect(store.get(focusStackState.atom)).toEqual([]));
+ });
+});
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadItemMenu.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadItemMenu.test.tsx
new file mode 100644
index 00000000000..3d1bdd841f2
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadItemMenu.test.tsx
@@ -0,0 +1,95 @@
+import { i18n } from '@lingui/core';
+import { I18nProvider } from '@lingui/react';
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { createStore, Provider } from 'jotai';
+import { MemoryRouter, useLocation } from 'react-router-dom';
+import { IconButton } from 'twenty-ui/components';
+import { IconDotsVertical } from 'twenty-ui/icon';
+
+import { AiChatThreadItemMenu } from '@/ai/components/AiChatThreadItemMenu';
+import { AI_CHAT_THREAD_ACTIONS_SURFACE } from '@/ai/constants/AiChatThreadActionsSurface';
+import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
+
+const archiveChatThread = jest.fn();
+const unarchiveChatThread = jest.fn();
+
+jest.mock('@/ai/hooks/useChatThreadArchiveActions', () => ({
+ useChatThreadArchiveActions: () => ({
+ archiveChatThread,
+ unarchiveChatThread,
+ }),
+}));
+
+jest.mock('@/ui/layout/dialog/hooks/useDialog', () => ({
+ useDialog: () => ({ openDialog: jest.fn() }),
+}));
+
+jest.mock('@/navigation/hooks/useIsNavigationDrawerContentExpanded', () => ({
+ useIsNavigationDrawerContentExpanded: () => true,
+}));
+
+jest.mock('@/ui/utilities/responsive/hooks/useIsMobile', () => ({
+ useIsMobile: () => false,
+}));
+
+const CurrentLocation = () => {
+ const location = useLocation();
+
+ return <output aria-label="Current location">{location.pathname}</output>;
+};
+
+it.each([
+ { label: 'unlinked', to: undefined },
+ { label: 'linked', to: '/chat' },
+])(
+ 'keeps $label drawer menu actions local and closes during an archive request',
+ async ({ to }) => {
+ const user = userEvent.setup();
+ const onRowClick = jest.fn();
+ archiveChatThread.mockReturnValue(new Promise(() => {}));
+
+ render(
+ <I18nProvider i18n={i18n}>
+ <Provider store={createStore()}>
+ <MemoryRouter initialEntries={['/initial']}>
+ <CurrentLocation />
+ <NavigationDrawerItem
+ label="Leads"
+ to={to}
+ onClick={onRowClick}
+ rightOptions={
+ <AiChatThreadItemMenu
+ threadId="thread-archive"
+ threadTitle="Leads"
+ isArchived={false}
+ surface={AI_CHAT_THREAD_ACTIONS_SURFACE.NAV_DRAWER}
+ onRenameRequested={jest.fn()}
+ trigger={
+ <IconButton aria-label="Chat actions" variant="outline">
+ <IconDotsVertical />
+ </IconButton>
+ }
+ />
+ }
+ />
+ </MemoryRouter>
+ </Provider>
+ </I18nProvider>,
+ );
+
+ const trigger = screen.getByRole('button', { name: 'Chat actions' });
+ await user.click(trigger);
+ await user.click(await screen.findByRole('menuitem', { name: 'Archive' }));
+
+ expect(archiveChatThread).toHaveBeenCalledWith('thread-archive');
+ expect(onRowClick).not.toHaveBeenCalled();
+ expect(
+ screen.getByRole('status', { name: 'Current location' }),
+ ).toHaveTextContent('/initial');
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ await waitFor(() => expect(trigger).toHaveFocus());
+ },
+);
diff --git a/packages/twenty-front/src/modules/ai/types/AiChatThreadFilterDropdownPage.ts b/packages/twenty-front/src/modules/ai/types/AiChatThreadFilterDropdownPage.ts
deleted file mode 100644
index 3c3a6b069b7..00000000000
--- a/packages/twenty-front/src/modules/ai/types/AiChatThreadFilterDropdownPage.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { type AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE } from '@/ai/constants/AiChatThreadFilterDropdownPage';
-
-export type AiChatThreadFilterDropdownPage =
- (typeof AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE)[keyof typeof AI_CHAT_THREAD_FILTER_DROPDOWN_PAGE];
diff --git a/packages/twenty-front/src/modules/ai/utils/getAiChatThreadItemMenuDropdownId.ts b/packages/twenty-front/src/modules/ai/utils/getAiChatThreadItemMenuDropdownId.ts
index 8b42607805d..5a2cc7a083b 100644
--- a/packages/twenty-front/src/modules/ai/utils/getAiChatThreadItemMenuDropdownId.ts
+++ b/packages/twenty-front/src/modules/ai/utils/getAiChatThreadItemMenuDropdownId.ts
@@ -1,6 +1,9 @@
import { type AiChatThreadActionsSurface } from '@/ai/types/AiChatThreadActionsSurface';
-export const getAiChatThreadItemMenuDropdownId = (
- threadId: string,
- surface: AiChatThreadActionsSurface,
-) => `ai-chat-thread-item-menu-${surface}-${threadId}`;
+export const getAiChatThreadItemMenuDropdownId = ({
+ threadId,
+ surface,
+}: {
+ threadId: string;
+ surface: AiChatThreadActionsSurface;
+}) => `ai-chat-thread-item-menu-${surface}-${threadId}`;
diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/MultiSelectAddressFields.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/MultiSelectAddressFields.tsx
index 4274c5139d4..5af72807e36 100644
--- a/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/MultiSelectAddressFields.tsx
+++ b/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/MultiSelectAddressFields.tsx
@@ -1,139 +1,131 @@
-import { ListItem } from 'twenty-ui/primitives/navigation';
+import { SelectControl } from '@/ui/input/components/SelectControl';
+import { type SelectSizeVariant } from '@/ui/input/components/Select';
import { SelectOptionIcon } from '@/ui/input/components/SelectOptionIcon';
-import { Tag } from 'twenty-ui/primitives/data-display';
import { type SelectValue } from '@/ui/input/components/internal/select/types';
-import { type SelectSizeVariant } from '@/ui/input/components/Select';
-import { SelectControl } from '@/ui/input/components/SelectControl';
-import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
-import { DropdownMenuSearchInput } from '@/ui/layout/dropdown/components/DropdownMenuSearchInput';
-import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownMenuSeparator';
-import { GenericDropdownContentWidth } from '@/ui/layout/dropdown/constants/GenericDropdownContentWidth';
-import { SelectableList } from '@/ui/layout/selectable-list/components/SelectableList';
-import { SelectableListItem } from '@/ui/layout/selectable-list/components/SelectableListItem';
+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
import { t } from '@lingui/core/macro';
-import { type MouseEvent, useMemo, useState } from 'react';
+import { isNonEmptyString } from '@sniptt/guards';
+import { type MouseEvent, useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { Dropdown } from 'twenty-ui/components';
import { type IconComponent } from 'twenty-ui/icon';
+import { Tag } from 'twenty-ui/primitives/data-display';
import { type SelectOption } from 'twenty-ui/primitives/input';
type CallToActionButton = {
text: string;
- onClick: (event: MouseEvent<HTMLDivElement>) => void;
+ onClick: (event: MouseEvent<HTMLElement>) => void;
Icon?: IconComponent;
};
-export type MultiSelectAddressFieldsProps<Value extends SelectValue> = {
+type MultiSelectAddressFieldsProps<TValue extends SelectValue> = {
+ dropdownId: string;
className?: string;
disabled?: boolean;
selectSizeVariant?: SelectSizeVariant;
- dropdownId: string;
dropdownWidth?: number;
- onChange?: (values: Value[]) => void;
- options: SelectOption<Value>[];
- values: Value[];
+ onChange?: (values: TValue[]) => void;
+ options: SelectOption<TValue>[];
+ values: TValue[];
callToActionButton?: CallToActionButton;
};
-export const MultiSelectAddressFields = <Value extends SelectValue>({
- className: _className,
- selectSizeVariant,
+export const MultiSelectAddressFields = <TValue extends SelectValue>({
dropdownId,
- dropdownWidth = GenericDropdownContentWidth.Medium,
+ className,
+ disabled = false,
+ selectSizeVariant,
+ dropdownWidth,
onChange,
options,
values,
callToActionButton,
-}: MultiSelectAddressFieldsProps<Value>) => {
+}: MultiSelectAddressFieldsProps<TValue>) => {
const [searchInputValue, setSearchInputValue] = useState('');
- const filteredOptions = useMemo(
- () =>
- searchInputValue
- ? options.filter(({ label }) =>
- label.toLowerCase().includes(searchInputValue.toLowerCase()),
- )
- : options,
- [options, searchInputValue],
- );
- const onOptionSelected = (value: Value, values: Value[]) => {
- if (!values.includes(value)) {
- return [...values, value];
- } else {
- return values.filter((val) => val !== value);
- }
- };
- const selectableItemIdArray = filteredOptions.map((option) => option.label);
- const onCloseDropdown = () => {
- setSearchInputValue('');
+ const filteredOptions = isNonEmptyString(searchInputValue)
+ ? options.filter(({ label }) =>
+ label.toLowerCase().includes(searchInputValue.toLowerCase()),
+ )
+ : options;
+
+ const handleOptionSelected = (value: TValue) => {
+ const nextValues = values.includes(value)
+ ? values.filter((selectedValue) => selectedValue !== value)
+ : [...values, value];
+
+ onChange?.(nextValues);
};
+
return (
- <Dropdown
+ <DropdownRoot
dropdownId={dropdownId}
- onClose={onCloseDropdown}
- clickableComponent={
+ type="picker"
+ multiple
+ onOpenChange={(open) => {
+ if (!open) {
+ setSearchInputValue('');
+ }
+ }}
+ >
+ <Dropdown.Trigger
+ className={className}
+ render={<div />}
+ nativeButton={false}
+ disabled={disabled}
+ aria-label={t`Select address fields`}
+ >
<SelectControl
selectedOption={{
label:
- values?.length === options.length
+ values.length === options.length
? t`Default`
- : values?.length.toString(),
- value: values?.length,
+ : values.length.toString(),
+ value: values.length,
}}
selectSizeVariant={selectSizeVariant}
+ isDisabled={disabled}
+ />
+ </Dropdown.Trigger>
+ <Dropdown.Content
+ width={dropdownWidth}
+ sideOffset={0}
+ align="end"
+ aria-label={t`Select address fields`}
+ >
+ <Dropdown.Search
+ value={searchInputValue}
+ onValueChange={setSearchInputValue}
+ aria-label={t`Search address fields`}
+ placeholder={t`Search`}
/>
- }
- dropdownComponents={
- <SelectableList
- selectableListInstanceId={dropdownId}
- selectableItemIdArray={selectableItemIdArray}
- focusId={dropdownId}
- >
- <DropdownContent selectDisabled widthInPixels={dropdownWidth}>
- <DropdownMenuSearchInput
- value={searchInputValue}
- onChange={(event) => setSearchInputValue(event.target.value)}
- autoFocus
- />
- <DropdownMenuSeparator />
- <DropdownMenuItemsContainer isMultiSelect hasMaxHeight>
- {filteredOptions?.map((option) => {
- return (
- <SelectableListItem
- key={`${option.value}`}
- itemId={`${option.value}`}
- onEnter={() => {
- onChange?.(onOptionSelected(option.value, values));
- }}
- >
- <ListItem
- key={`${option.value}`}
- onClick={() =>
- onChange?.(onOptionSelected(option.value, values))
- }
- role="option"
- aria-selected={values?.includes(option?.value) || false}
- selected={values?.includes(option?.value) || false}
- indicator="checkbox"
- >
- <Tag color={'transparent'}>{option.label}</Tag>
- </ListItem>
- </SelectableListItem>
- );
- })}
- </DropdownMenuItemsContainer>
- </DropdownContent>
- <DropdownMenuSeparator />
- <DropdownMenuItemsContainer hasMaxHeight scrollable={false}>
- <ListItem
- onClick={callToActionButton?.onClick}
- startIcon={<SelectOptionIcon Icon={callToActionButton?.Icon} />}
- disabled={values.length === options.length}
+ <Dropdown.Separator />
+ <Dropdown.Section>
+ {filteredOptions.map((option) => (
+ <Dropdown.OptionItem
+ key={`${option.value}`}
+ selected={values.includes(option.value)}
+ onSelect={() => handleOptionSelected(option.value)}
+ disabled={option.disabled}
>
- {callToActionButton?.text}
- </ListItem>
- </DropdownMenuItemsContainer>
- </SelectableList>
- }
- />
+ <Tag color="transparent">{option.label}</Tag>
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.Section>
+ {isDefined(callToActionButton) && (
+ <>
+ <Dropdown.Separator />
+ <Dropdown.Section>
+ <Dropdown.ActionItem
+ onClick={callToActionButton.onClick}
+ startIcon={<SelectOptionIcon Icon={callToActionButton.Icon} />}
+ disabled={values.length === options.length}
+ >
+ {callToActionButton.text}
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </>
+ )}
+ </Dropdown.Content>
+ </DropdownRoot>
);
};
diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/SettingsDataModelFieldAddressForm.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/SettingsDataModelFieldAddressForm.tsx
index 13e1fc4c6ec..5f4404d9b57 100644
--- a/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/SettingsDataModelFieldAddressForm.tsx
+++ b/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/SettingsDataModelFieldAddressForm.tsx
@@ -9,9 +9,7 @@ import { DEFAULT_SELECTION_ADDRESS_WITH_MESSAGES } from '@/settings/data-model/f
import { useAddressSettingsFormInitialValues } from '@/settings/data-model/fields/forms/address/hooks/useAddressSettingsFormInitialValues';
import { useCountries } from '@/ui/input/components/internal/hooks/useCountries';
import { Select } from '@/ui/input/components/Select';
-import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
import { useLingui } from '@lingui/react/macro';
-import { type MouseEvent } from 'react';
import {
IconCircleOff,
IconList,
@@ -66,12 +64,6 @@ export const SettingsDataModelFieldAddressForm = ({
resetDefaultValueField,
} = useAddressSettingsFormInitialValues({ existingFieldMetadataId });
- const { closeDropdown } = useCloseDropdown();
- const reset = () => {
- resetDefaultValueField();
- closeDropdown('addressSubFieldsId');
- };
-
return (
<>
<Controller
@@ -119,6 +111,7 @@ export const SettingsDataModelFieldAddressForm = ({
description={t`Decide which Sub-address fields you want to display`}
>
<MultiSelectAddressFields<string>
+ dropdownId="addressSubFieldsId"
options={DEFAULT_SELECTION_ADDRESS_WITH_MESSAGES.map(
(option) => ({
...option,
@@ -126,14 +119,10 @@ export const SettingsDataModelFieldAddressForm = ({
}),
)}
values={values}
- dropdownId="addressSubFieldsId"
onChange={onChange}
callToActionButton={{
text: t`Reset to default`,
- onClick: (event: MouseEvent<HTMLDivElement>) => {
- event.preventDefault();
- reset();
- },
+ onClick: resetDefaultValueField,
Icon: IconRefresh,
}}
selectSizeVariant="small"
diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/__tests__/MultiSelectAddressFields.test.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/__tests__/MultiSelectAddressFields.test.tsx
new file mode 100644
index 00000000000..928b1c25e29
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/data-model/fields/forms/address/components/__tests__/MultiSelectAddressFields.test.tsx
@@ -0,0 +1,104 @@
+import { i18n } from '@lingui/core';
+import { I18nProvider } from '@lingui/react';
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { Provider } from 'jotai';
+import { type ReactNode, useState } from 'react';
+
+import { MultiSelectAddressFields } from '@/settings/data-model/fields/forms/address/components/MultiSelectAddressFields';
+
+const ADDRESS_FIELD_OPTIONS = [
+ { label: 'Street', value: 'street' },
+ { label: 'City', value: 'city' },
+ { label: 'Country', value: 'country' },
+];
+
+const Wrapper = ({ children }: { children: ReactNode }) => (
+ <I18nProvider i18n={i18n}>
+ <Provider>{children}</Provider>
+ </I18nProvider>
+);
+
+const AddressFieldsPicker = () => {
+ const [values, setValues] = useState(['street']);
+
+ return (
+ <MultiSelectAddressFields
+ dropdownId="address-fields-test"
+ options={ADDRESS_FIELD_OPTIONS}
+ values={values}
+ onChange={setValues}
+ callToActionButton={{
+ text: 'Reset to default',
+ onClick: () => setValues(['street', 'city', 'country']),
+ }}
+ />
+ );
+};
+
+describe('MultiSelectAddressFields', () => {
+ it('keeps multiple selections open and closes after resetting to default', async () => {
+ const user = userEvent.setup();
+ render(<AddressFieldsPicker />, { wrapper: Wrapper });
+
+ const trigger = screen.getByRole('button', {
+ name: 'Select address fields',
+ });
+ await user.click(trigger);
+ await user.click(screen.getByRole('button', { name: 'City' }));
+
+ expect(screen.getByRole('button', { name: 'City' })).toHaveAttribute(
+ 'aria-pressed',
+ 'true',
+ );
+ expect(screen.getByRole('button', { name: 'Street' })).toHaveAttribute(
+ 'aria-pressed',
+ 'true',
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Reset to default' }));
+
+ await waitFor(() => {
+ expect(
+ screen.queryByRole('button', { name: 'City' }),
+ ).not.toBeInTheDocument();
+ });
+ expect(trigger).toHaveTextContent('Default');
+
+ await user.click(trigger);
+ expect(
+ screen.getByRole('button', { name: 'Reset to default' }),
+ ).toHaveAttribute('aria-disabled', 'true');
+ });
+
+ it('filters results, selects with the keyboard, and clears search after closing', async () => {
+ const user = userEvent.setup();
+ render(<AddressFieldsPicker />, { wrapper: Wrapper });
+
+ const trigger = screen.getByRole('button', {
+ name: 'Select address fields',
+ });
+ await user.click(trigger);
+ await user.type(
+ screen.getByRole('searchbox', { name: 'Search address fields' }),
+ 'City',
+ );
+
+ expect(
+ screen.queryByRole('button', { name: 'Street' }),
+ ).not.toBeInTheDocument();
+ await user.keyboard('{ArrowDown}{Enter}');
+ expect(screen.getByRole('button', { name: 'City' })).toHaveAttribute(
+ 'aria-pressed',
+ 'true',
+ );
+ await user.keyboard('{Escape}');
+
+ await waitFor(() => expect(trigger).toHaveFocus());
+ await user.click(trigger);
+ expect(
+ screen.getByRole('searchbox', { name: 'Search address fields' }),
+ ).toHaveValue('');
+ expect(screen.getByRole('button', { name: 'Street' })).toBeInTheDocument();
+ });
+});
diff --git a/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx b/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx
index 9df5a79e1f1..f61731b6943 100644
--- a/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx
+++ b/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx
@@ -270,6 +270,7 @@ const TextInputComponent = forwardRef<
>(
(
{
+ 'aria-label': ariaLabel,
className,
label,
value,
@@ -357,6 +358,7 @@ const TextInputComponent = forwardRef<
)}
<StyledInput
+ aria-label={ariaLabel}
id={instanceId}
width={width}
data-testid={dataTestId}
diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownCleanupEffect.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownCleanupEffect.tsx
new file mode 100644
index 00000000000..d8f4828ac33
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownCleanupEffect.tsx
@@ -0,0 +1,17 @@
+import { useEffect } from 'react';
+
+import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
+
+type DropdownCleanupEffectProps = {
+ dropdownId: string;
+};
+
+export const DropdownCleanupEffect = ({
+ dropdownId,
+}: DropdownCleanupEffectProps) => {
+ const { closeDropdown } = useCloseDropdown();
+
+ useEffect(() => () => closeDropdown(dropdownId), [closeDropdown, dropdownId]);
+
+ return null;
+};
diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownRoot.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownRoot.tsx
new file mode 100644
index 00000000000..027582c01d7
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownRoot.tsx
@@ -0,0 +1,74 @@
+import { useStore } from 'jotai';
+import { type ComponentProps, useCallback, useSyncExternalStore } from 'react';
+import { Dropdown } from 'twenty-ui/components';
+
+import { DropdownCleanupEffect } from '@/ui/layout/dropdown/components/DropdownCleanupEffect';
+import { DropdownComponentInstanceContext } from '@/ui/layout/dropdown/contexts/DropdownComponentInstanceContext';
+import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
+import { useOpenDropdown } from '@/ui/layout/dropdown/hooks/useOpenDropdown';
+import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
+
+type DropdownRootProps = Pick<
+ ComponentProps<typeof Dropdown.Root>,
+ 'children' | 'type' | 'multiple' | 'defaultPage' | 'onOpenChange'
+> & {
+ dropdownId: string;
+};
+
+export const DropdownRoot = ({
+ children,
+ type,
+ multiple,
+ defaultPage,
+ dropdownId,
+ onOpenChange,
+}: DropdownRootProps) => {
+ const store = useStore();
+ const dropdownOpenState = isDropdownOpenComponentState.atomFamily({
+ instanceId: dropdownId,
+ });
+ const subscribeToDropdownOpenState = useCallback(
+ (onStoreChange: () => void) =>
+ store.sub(dropdownOpenState, () => {
+ const open = store.get(dropdownOpenState);
+
+ onStoreChange();
+ onOpenChange?.(open);
+ }),
+ [dropdownOpenState, onOpenChange, store],
+ );
+ const getIsDropdownOpen = () => store.get(dropdownOpenState);
+ const isDropdownOpen = useSyncExternalStore(
+ subscribeToDropdownOpenState,
+ getIsDropdownOpen,
+ getIsDropdownOpen,
+ );
+ const { openDropdown } = useOpenDropdown();
+ const { closeDropdown } = useCloseDropdown();
+
+ const handleOpenChange = (open: boolean) => {
+ if (!open) {
+ closeDropdown(dropdownId);
+ return;
+ }
+
+ openDropdown({ dropdownComponentInstanceIdFromProps: dropdownId });
+ };
+
+ return (
+ <DropdownComponentInstanceContext.Provider
+ value={{ instanceId: dropdownId }}
+ >
+ <Dropdown.Root
+ type={type}
+ multiple={multiple}
+ defaultPage={defaultPage}
+ open={isDropdownOpen}
+ onOpenChange={handleOpenChange}
+ >
+ <DropdownCleanupEffect dropdownId={dropdownId} />
+ {children}
+ </Dropdown.Root>
+ </DropdownComponentInstanceContext.Provider>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/__tests__/DropdownRoot.test.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/__tests__/DropdownRoot.test.tsx
new file mode 100644
index 00000000000..29de23c7c27
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/__tests__/DropdownRoot.test.tsx
@@ -0,0 +1,465 @@
+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
+import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
+import { useOpenDropdown } from '@/ui/layout/dropdown/hooks/useOpenDropdown';
+import { activeDropdownFocusIdState } from '@/ui/layout/dropdown/states/activeDropdownFocusIdState';
+import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
+import { previousDropdownFocusIdStackState } from '@/ui/layout/dropdown/states/previousDropdownFocusIdStackState';
+import { currentGlobalHotkeysConfigSelector } from '@/ui/utilities/focus/states/currentGlobalHotkeysConfigSelector';
+import { focusStackState } from '@/ui/utilities/focus/states/focusStackState';
+import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
+import { type FocusStackItem } from '@/ui/utilities/focus/types/FocusStackItem';
+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
+import {
+ act,
+ render,
+ renderHook,
+ screen,
+ waitFor,
+} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { createStore, Provider as JotaiProvider } from 'jotai';
+import { Dropdown } from 'twenty-ui/components';
+
+const BACKGROUND_FOCUS_ITEM: FocusStackItem = {
+ focusId: 'record-page',
+ componentInstance: {
+ componentType: FocusComponentType.PAGE,
+ componentInstanceId: 'record-page',
+ },
+ globalHotkeysConfig: {
+ enableGlobalHotkeysConflictingWithKeyboard: true,
+ enableGlobalHotkeysWithModifiers: true,
+ },
+};
+
+const DROPDOWN_HOTKEYS_CONFIG = {
+ enableGlobalHotkeysConflictingWithKeyboard: false,
+ enableGlobalHotkeysWithModifiers: false,
+};
+
+const createTestStore = () => {
+ const store = createStore();
+
+ store.set(focusStackState.atom, [BACKGROUND_FOCUS_ITEM]);
+
+ return store;
+};
+
+const DropdownOpenState = () => {
+ const isDropdownOpen = useAtomComponentStateValue(
+ isDropdownOpenComponentState,
+ );
+
+ return (
+ <output aria-label="Dropdown state">
+ {isDropdownOpen ? 'Open' : 'Closed'}
+ </output>
+ );
+};
+
+const SaveButton = () => {
+ const { closeDropdown } = useCloseDropdown();
+
+ return <button onClick={() => closeDropdown()}>Save</button>;
+};
+
+const DropdownOwners = ({
+ isInnerOwnerVisible,
+}: {
+ isInnerOwnerVisible: boolean;
+}) => (
+ <DropdownRoot dropdownId="outer-dropdown" type="panel">
+ <Dropdown.Trigger>Outer dropdown</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Outer dropdown">
+ {isInnerOwnerVisible && (
+ <DropdownRoot dropdownId="inner-dropdown" type="panel">
+ <Dropdown.Trigger>Inner dropdown</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Inner dropdown">
+ Inner content
+ </Dropdown.Content>
+ </DropdownRoot>
+ )}
+ </Dropdown.Content>
+ </DropdownRoot>
+);
+
+describe('DropdownRoot', () => {
+ it('updates focus and global shortcuts before notifying opening and dismissal', async () => {
+ const user = userEvent.setup();
+ const store = createTestStore();
+ const onOpenChange = jest.fn((open: boolean) => ({
+ open,
+ focusStack: store.get(focusStackState.atom),
+ globalHotkeysConfig: store.get(currentGlobalHotkeysConfigSelector.atom),
+ }));
+
+ render(
+ <JotaiProvider store={store}>
+ <DropdownRoot
+ dropdownId="actions-dropdown"
+ type="menu"
+ onOpenChange={onOpenChange}
+ >
+ <Dropdown.Trigger>Actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Actions">
+ <Dropdown.ActionItem>Archive</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </DropdownRoot>
+ </JotaiProvider>,
+ );
+
+ expect(store.get(focusStackState.atom)).toEqual([BACKGROUND_FOCUS_ITEM]);
+
+ const trigger = screen.getByRole('button', { name: 'Actions' });
+
+ await user.click(trigger);
+
+ expect(screen.getByRole('menu', { name: 'Actions' })).toBeVisible();
+ expect(onOpenChange).toHaveLastReturnedWith({
+ open: true,
+ focusStack: [
+ BACKGROUND_FOCUS_ITEM,
+ {
+ focusId: 'actions-dropdown',
+ componentInstance: {
+ componentType: FocusComponentType.DROPDOWN,
+ componentInstanceId: 'actions-dropdown',
+ },
+ globalHotkeysConfig: DROPDOWN_HOTKEYS_CONFIG,
+ },
+ ],
+ globalHotkeysConfig: DROPDOWN_HOTKEYS_CONFIG,
+ });
+
+ const openedFocusStack = store.get(focusStackState.atom);
+
+ await user.keyboard('{Escape}');
+
+ expect(onOpenChange).toHaveLastReturnedWith({
+ open: false,
+ focusStack: [BACKGROUND_FOCUS_ITEM],
+ globalHotkeysConfig: BACKGROUND_FOCUS_ITEM.globalHotkeysConfig,
+ });
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ await waitFor(() => expect(trigger).toHaveFocus());
+
+ await user.click(trigger);
+
+ expect(store.get(focusStackState.atom)).toEqual(openedFocusStack);
+ });
+
+ it('closes the popup and restores focus through the close hook', async () => {
+ const user = userEvent.setup();
+ const store = createTestStore();
+
+ render(
+ <JotaiProvider store={store}>
+ <DropdownRoot dropdownId="edit-record-dropdown" type="panel">
+ <Dropdown.Trigger>Edit record</Dropdown.Trigger>
+ <DropdownOpenState />
+ <Dropdown.Content aria-label="Edit record">
+ <SaveButton />
+ </Dropdown.Content>
+ </DropdownRoot>
+ </JotaiProvider>,
+ );
+
+ const trigger = screen.getByRole('button', { name: 'Edit record' });
+ const dropdownState = screen.getByRole('status', {
+ name: 'Dropdown state',
+ });
+
+ expect(dropdownState).toHaveTextContent('Closed');
+
+ await user.click(trigger);
+
+ expect(dropdownState).toHaveTextContent('Open');
+ expect(screen.getByRole('dialog', { name: 'Edit record' })).toBeVisible();
+
+ await user.click(screen.getByRole('button', { name: 'Save' }));
+
+ expect(dropdownState).toHaveTextContent('Closed');
+ expect(store.get(focusStackState.atom)).toEqual([BACKGROUND_FOCUS_ITEM]);
+ expect(store.get(currentGlobalHotkeysConfigSelector.atom)).toEqual(
+ BACKGROUND_FOCUS_ITEM.globalHotkeysConfig,
+ );
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ await waitFor(() => expect(trigger).toHaveFocus());
+ });
+
+ it('removes the unmounted inner owner while the outer dropdown remains open', async () => {
+ const user = userEvent.setup();
+ const store = createTestStore();
+ const { rerender, unmount } = render(
+ <JotaiProvider store={store}>
+ <DropdownOwners isInnerOwnerVisible />
+ </JotaiProvider>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Outer dropdown' }));
+
+ const remainingFocusItem = store.get(focusStackState.atom).at(-1);
+
+ await user.click(screen.getByRole('button', { name: 'Inner dropdown' }));
+
+ expect(store.get(focusStackState.atom)).toHaveLength(3);
+
+ rerender(
+ <JotaiProvider store={store}>
+ <DropdownOwners isInnerOwnerVisible={false} />
+ </JotaiProvider>,
+ );
+
+ expect(store.get(focusStackState.atom)).toEqual([
+ BACKGROUND_FOCUS_ITEM,
+ remainingFocusItem,
+ ]);
+ expect(
+ screen.getByRole('button', { name: 'Outer dropdown' }),
+ ).toHaveAttribute('aria-expanded', 'true');
+ expect(
+ screen.getByRole('dialog', { name: 'Outer dropdown' }),
+ ).toBeVisible();
+ expect(store.get(currentGlobalHotkeysConfigSelector.atom)).toEqual(
+ DROPDOWN_HOTKEYS_CONFIG,
+ );
+
+ unmount();
+
+ expect(store.get(focusStackState.atom)).toEqual([BACKGROUND_FOCUS_ITEM]);
+ expect(store.get(currentGlobalHotkeysConfigSelector.atom)).toEqual(
+ BACKGROUND_FOCUS_ITEM.globalHotkeysConfig,
+ );
+ });
+
+ it('opens and closes the declared dropdown through external hooks', async () => {
+ const store = createTestStore();
+ const onOpenChange = jest.fn((open: boolean) => ({
+ open,
+ focusStack: store.get(focusStackState.atom),
+ globalHotkeysConfig: store.get(currentGlobalHotkeysConfigSelector.atom),
+ }));
+ const { result } = renderHook(
+ () => ({ ...useOpenDropdown(), ...useCloseDropdown() }),
+ {
+ wrapper: ({ children }) => (
+ <JotaiProvider store={store}>{children}</JotaiProvider>
+ ),
+ },
+ );
+
+ render(
+ <JotaiProvider store={store}>
+ <DropdownRoot
+ dropdownId="external-dropdown"
+ type="menu"
+ onOpenChange={onOpenChange}
+ >
+ <Dropdown.Trigger>External actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="External actions">
+ <Dropdown.ActionItem>Archive</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </DropdownRoot>
+ <DropdownRoot dropdownId="other-dropdown" type="menu">
+ <Dropdown.Trigger>Other actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Other actions">
+ <Dropdown.ActionItem>Rename</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </DropdownRoot>
+ </JotaiProvider>,
+ );
+
+ act(() => {
+ result.current.openDropdown({
+ dropdownComponentInstanceIdFromProps: 'external-dropdown',
+ });
+
+ expect(onOpenChange).toHaveBeenCalledTimes(1);
+ expect(onOpenChange).toHaveLastReturnedWith({
+ open: true,
+ focusStack: [
+ BACKGROUND_FOCUS_ITEM,
+ {
+ focusId: 'external-dropdown',
+ componentInstance: {
+ componentType: FocusComponentType.DROPDOWN,
+ componentInstanceId: 'external-dropdown',
+ },
+ globalHotkeysConfig: DROPDOWN_HOTKEYS_CONFIG,
+ },
+ ],
+ globalHotkeysConfig: DROPDOWN_HOTKEYS_CONFIG,
+ });
+
+ result.current.openDropdown({
+ dropdownComponentInstanceIdFromProps: 'external-dropdown',
+ });
+
+ expect(onOpenChange).toHaveBeenCalledTimes(1);
+ });
+
+ await waitFor(() =>
+ expect(
+ screen.getByRole('menu', { name: 'External actions' }),
+ ).toBeVisible(),
+ );
+ expect(
+ screen.queryByRole('menu', { name: 'Other actions' }),
+ ).not.toBeInTheDocument();
+ expect(onOpenChange).toHaveBeenLastCalledWith(true);
+ expect(store.get(activeDropdownFocusIdState.atom)).toBe(
+ 'external-dropdown',
+ );
+
+ act(() => {
+ result.current.closeDropdown('external-dropdown');
+
+ expect(onOpenChange).toHaveBeenCalledTimes(2);
+ expect(onOpenChange).toHaveLastReturnedWith({
+ open: false,
+ focusStack: [BACKGROUND_FOCUS_ITEM],
+ globalHotkeysConfig: BACKGROUND_FOCUS_ITEM.globalHotkeysConfig,
+ });
+
+ result.current.closeDropdown('external-dropdown');
+
+ expect(onOpenChange).toHaveBeenCalledTimes(2);
+ });
+
+ expect(onOpenChange).toHaveBeenLastCalledWith(false);
+ expect(store.get(focusStackState.atom)).toEqual([BACKGROUND_FOCUS_ITEM]);
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('uses the latest callback and stops notifying after unmount', () => {
+ const store = createTestStore();
+ const initialOnOpenChange = jest.fn();
+ const latestOnOpenChange = jest.fn();
+ const { result } = renderHook(
+ () => ({ ...useOpenDropdown(), ...useCloseDropdown() }),
+ {
+ wrapper: ({ children }) => (
+ <JotaiProvider store={store}>{children}</JotaiProvider>
+ ),
+ },
+ );
+ const { rerender, unmount } = render(
+ <JotaiProvider store={store}>
+ <DropdownRoot
+ dropdownId="subscribed-dropdown"
+ type="menu"
+ onOpenChange={initialOnOpenChange}
+ >
+ <Dropdown.Trigger>Actions</Dropdown.Trigger>
+ </DropdownRoot>
+ </JotaiProvider>,
+ );
+
+ rerender(
+ <JotaiProvider store={store}>
+ <DropdownRoot
+ dropdownId="subscribed-dropdown"
+ type="menu"
+ onOpenChange={latestOnOpenChange}
+ >
+ <Dropdown.Trigger>Actions</Dropdown.Trigger>
+ </DropdownRoot>
+ </JotaiProvider>,
+ );
+
+ act(() => {
+ result.current.openDropdown({
+ dropdownComponentInstanceIdFromProps: 'subscribed-dropdown',
+ });
+
+ expect(initialOnOpenChange).not.toHaveBeenCalled();
+ expect(latestOnOpenChange).toHaveBeenCalledTimes(1);
+ expect(latestOnOpenChange).toHaveBeenLastCalledWith(true);
+
+ result.current.closeDropdown('subscribed-dropdown');
+
+ expect(latestOnOpenChange).toHaveBeenCalledTimes(2);
+ expect(latestOnOpenChange).toHaveBeenLastCalledWith(false);
+
+ result.current.openDropdown({
+ dropdownComponentInstanceIdFromProps: 'subscribed-dropdown',
+ });
+
+ expect(latestOnOpenChange).toHaveBeenCalledTimes(3);
+ expect(latestOnOpenChange).toHaveBeenLastCalledWith(true);
+ });
+
+ unmount();
+
+ expect(latestOnOpenChange).toHaveBeenCalledTimes(3);
+ expect(
+ store.get(
+ isDropdownOpenComponentState.atomFamily({
+ instanceId: 'subscribed-dropdown',
+ }),
+ ),
+ ).toBe(false);
+
+ act(() => {
+ result.current.openDropdown({
+ dropdownComponentInstanceIdFromProps: 'subscribed-dropdown',
+ });
+ result.current.closeDropdown('subscribed-dropdown');
+ });
+
+ expect(initialOnOpenChange).not.toHaveBeenCalled();
+ expect(latestOnOpenChange).toHaveBeenCalledTimes(3);
+ });
+
+ it('remounts a declared dropdown closed after its open owner unmounts', async () => {
+ const user = userEvent.setup();
+ const store = createTestStore();
+ const dropdown = (
+ <JotaiProvider store={store}>
+ <DropdownRoot dropdownId="remounted-dropdown" type="menu">
+ <Dropdown.Trigger>Actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Actions">
+ <Dropdown.ActionItem>Archive</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </DropdownRoot>
+ </JotaiProvider>
+ );
+ const { unmount } = render(dropdown);
+
+ await user.click(screen.getByRole('button', { name: 'Actions' }));
+
+ expect(screen.getByRole('menu', { name: 'Actions' })).toBeVisible();
+
+ unmount();
+
+ expect(
+ store.get(
+ isDropdownOpenComponentState.atomFamily({
+ instanceId: 'remounted-dropdown',
+ }),
+ ),
+ ).toBe(false);
+ expect(store.get(activeDropdownFocusIdState.atom)).toBeNull();
+ expect(store.get(previousDropdownFocusIdStackState.atom)).toEqual([]);
+ expect(store.get(focusStackState.atom)).toEqual([BACKGROUND_FOCUS_ITEM]);
+
+ render(dropdown);
+
+ expect(screen.getByRole('button', { name: 'Actions' })).toHaveAttribute(
+ 'aria-expanded',
+ 'false',
+ );
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();
+
+ await user.click(screen.getByRole('button', { name: 'Actions' }));
+
+ expect(screen.getByRole('menu', { name: 'Actions' })).toBeVisible();
+ expect(store.get(focusStackState.atom)).toHaveLength(2);
+ });
+});
diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/__tests__/useCloseDropdown.test.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/__tests__/useCloseDropdown.test.tsx
index 9690ad9115f..3cbd861fcf5 100644
--- a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/__tests__/useCloseDropdown.test.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/__tests__/useCloseDropdown.test.tsx
@@ -5,7 +5,10 @@ import { act } from 'react';
import { DropdownComponentInstanceContext } from '@/ui/layout/dropdown/contexts/DropdownComponentInstanceContext';
import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
import { useOpenDropdown } from '@/ui/layout/dropdown/hooks/useOpenDropdown';
+import { activeDropdownFocusIdState } from '@/ui/layout/dropdown/states/activeDropdownFocusIdState';
import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
+import { previousDropdownFocusIdStackState } from '@/ui/layout/dropdown/states/previousDropdownFocusIdStackState';
+import { focusStackState } from '@/ui/utilities/focus/states/focusStackState';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
@@ -29,6 +32,9 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => {
describe('useCloseDropdown', () => {
beforeEach(() => {
+ jotaiStore.set(activeDropdownFocusIdState.atom, null);
+ jotaiStore.set(previousDropdownFocusIdStackState.atom, []);
+ jotaiStore.set(focusStackState.atom, []);
jotaiStore.set(
isDropdownOpenComponentState.atomFamily({ instanceId: dropdownId }),
false,
@@ -128,4 +134,57 @@ describe('useCloseDropdown', () => {
expect(result.current.isDropdownOpen).toBe(false);
expect(result.current.isOutsideDropdownOpen).toBe(false);
});
+
+ it('keeps the active dropdown focused when an earlier dropdown closes', () => {
+ const { result } = renderHook(
+ () => ({ ...useOpenDropdown(), ...useCloseDropdown() }),
+ { wrapper: Wrapper },
+ );
+
+ act(() => {
+ result.current.openDropdown();
+ result.current.openDropdown({
+ dropdownComponentInstanceIdFromProps: outsideDropdownId,
+ });
+ });
+
+ expect(jotaiStore.get(activeDropdownFocusIdState.atom)).toBe(
+ outsideDropdownId,
+ );
+ expect(jotaiStore.get(previousDropdownFocusIdStackState.atom)).toEqual([
+ dropdownId,
+ ]);
+
+ act(() => {
+ result.current.closeDropdown();
+ });
+
+ expect(
+ jotaiStore.get(
+ isDropdownOpenComponentState.atomFamily({ instanceId: dropdownId }),
+ ),
+ ).toBe(false);
+ expect(
+ jotaiStore.get(
+ isDropdownOpenComponentState.atomFamily({
+ instanceId: outsideDropdownId,
+ }),
+ ),
+ ).toBe(true);
+ expect(jotaiStore.get(activeDropdownFocusIdState.atom)).toBe(
+ outsideDropdownId,
+ );
+ expect(jotaiStore.get(previousDropdownFocusIdStackState.atom)).toEqual([]);
+ expect(
+ jotaiStore.get(focusStackState.atom).map(({ focusId }) => focusId),
+ ).toEqual([outsideDropdownId]);
+
+ act(() => {
+ result.current.closeDropdown(outsideDropdownId);
+ });
+
+ expect(jotaiStore.get(activeDropdownFocusIdState.atom)).toBeNull();
+ expect(jotaiStore.get(previousDropdownFocusIdStackState.atom)).toEqual([]);
+ expect(jotaiStore.get(focusStackState.atom)).toEqual([]);
+ });
});
diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useCloseDropdown.ts b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useCloseDropdown.ts
index c37d5bf1b57..61fd4514d25 100644
--- a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useCloseDropdown.ts
+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useCloseDropdown.ts
@@ -1,8 +1,9 @@
import { useCallback } from 'react';
import { DropdownComponentInstanceContext } from '@/ui/layout/dropdown/contexts/DropdownComponentInstanceContext';
-import { useGoBackToPreviousDropdownFocusId } from '@/ui/layout/dropdown/hooks/useGoBackToPreviousDropdownFocusId';
+import { activeDropdownFocusIdState } from '@/ui/layout/dropdown/states/activeDropdownFocusIdState';
import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
+import { previousDropdownFocusIdStackState } from '@/ui/layout/dropdown/states/previousDropdownFocusIdStackState';
import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooks/useRemoveFocusItemFromFocusStackById';
import { useAvailableComponentInstanceId } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceId';
@@ -10,9 +11,6 @@ import { useStore } from 'jotai';
import { isDefined } from 'twenty-shared/utils';
export const useCloseDropdown = () => {
- const { goBackToPreviousDropdownFocusId } =
- useGoBackToPreviousDropdownFocusId();
-
const { removeFocusItemFromFocusStackById } =
useRemoveFocusItemFromFocusStackById();
@@ -37,24 +35,42 @@ export const useCloseDropdown = () => {
}),
);
- if (isDropdownOpen) {
- removeFocusItemFromFocusStackById({
- focusId: dropdownComponentInstanceId,
- });
+ if (!isDropdownOpen) {
+ return;
+ }
+
+ removeFocusItemFromFocusStackById({
+ focusId: dropdownComponentInstanceId,
+ });
- goBackToPreviousDropdownFocusId();
+ const previousDropdownFocusIds = store
+ .get(previousDropdownFocusIdStackState.atom)
+ .filter((dropdownId) => dropdownId !== dropdownComponentInstanceId);
+ const isActiveDropdown =
+ store.get(activeDropdownFocusIdState.atom) ===
+ dropdownComponentInstanceId;
+ if (isActiveDropdown) {
store.set(
- isDropdownOpenComponentState.atomFamily({
- instanceId: dropdownComponentInstanceId,
- }),
- false,
+ activeDropdownFocusIdState.atom,
+ previousDropdownFocusIds.pop() ?? null,
);
}
+
+ store.set(
+ previousDropdownFocusIdStackState.atom,
+ previousDropdownFocusIds,
+ );
+
+ store.set(
+ isDropdownOpenComponentState.atomFamily({
+ instanceId: dropdownComponentInstanceId,
+ }),
+ false,
+ );
},
[
removeFocusItemFromFocusStackById,
- goBackToPreviousDropdownFocusId,
dropdownComponentInstanceIdFromContext,
store,
],
diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useOpenDropdown.ts b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useOpenDropdown.ts
index 6f56194baa3..c34c66f6f09 100644
--- a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useOpenDropdown.ts
+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useOpenDropdown.ts
@@ -36,13 +36,6 @@ export const useOpenDropdown = () => {
throw new Error('Dropdown component instance ID is not defined');
}
- store.set(
- isDropdownOpenComponentState.atomFamily({
- instanceId: dropdownComponentInstanceId,
- }),
- true,
- );
-
setActiveDropdownFocusIdAndMemorizePrevious(dropdownComponentInstanceId);
pushFocusItemToFocusStack({
@@ -60,6 +53,13 @@ export const useOpenDropdown = () => {
false,
},
});
+
+ store.set(
+ isDropdownOpenComponentState.atomFamily({
+ instanceId: dropdownComponentInstanceId,
+ }),
+ true,
+ );
},
[
pushFocusItemToFocusStack,
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
index c1934f9c9ac..f49ab4d6464 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
@@ -451,7 +451,16 @@ export const NavigationDrawerItem = ({
stopPropagation blocks Link's own preventDefault */}
<StyledRightOptionsContainer
onMouseDown={(e) => e.stopPropagation()}
- onClickCapture={(e) => e.preventDefault()}
+ onClickCapture={(event) => {
+ const isClickInsideLinkedOptions =
+ isDefined(to) &&
+ event.target instanceof Node &&
+ event.currentTarget.contains(event.target);
+
+ if (isClickInsideLinkedOptions) {
+ event.preventDefault();
+ }
+ }}
>
<StyledRightOptionsVisbility
data-visible={
diff --git a/packages/twenty-shared/src/constants/DocumentationPaths.ts b/packages/twenty-shared/src/constants/DocumentationPaths.ts
index eed9a9fdeee..711d3d614dc 100644
--- a/packages/twenty-shared/src/constants/DocumentationPaths.ts
+++ b/packages/twenty-shared/src/constants/DocumentationPaths.ts
@@ -129,6 +129,7 @@ export const DOCUMENTATION_PATHS = {
GETTING_STARTED_QUICKSTART: '/getting-started/quickstart',
UI_ACCESSIBILITY: '/ui/accessibility',
UI_COMPONENTS_CODE_EDITOR: '/ui/components/code-editor',
+ UI_COMPONENTS_DROPDOWN: '/ui/components/dropdown',
UI_COMPONENTS_INPUT_ICON_BUTTON: '/ui/components/input/icon-button',
UI_COMPONENTS_INPUT_LIGHT_BUTTON: '/ui/components/input/light-button',
UI_COMPONENTS_INPUT_LIGHT_ICON_BUTTON:
diff --git a/packages/twenty-ui/.size-limit.json b/packages/twenty-ui/.size-limit.json
index e57e0c91746..c35acf269df 100644
--- a/packages/twenty-ui/.size-limit.json
+++ b/packages/twenty-ui/.size-limit.json
@@ -13,7 +13,7 @@
{
"name": "components",
"path": "dist/components.mjs",
- "limit": "125 kB"
+ "limit": "140 kB"
},
{
"name": "components/code-editor",
diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.ts
index a546181fe7d..95ac26298e5 100644
--- a/packages/twenty-ui/docs/components.ts
+++ b/packages/twenty-ui/docs/components.ts
@@ -233,6 +233,39 @@ export const DOCUMENTED_COMPONENTS = [
slug: 'components/settings-row',
propDescriptions: SETTINGS_ROW_PROP_DESCRIPTIONS,
},
+ {
+ name: 'Dropdown',
+ source: 'components/navigation/Dropdown/Dropdown.tsx',
+ entryPoint: 'twenty-ui/components',
+ slug: 'components/dropdown',
+ parts: [
+ 'Root',
+ 'Trigger',
+ 'Content',
+ 'ActionItem',
+ 'OptionItem',
+ 'Search',
+ 'Page',
+ 'Back',
+ 'Submenu',
+ 'SubmenuTrigger',
+ 'Section',
+ ],
+ partPropDefaults: {
+ ActionItem: {
+ nativeButton: 'true when render is omitted; false otherwise',
+ },
+ OptionItem: {
+ nativeButton: 'true when render is omitted; false otherwise',
+ },
+ Back: {
+ nativeButton: 'true when render is omitted; false otherwise',
+ },
+ SubmenuTrigger: {
+ nativeButton: 'true when render is omitted; false otherwise',
+ },
+ },
+ },
{
name: 'Section',
source: 'components/layout/Section/Section.tsx',
diff --git a/packages/twenty-ui/docs/module-ownership.json b/packages/twenty-ui/docs/module-ownership.json
index 3e787287f0c..f926de597ed 100644
--- a/packages/twenty-ui/docs/module-ownership.json
+++ b/packages/twenty-ui/docs/module-ownership.json
@@ -53,6 +53,7 @@
"CodeEditorHeader",
"ColorSchemePicker",
"CommandBlock",
+ "Dropdown",
"IconButton",
"Info",
"InlineBanner",
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 6fe229c142d..e8fd51c02ce 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -5904,6 +5904,769 @@
}
]
},
+ {
+ "name": "Dropdown",
+ "entryPoint": "twenty-ui/components",
+ "slug": "components/dropdown",
+ "props": [],
+ "parts": [
+ {
+ "name": "Root",
+ "props": [
+ {
+ "name": "defaultOpen",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "defaultPage",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "multiple",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "onOpenChange",
+ "type": "((open: boolean) => void)",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "open",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "type",
+ "type": "\"menu\" | \"panel\" | \"picker\"",
+ "required": true,
+ "defaultValue": null,
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "Trigger",
+ "props": [
+ {
+ "name": "className",
+ "type": "string | ((state: PopoverTriggerState) => string | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "CSS class applied to the element, or a function that\nreturns a class based on the component's state."
+ },
+ {
+ "name": "closeDelay",
+ "type": "number",
+ "required": false,
+ "defaultValue": "0",
+ "description": "How long to wait before closing the popover that was opened on hover.\nSpecified in milliseconds.\n\nRequires the `openOnHover` prop."
+ },
+ {
+ "name": "delay",
+ "type": "number",
+ "required": false,
+ "defaultValue": "300",
+ "description": "How long to wait before the popover may be opened on hover. Specified in milliseconds.\n\nRequires the `openOnHover` prop."
+ },
+ {
+ "name": "handle",
+ "type": "PopoverHandle<unknown>",
+ "required": false,
+ "defaultValue": null,
+ "description": "A handle to associate the trigger with a popover."
+ },
+ {
+ "name": "id",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "ID of the trigger. In addition to being forwarded to the rendered element,\nit is also used to specify the active trigger for the popover in controlled mode (with the PopoverRoot `triggerId` prop)."
+ },
+ {
+ "name": "nativeButton",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true",
+ "description": "Whether the component renders a native `<button>` element when replacing it\nvia the `render` prop.\nSet to `false` if the rendered element is not a button (e.g. `<div>`)."
+ },
+ {
+ "name": "openOnHover",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Whether the popover should also open when the trigger is hovered."
+ },
+ {
+ "name": "payload",
+ "type": "unknown",
+ "required": false,
+ "defaultValue": null,
+ "description": "A payload to pass to the popover when it is opened."
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTriggerState>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Allows you to replace the component's HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties | ((state: PopoverTriggerState) => CSSProperties | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."
+ }
+ ]
+ },
+ {
+ "name": "Content",
+ "props": [
+ {
+ "name": "align",
+ "type": "\"center\" | \"end\" | \"start\"",
+ "required": false,
+ "defaultValue": "start",
+ "description": "Alignment of the popup along the anchor."
+ },
+ {
+ "name": "alignOffset",
+ "type": "number",
+ "required": false,
+ "defaultValue": null,
+ "description": "Offset in pixels along the alignment axis."
+ },
+ {
+ "name": "anchor",
+ "type": "Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | null",
+ "required": false,
+ "defaultValue": null,
+ "description": "Element or position the popup is anchored to. Defaults to the trigger."
+ },
+ {
+ "name": "className",
+ "type": "string | ((state: PopoverPopupState) => string | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "CSS class applied to the element, or a function that\nreturns a class based on the component's state."
+ },
+ {
+ "name": "container",
+ "type": "HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null",
+ "required": false,
+ "defaultValue": null,
+ "description": "Element the popup is portaled into. Defaults to the theme's portal\ncontainer."
+ },
+ {
+ "name": "finalFocus",
+ "type": "boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Determines the element to focus when the popover is closed.\n\n- `false`: Do not move focus.\n- `true`: Move focus based on the default behavior (trigger or previously focused element).\n- `RefObject`: Move focus to the ref element.\n- `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`).\n Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing."
+ },
+ {
+ "name": "initialFocus",
+ "type": "boolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Determines the element to focus when the popover is opened.\nBy default, focus moves to the first tabbable element inside the popup, except when the popover\nis opened by touch — then the popup itself is focused to avoid opening the virtual keyboard.\n\n- `false`: Do not move focus.\n- `true`: Move focus based on the default behavior (first tabbable element or popup).\n- `RefObject`: Move focus to the ref element.\n- `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`).\n Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing."
+ },
+ {
+ "name": "keepMounted",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": "Keeps the popup mounted in the DOM while the popover is closed."
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverPopupState>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Allows you to replace the component's HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
+ },
+ {
+ "name": "side",
+ "type": "\"bottom\" | \"inline-end\" | \"inline-start\" | \"left\" | \"right\" | \"top\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Side of the anchor the popup is placed on."
+ },
+ {
+ "name": "sideOffset",
+ "type": "number",
+ "required": false,
+ "defaultValue": "0",
+ "description": "Distance in pixels between the anchor and the popup."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties | ((state: PopoverPopupState) => CSSProperties | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."
+ },
+ {
+ "name": "width",
+ "type": "Width<string | number>",
+ "required": false,
+ "defaultValue": "200",
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "ActionItem",
+ "props": [
+ {
+ "name": "className",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "closeOnClick",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true",
+ "description": ""
+ },
+ {
+ "name": "color",
+ "type": "\"danger\" | \"neutral\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Color of the text and icons. `danger` marks a destructive action."
+ },
+ {
+ "name": "description",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Supporting text, placed according to `descriptionPlacement`."
+ },
+ {
+ "name": "descriptionPlacement",
+ "type": "\"end\" | \"inline\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Where the description renders: inline after the content or at the end of\nthe row."
+ },
+ {
+ "name": "endIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered after the content."
+ },
+ {
+ "name": "focusableWhenDisabled",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Whether the button should be focusable when disabled."
+ },
+ {
+ "name": "hasSubmenu",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": "Shows a chevron indicating that the item opens a submenu."
+ },
+ {
+ "name": "hotkeys",
+ "type": "string[]",
+ "required": false,
+ "defaultValue": null,
+ "description": "Keyboard shortcut keys displayed at the end of the row. Registering the\nshortcut is up to the application."
+ },
+ {
+ "name": "nativeButton",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true when render is omitted; false otherwise",
+ "description": "Whether the component renders a native `<button>` element when replacing it\nvia the `render` prop.\nSet to `false` if the rendered element is not a button (for example, `<div>`)."
+ },
+ {
+ "name": "page",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>>",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "startIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered before the content."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "OptionItem",
+ "props": [
+ {
+ "name": "className",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "closeOnSelect",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "color",
+ "type": "\"danger\" | \"neutral\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Color of the text and icons. `danger` marks a destructive action."
+ },
+ {
+ "name": "description",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Supporting text, placed according to `descriptionPlacement`."
+ },
+ {
+ "name": "descriptionPlacement",
+ "type": "\"end\" | \"inline\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Where the description renders: inline after the content or at the end of\nthe row."
+ },
+ {
+ "name": "endIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered after the content."
+ },
+ {
+ "name": "focusableWhenDisabled",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Whether the button should be focusable when disabled."
+ },
+ {
+ "name": "hasSubmenu",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": "Shows a chevron indicating that the item opens a submenu."
+ },
+ {
+ "name": "hotkeys",
+ "type": "string[]",
+ "required": false,
+ "defaultValue": null,
+ "description": "Keyboard shortcut keys displayed at the end of the row. Registering the\nshortcut is up to the application."
+ },
+ {
+ "name": "nativeButton",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true when render is omitted; false otherwise",
+ "description": "Whether the component renders a native `<button>` element when replacing it\nvia the `render` prop.\nSet to `false` if the rendered element is not a button (for example, `<div>`)."
+ },
+ {
+ "name": "onSelect",
+ "type": "(() => void)",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>>",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "selected",
+ "type": "boolean",
+ "required": true,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "startIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered before the content."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "Search",
+ "props": [
+ {
+ "name": "className",
+ "type": "string | ((state: InputState) => string | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "CSS class applied to the element, or a function that\nreturns a class based on the component's state."
+ },
+ {
+ "name": "defaultValue",
+ "type": "string | number | readonly string[]",
+ "required": false,
+ "defaultValue": null,
+ "description": "The default value of the input. Use when uncontrolled."
+ },
+ {
+ "name": "onValueChange",
+ "type": "((value: string) => void)",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, InputState>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Allows you to replace the component's HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties | ((state: InputState) => CSSProperties | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."
+ },
+ {
+ "name": "value",
+ "type": "string | number | readonly string[]",
+ "required": false,
+ "defaultValue": null,
+ "description": "The value of the input. Use when controlled."
+ }
+ ]
+ },
+ {
+ "name": "Page",
+ "props": [
+ {
+ "name": "id",
+ "type": "string",
+ "required": true,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "type",
+ "type": "\"menu\" | \"panel\" | \"picker\"",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "Back",
+ "props": [
+ {
+ "name": "className",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "color",
+ "type": "\"danger\" | \"neutral\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Color of the text and icons. `danger` marks a destructive action."
+ },
+ {
+ "name": "description",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Supporting text, placed according to `descriptionPlacement`."
+ },
+ {
+ "name": "descriptionPlacement",
+ "type": "\"end\" | \"inline\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Where the description renders: inline after the content or at the end of\nthe row."
+ },
+ {
+ "name": "endIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered after the content."
+ },
+ {
+ "name": "focusableWhenDisabled",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Whether the button should be focusable when disabled."
+ },
+ {
+ "name": "hasSubmenu",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": "Shows a chevron indicating that the item opens a submenu."
+ },
+ {
+ "name": "hotkeys",
+ "type": "string[]",
+ "required": false,
+ "defaultValue": null,
+ "description": "Keyboard shortcut keys displayed at the end of the row. Registering the\nshortcut is up to the application."
+ },
+ {
+ "name": "nativeButton",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true when render is omitted; false otherwise",
+ "description": "Whether the component renders a native `<button>` element when replacing it\nvia the `render` prop.\nSet to `false` if the rendered element is not a button (for example, `<div>`)."
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>>",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "startIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered before the content."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "Submenu",
+ "props": [
+ {
+ "name": "defaultOpen",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "defaultPage",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "multiple",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "onOpenChange",
+ "type": "((open: boolean) => void)",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "open",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "type",
+ "type": "\"menu\" | \"panel\" | \"picker\"",
+ "required": false,
+ "defaultValue": "menu",
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "SubmenuTrigger",
+ "props": [
+ {
+ "name": "className",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "closeDelay",
+ "type": "number",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "color",
+ "type": "\"danger\" | \"neutral\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Color of the text and icons. `danger` marks a destructive action."
+ },
+ {
+ "name": "delay",
+ "type": "number",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "description",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Supporting text, placed according to `descriptionPlacement`."
+ },
+ {
+ "name": "descriptionPlacement",
+ "type": "\"end\" | \"inline\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Where the description renders: inline after the content or at the end of\nthe row."
+ },
+ {
+ "name": "endIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered after the content."
+ },
+ {
+ "name": "focusableWhenDisabled",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Whether the button should be focusable when disabled."
+ },
+ {
+ "name": "hasSubmenu",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true",
+ "description": "Shows a chevron indicating that the item opens a submenu."
+ },
+ {
+ "name": "hotkeys",
+ "type": "string[]",
+ "required": false,
+ "defaultValue": null,
+ "description": "Keyboard shortcut keys displayed at the end of the row. Registering the\nshortcut is up to the application."
+ },
+ {
+ "name": "nativeButton",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true when render is omitted; false otherwise",
+ "description": "Whether the component renders a native `<button>` element when replacing it\nvia the `render` prop.\nSet to `false` if the rendered element is not a button (for example, `<div>`)."
+ },
+ {
+ "name": "openOnHover",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "true",
+ "description": ""
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>>",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ },
+ {
+ "name": "startIcon",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Icon rendered before the content."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ }
+ ]
+ },
+ {
+ "name": "Section",
+ "props": [
+ {
+ "name": "label",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": ""
+ }
+ ]
+ }
+ ]
+ },
{
"name": "Section",
"entryPoint": "twenty-ui/components",
diff --git a/packages/twenty-ui/scripts/generateDocsData.ts b/packages/twenty-ui/scripts/generateDocsData.ts
index fb150f2db1e..e2126c22e03 100644
--- a/packages/twenty-ui/scripts/generateDocsData.ts
+++ b/packages/twenty-ui/scripts/generateDocsData.ts
@@ -184,6 +184,9 @@ const components: ComponentDocumentation[] = DOCUMENTED_COMPONENTS.map(
Record<string, Partial<Record<string, string>>>
> =
'partPropDescriptions' in component ? component.partPropDescriptions : {};
+ const partPropDefaults: Partial<
+ Record<string, Partial<Record<string, string>>>
+ > = 'partPropDefaults' in component ? component.partPropDefaults : {};
const componentParts = type
.getProperties()
.filter((part) => COMPONENT_PART_NAME_PATTERN.test(part.name))
@@ -211,6 +214,7 @@ const components: ComponentDocumentation[] = DOCUMENTED_COMPONENTS.map(
symbol: partSymbol,
name: `${component.name}.${part.name}`,
propDescriptions: partPropDescriptions[part.name],
+ propDefaults: partPropDefaults[part.name],
}),
};
});
diff --git a/packages/twenty-ui/src/components/index.ts b/packages/twenty-ui/src/components/index.ts
index cb88f4b3a5e..b6f7b51cef4 100644
--- a/packages/twenty-ui/src/components/index.ts
+++ b/packages/twenty-ui/src/components/index.ts
@@ -70,6 +70,18 @@ export { AnimatedIconCrossfade } from './layout/AnimatedIconCrossfade/AnimatedIc
export { Section } from './layout/Section/Section';
export type { SectionHeaderProps } from './layout/Section/types/SectionHeaderProps';
export type { SectionRootProps } from './layout/Section/types/SectionRootProps';
+export { Dropdown } from './navigation/Dropdown/Dropdown';
+export type { DropdownActionItemProps } from './navigation/Dropdown/types/DropdownActionItemProps';
+export type { DropdownContentProps } from './navigation/Dropdown/types/DropdownContentProps';
+export type { DropdownOptionItemProps } from './navigation/Dropdown/types/DropdownOptionItemProps';
+export type { DropdownPageProps } from './navigation/Dropdown/types/DropdownPageProps';
+export type { DropdownRootProps } from './navigation/Dropdown/types/DropdownRootProps';
+export type { DropdownSearchProps } from './navigation/Dropdown/types/DropdownSearchProps';
+export type { DropdownSectionProps } from './navigation/Dropdown/types/DropdownSectionProps';
+export type { DropdownSubmenuProps } from './navigation/Dropdown/types/DropdownSubmenuProps';
+export type { DropdownSubmenuTriggerProps } from './navigation/Dropdown/types/DropdownSubmenuTriggerProps';
+export type { DropdownTriggerProps } from './navigation/Dropdown/types/DropdownTriggerProps';
+export type { DropdownType } from './navigation/Dropdown/types/DropdownType';
export { DEFAULT_COLOR_LABELS } from './navigation/MenuItem/constants/DefaultColorLabels';
export { MenuItem } from './navigation/MenuItem/MenuItem';
export type { ColorLabels } from './navigation/MenuItem/types/ColorLabels';
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.module.scss b/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.module.scss
new file mode 100644
index 00000000000..b8eb723cee6
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.module.scss
@@ -0,0 +1,67 @@
+.content[data-dropdown-content] {
+ --tw-popover-padding: 0;
+
+ box-sizing: border-box;
+ gap: 0;
+ max-block-size: var(--available-height);
+ overflow-y: auto;
+
+ [data-dropdown-item]:focus-visible {
+ background: var(--t-background-transparent-light);
+ }
+}
+
+.page {
+ display: contents;
+}
+
+.section {
+ padding: var(--t-spacing-1);
+}
+
+.separator[data-dropdown-separator] {
+ margin-inline: 0;
+}
+
+.section > .separator[data-dropdown-separator] {
+ margin-inline: calc(-1 * var(--t-spacing-1));
+}
+
+.back {
+ border-bottom: 1px solid var(--t-border-color-light);
+ border-bottom-left-radius: 0;
+ border-bottom-right-radius: 0;
+ color: var(--t-font-color-primary);
+ flex: none;
+ font-size: var(--t-font-size-md);
+ font-weight: var(--t-font-weight-medium);
+ min-block-size: 33px;
+ padding-inline: var(--t-spacing-2);
+
+ &:dir(rtl) svg {
+ transform: rotate(180deg);
+ }
+}
+
+.searchContainer {
+ align-items: center;
+ box-sizing: border-box;
+ display: flex;
+ flex: none;
+ min-block-size: 36px;
+ padding-block: var(--t-spacing-2);
+}
+
+.search[data-dropdown-search] {
+ background: transparent;
+ block-size: auto;
+ border: none;
+ border-radius: 0;
+ font-size: var(--t-font-size-sm);
+}
+
+.status {
+ color: var(--t-font-color-secondary);
+ font-size: var(--t-font-size-sm);
+ padding: var(--t-spacing-2);
+}
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.module.scss.d.ts b/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.module.scss.d.ts
new file mode 100644
index 00000000000..ae80577c77b
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.module.scss.d.ts
@@ -0,0 +1,11 @@
+declare const classNames: {
+ readonly content: 'content';
+ readonly page: 'page';
+ readonly section: 'section';
+ readonly separator: 'separator';
+ readonly back: 'back';
+ readonly searchContainer: 'searchContainer';
+ readonly search: 'search';
+ readonly status: 'status';
+};
+export default classNames;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.tsx
new file mode 100644
index 00000000000..d7f293af370
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/Dropdown.tsx
@@ -0,0 +1,37 @@
+import { type ReactElement } from 'react';
+
+import { DropdownActionItem } from './internal/DropdownActionItem';
+import { DropdownBack } from './internal/DropdownBack';
+import { DropdownContent } from './internal/DropdownContent';
+import { DropdownEmpty } from './internal/DropdownEmpty';
+import { DropdownLoading } from './internal/DropdownLoading';
+import { DropdownOptionItem } from './internal/DropdownOptionItem';
+import { DropdownPage } from './internal/DropdownPage';
+import { DropdownRoot as InternalDropdownRoot } from './internal/DropdownRoot';
+import { DropdownSearch } from './internal/DropdownSearch';
+import { DropdownSection } from './internal/DropdownSection';
+import { DropdownSeparator } from './internal/DropdownSeparator';
+import { DropdownSubmenu } from './internal/DropdownSubmenu';
+import { DropdownSubmenuTrigger } from './internal/DropdownSubmenuTrigger';
+import { DropdownTrigger } from './internal/DropdownTrigger';
+import { type DropdownRootProps } from './types/DropdownRootProps';
+
+const DropdownRoot: (props: DropdownRootProps) => ReactElement =
+ InternalDropdownRoot;
+
+export const Dropdown = {
+ Root: DropdownRoot,
+ Trigger: DropdownTrigger,
+ Content: DropdownContent,
+ ActionItem: DropdownActionItem,
+ OptionItem: DropdownOptionItem,
+ Search: DropdownSearch,
+ Page: DropdownPage,
+ Back: DropdownBack,
+ Submenu: DropdownSubmenu,
+ SubmenuTrigger: DropdownSubmenuTrigger,
+ Section: DropdownSection,
+ Separator: DropdownSeparator,
+ Loading: DropdownLoading,
+ Empty: DropdownEmpty,
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.stories.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.stories.tsx
new file mode 100644
index 00000000000..21f01d2281c
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.stories.tsx
@@ -0,0 +1,246 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, userEvent, waitFor, within } from 'storybook/test';
+
+import { IconArchive, IconCopy, IconDownload } from '@ui/icon';
+import { Button } from '@ui/primitives/input/Button/Button';
+import { ComponentDecorator } from '@ui/testing';
+
+import { Dropdown } from '../Dropdown';
+import { DropdownPagesExample } from './DropdownPagesExample';
+import { DropdownPanelExample } from './DropdownPanelExample';
+import { DropdownPickerExample } from './DropdownPickerExample';
+
+const DropdownMenuExample = () => (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger render={<Button>Record actions</Button>} />
+ <Dropdown.Content aria-label="Record actions" width={240}>
+ <Dropdown.Section>
+ <Dropdown.ActionItem startIcon={<IconCopy />}>
+ Duplicate
+ </Dropdown.ActionItem>
+ <Dropdown.Submenu>
+ <Dropdown.SubmenuTrigger startIcon={<IconDownload />}>
+ Export
+ </Dropdown.SubmenuTrigger>
+ <Dropdown.Content aria-label="Export formats">
+ <Dropdown.Section>
+ <Dropdown.ActionItem>CSV</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Excel</Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </Dropdown.Submenu>
+ </Dropdown.Section>
+ <Dropdown.Separator />
+ <Dropdown.Section>
+ <Dropdown.ActionItem startIcon={<IconArchive />}>
+ Archive
+ </Dropdown.ActionItem>
+ <Dropdown.ActionItem
+ render={
+ <a href="#dropdown-documentation" aria-label="Documentation" />
+ }
+ >
+ Documentation
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </Dropdown.Root>
+);
+
+const meta: Meta<typeof DropdownMenuExample> = {
+ title: 'UI/Components/Dropdown',
+ component: DropdownMenuExample,
+ decorators: [ComponentDecorator],
+ parameters: { container: { width: 320, height: 340 } },
+};
+
+export default meta;
+
+type Story = StoryObj<typeof DropdownMenuExample>;
+
+export const Documentation: Story = {};
+
+export const Menu: Story = {
+ parameters: {
+ a11y: {
+ config: {
+ rules: [
+ {
+ id: 'aria-hidden-focus',
+ selector: '[aria-hidden="true"]:not([data-base-ui-focus-guard])',
+ },
+ ],
+ },
+ },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const trigger = canvas.getByRole('button', { name: 'Record actions' });
+
+ await userEvent.click(trigger);
+ await waitFor(() =>
+ expect(body.getByRole('menu', { name: 'Record actions' })).toBeVisible(),
+ );
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ await expect(trigger).toHaveFocus();
+ await userEvent.keyboard('{ArrowDown}');
+ await waitFor(() =>
+ expect(body.getByRole('menuitem', { name: /Duplicate/ })).toHaveFocus(),
+ );
+ await userEvent.keyboard('{ArrowDown}{ArrowRight}');
+ await waitFor(() =>
+ expect(body.getByRole('menuitem', { name: 'CSV' })).toHaveFocus(),
+ );
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() =>
+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ await expect(trigger).toHaveFocus();
+ await userEvent.keyboard('{ArrowUp}');
+ const documentation = await body.findByRole('menuitem', {
+ name: 'Documentation',
+ });
+
+ await waitFor(() => expect(documentation).toHaveFocus());
+ await expect(documentation).toHaveAttribute(
+ 'href',
+ '#dropdown-documentation',
+ );
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ await userEvent.click(trigger);
+ await waitFor(() =>
+ expect(body.getByRole('menu', { name: 'Record actions' })).toBeVisible(),
+ );
+ },
+};
+
+export const MenuDark: Story = {
+ ...Menu,
+ globals: { colorScheme: 'dark' },
+};
+
+export const Picker: Story = {
+ render: () => <DropdownPickerExample />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Choose people' }),
+ );
+ const search = await body.findByRole('searchbox', {
+ name: 'Search people',
+ });
+
+ await waitFor(() => expect(search).toHaveFocus());
+ await userEvent.type(search, 'Grace');
+ await userEvent.keyboard('{ArrowDown}');
+ await expect(
+ body.getByRole('button', { name: 'Create Grace' }),
+ ).toHaveFocus();
+ await userEvent.keyboard('{ArrowDown}');
+ await expect(
+ body.getByRole('button', { name: 'Grace Hopper' }),
+ ).toHaveFocus();
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const MultipleSelection: Story = {
+ render: () => <DropdownPickerExample multiple />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Choose people' }),
+ );
+ await waitFor(() => expect(body.getByRole('dialog')).toBeVisible());
+ const ada = await body.findByRole('button', { name: 'Ada Lovelace' });
+
+ await userEvent.click(ada);
+ await expect(ada).toHaveAttribute('aria-pressed', 'true');
+ await expect(body.getByRole('dialog')).toBeVisible();
+ },
+};
+
+export const MultipleSelectionDark: Story = {
+ ...MultipleSelection,
+ globals: { colorScheme: 'dark' },
+};
+
+export const Loading: Story = {
+ render: () => <DropdownPickerExample loading />,
+ play: async ({ canvasElement }) => {
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Choose people' }),
+ );
+ await expect(
+ await within(canvasElement.ownerDocument.body).findByRole('status'),
+ ).toHaveTextContent('Loading people');
+ },
+};
+
+export const Pages: Story = {
+ render: () => <DropdownPagesExample />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Filters' }),
+ );
+ await userEvent.click(
+ await body.findByRole('menuitem', { name: 'Person' }),
+ );
+ const search = await body.findByRole('searchbox', {
+ name: 'Search people',
+ });
+
+ await waitFor(() => expect(search).toHaveFocus());
+ await userEvent.click(
+ within(body.getByRole('dialog')).getByRole('button', { name: 'Filters' }),
+ );
+ await waitFor(() =>
+ expect(body.getByRole('menuitem', { name: 'Person' })).toHaveFocus(),
+ );
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() =>
+ expect(
+ body.getByRole('searchbox', { name: 'Search people' }),
+ ).toHaveFocus(),
+ );
+ },
+};
+
+export const PagesDark: Story = {
+ ...Pages,
+ globals: { colorScheme: 'dark' },
+};
+
+export const Panel: Story = {
+ render: () => <DropdownPanelExample />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Edit view' }),
+ );
+ const name = await body.findByRole('textbox', { name: 'View name' });
+
+ await waitFor(() => expect(name).toHaveFocus());
+ await userEvent.clear(name);
+ await userEvent.type(name, 'My team');
+ await userEvent.click(body.getByRole('button', { name: 'Save view' }));
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPagesExample.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPagesExample.tsx
new file mode 100644
index 00000000000..8de2e5f6823
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPagesExample.tsx
@@ -0,0 +1,55 @@
+import { useState } from 'react';
+
+import { IconFilter, IconUser } from '@ui/icon';
+import { Button } from '@ui/primitives/input/Button/Button';
+
+import { Dropdown } from '../Dropdown';
+
+export const DropdownPagesExample = () => {
+ const [search, setSearch] = useState('');
+ const [selectedPerson, setSelectedPerson] = useState('');
+
+ return (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger
+ render={<Button startIcon={<IconFilter />}>Filters</Button>}
+ />
+ <Dropdown.Content aria-label="Filters" width={260}>
+ <Dropdown.Page id="root">
+ <Dropdown.Section>
+ <Dropdown.ActionItem startIcon={<IconUser />} page="people">
+ Person
+ </Dropdown.ActionItem>
+ <Dropdown.ActionItem onClick={() => setSelectedPerson('')}>
+ Clear filters
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Page>
+ <Dropdown.Page id="people" type="picker">
+ <Dropdown.Back>Filters</Dropdown.Back>
+ <Dropdown.Search
+ aria-label="Search people"
+ placeholder="Search people"
+ value={search}
+ onValueChange={setSearch}
+ />
+ <Dropdown.Section>
+ {['Ada Lovelace', 'Grace Hopper']
+ .filter((person) =>
+ person.toLowerCase().includes(search.toLowerCase()),
+ )
+ .map((person) => (
+ <Dropdown.OptionItem
+ key={person}
+ selected={selectedPerson === person}
+ onSelect={() => setSelectedPerson(person)}
+ >
+ {person}
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.Section>
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPanelExample.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPanelExample.tsx
new file mode 100644
index 00000000000..cacb0a31b15
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPanelExample.tsx
@@ -0,0 +1,33 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { useState } from 'react';
+
+import { Button } from '@ui/primitives/input/Button/Button';
+import { Field } from '@ui/primitives/input/Field/Field';
+import { Input } from '@ui/primitives/input/Input/Input';
+
+import { Dropdown } from '../Dropdown';
+
+export const DropdownPanelExample = () => {
+ const [open, setOpen] = useState(false);
+ const [name, setName] = useState('My view');
+
+ return (
+ <Dropdown.Root type="panel" open={open} onOpenChange={setOpen}>
+ <Dropdown.Trigger render={<Button>Edit view</Button>} />
+ <Dropdown.Content aria-label="Edit view" width={280}>
+ <Dropdown.Section>
+ <Field.Root>
+ <Field.Label>View name</Field.Label>
+ <Input value={name} onValueChange={setName} />
+ </Field.Root>
+ </Dropdown.Section>
+ <Dropdown.Separator />
+ <Dropdown.Section>
+ <Dropdown.ActionItem disabled={!isNonEmptyString(name.trim())}>
+ Save view
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPickerExample.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPickerExample.tsx
new file mode 100644
index 00000000000..674d12a6ca3
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/DropdownPickerExample.tsx
@@ -0,0 +1,80 @@
+import { isNonEmptyArray, isNonEmptyString } from '@sniptt/guards';
+import { useState } from 'react';
+
+import { IconPlus } from '@ui/icon';
+import { Button } from '@ui/primitives/input/Button/Button';
+
+import { Dropdown } from '../Dropdown';
+
+const PEOPLE = ['Ada Lovelace', 'Grace Hopper', 'Margaret Hamilton'];
+
+export const DropdownPickerExample = ({
+ multiple = false,
+ loading = false,
+}: {
+ multiple?: boolean;
+ loading?: boolean;
+}) => {
+ const [search, setSearch] = useState('');
+ const [people, setPeople] = useState(PEOPLE);
+ const [selectedPeople, setSelectedPeople] = useState<string[]>([]);
+ const results = people.filter((person) =>
+ person.toLowerCase().includes(search.toLowerCase()),
+ );
+ const hasSearch = isNonEmptyString(search.trim());
+
+ return (
+ <Dropdown.Root type="picker" multiple={multiple}>
+ <Dropdown.Trigger render={<Button>Choose people</Button>} />
+ <Dropdown.Content aria-label="Choose people" width={280}>
+ <Dropdown.Search
+ aria-label="Search people"
+ placeholder="Search people"
+ value={search}
+ onValueChange={setSearch}
+ />
+ <Dropdown.Section>
+ <Dropdown.ActionItem
+ startIcon={<IconPlus />}
+ disabled={!hasSearch || people.includes(search)}
+ closeOnClick={false}
+ onClick={() => {
+ setPeople((current) => [search, ...current]);
+ setSearch('');
+ }}
+ >
+ {hasSearch ? `Create ${search}` : 'Create person'}
+ </Dropdown.ActionItem>
+ {loading ? (
+ <Dropdown.Loading>Loading people</Dropdown.Loading>
+ ) : (
+ results.map((person) => (
+ <Dropdown.OptionItem
+ key={person}
+ selected={selectedPeople.includes(person)}
+ onSelect={() =>
+ setSelectedPeople((current) => {
+ if (!multiple) {
+ return [person];
+ }
+
+ return current.includes(person)
+ ? current.filter(
+ (selectedPerson) => selectedPerson !== person,
+ )
+ : [...current, person];
+ })
+ }
+ >
+ {person}
+ </Dropdown.OptionItem>
+ ))
+ )}
+ {!loading && !isNonEmptyArray(results) && (
+ <Dropdown.Empty>No people found</Dropdown.Empty>
+ )}
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.menu.test.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.menu.test.tsx
new file mode 100644
index 00000000000..a975132340c
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.menu.test.tsx
@@ -0,0 +1,401 @@
+import { render, screen, waitFor, within } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { describe, expect, it, vi } from 'vitest';
+
+import { Button } from '@ui/primitives/input/Button/Button';
+
+import { Dropdown } from '../Dropdown';
+
+const TYPEAHEAD_PAUSE_IN_MS = 600;
+
+describe('Dropdown menu', () => {
+ it('opens from the keyboard, navigates commands, and restores focus on Escape', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger render={<Button>Record actions</Button>} />
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Section label="Actions">
+ <Dropdown.ActionItem>Duplicate</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Export</Dropdown.ActionItem>
+ </Dropdown.Section>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ const trigger = screen.getByRole('button', { name: 'Record actions' });
+
+ await user.tab();
+ await user.keyboard('{ArrowDown}');
+ const actions = screen.getByRole('group', { name: 'Actions' });
+
+ await waitFor(() =>
+ expect(
+ within(actions).getByRole('menuitem', { name: 'Duplicate' }),
+ ).toHaveFocus(),
+ );
+ await user.keyboard('{ArrowDown}');
+ expect(screen.getByRole('menuitem', { name: 'Export' })).toHaveFocus();
+ await user.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ expect(trigger).toHaveFocus();
+ });
+
+ it('focuses the last item when first opened with ArrowUp and the first item when reopened by pointer', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.ActionItem>Duplicate</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Export</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ const trigger = screen.getByRole('button', { name: 'Record actions' });
+
+ await user.tab();
+ await user.keyboard('{ArrowUp}');
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Export' })).toHaveFocus(),
+ );
+ await user.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ expect(trigger).toHaveFocus();
+ await user.click(trigger);
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveFocus(),
+ );
+ });
+
+ it('prevents disabled commands and closes after an enabled command', async () => {
+ const user = userEvent.setup();
+ const archive = vi.fn();
+ const duplicate = vi.fn();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.ActionItem disabled onClick={archive}>
+ Archive
+ </Dropdown.ActionItem>
+ <Dropdown.ActionItem onClick={duplicate}>
+ Duplicate
+ </Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ await user.click(screen.getByRole('menuitem', { name: 'Archive' }));
+ expect(archive).not.toHaveBeenCalled();
+ expect(screen.getByRole('menu')).toBeVisible();
+ await user.click(screen.getByRole('menuitem', { name: 'Duplicate' }));
+ expect(duplicate).toHaveBeenCalledOnce();
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('supports menu typeahead and first or last item navigation', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.ActionItem>Duplicate</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Export</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Email</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Share</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveFocus(),
+ );
+ await user.keyboard('em');
+ expect(screen.getByRole('menuitem', { name: 'Email' })).toHaveFocus();
+ await user.keyboard('{End}');
+ expect(screen.getByRole('menuitem', { name: 'Share' })).toHaveFocus();
+ await user.keyboard('{Home}');
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveFocus();
+ });
+
+ it('cycles repeated typeahead letters and starts a fresh query after a pause', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.ActionItem>Duplicate</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Export</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Email</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Share</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveFocus(),
+ );
+
+ const startTimestamp = Date.now();
+ const now = vi.spyOn(Date, 'now').mockReturnValue(startTimestamp);
+
+ try {
+ await user.keyboard('e');
+ expect(screen.getByRole('menuitem', { name: 'Export' })).toHaveFocus();
+ await user.keyboard('e');
+ expect(screen.getByRole('menuitem', { name: 'Email' })).toHaveFocus();
+ await user.keyboard('e');
+ expect(screen.getByRole('menuitem', { name: 'Export' })).toHaveFocus();
+
+ now.mockReturnValue(startTimestamp + TYPEAHEAD_PAUSE_IN_MS);
+
+ await user.keyboard('s');
+ expect(screen.getByRole('menuitem', { name: 'Share' })).toHaveFocus();
+ } finally {
+ now.mockRestore();
+ }
+ });
+
+ it('keeps repeated actions open and dismisses when clicking outside', async () => {
+ const user = userEvent.setup();
+ const duplicate = vi.fn();
+
+ render(
+ <>
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.ActionItem closeOnClick={false} onClick={duplicate}>
+ Duplicate
+ </Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ <Button>Outside</Button>
+ </>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ const action = screen.getByRole('menuitem', { name: 'Duplicate' });
+
+ await user.click(action);
+ await user.click(action);
+ expect(duplicate).toHaveBeenCalledTimes(2);
+ expect(screen.getByRole('menu')).toBeVisible();
+ await user.click(screen.getByRole('button', { name: 'Outside' }));
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('preserves link targets and handles their keyboard activation', async () => {
+ const user = userEvent.setup();
+ const navigate = vi.fn();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Help</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Help">
+ <Dropdown.ActionItem
+ render={<a href="#documentation" aria-label="Documentation" />}
+ onClick={navigate}
+ >
+ Documentation
+ </Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.tab();
+ await user.keyboard('{ArrowDown}');
+ const link = await screen.findByRole('menuitem', { name: 'Documentation' });
+
+ expect(link).toHaveAttribute('href', '#documentation');
+ await waitFor(() => expect(link).toHaveFocus());
+ await user.keyboard('{Enter}');
+ expect(navigate).toHaveBeenCalledOnce();
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('opens a side submenu from the keyboard and closes the full menu on selection', async () => {
+ const user = userEvent.setup();
+ const exportRecords = vi.fn();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Submenu>
+ <Dropdown.SubmenuTrigger>Export</Dropdown.SubmenuTrigger>
+ <Dropdown.Content aria-label="Export formats">
+ <Dropdown.ActionItem onClick={exportRecords}>
+ CSV
+ </Dropdown.ActionItem>
+ <Dropdown.ActionItem>Excel</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Submenu>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.tab();
+ await user.keyboard('{ArrowDown}');
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Export' })).toHaveFocus(),
+ );
+ await user.keyboard('{ArrowRight}');
+ const csv = await screen.findByRole('menuitem', { name: 'CSV' });
+
+ await waitFor(() => expect(csv).toHaveFocus());
+ await user.keyboard('{Enter}');
+ expect(exportRecords).toHaveBeenCalledOnce();
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ expect(
+ screen.getByRole('button', { name: 'Record actions' }),
+ ).toHaveFocus();
+ });
+
+ it.each([
+ {
+ direction: 'ltr',
+ forwardKey: '{ArrowRight}',
+ backwardKey: '{ArrowLeft}',
+ },
+ {
+ direction: 'rtl',
+ forwardKey: '{ArrowLeft}',
+ backwardKey: '{ArrowRight}',
+ },
+ ] as const)(
+ 'preserves text editing and submenu navigation in $direction layout',
+ async ({ direction, forwardKey, backwardKey }) => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Filters</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Filters" style={{ direction }}>
+ <Dropdown.Submenu type="picker">
+ <Dropdown.SubmenuTrigger style={{ direction }}>
+ People
+ </Dropdown.SubmenuTrigger>
+ <Dropdown.Content
+ aria-label="Choose person"
+ style={{ direction }}
+ >
+ <Dropdown.Search
+ aria-label="Search people"
+ defaultValue="Ada"
+ />
+ <Dropdown.OptionItem selected={false}>
+ Ada Lovelace
+ </Dropdown.OptionItem>
+ </Dropdown.Content>
+ </Dropdown.Submenu>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.tab();
+ await user.keyboard('{ArrowDown}');
+ const people = await screen.findByRole('menuitem', { name: 'People' });
+
+ await waitFor(() => expect(people).toHaveFocus());
+ await user.keyboard(forwardKey);
+ const search = await screen.findByRole('searchbox', {
+ name: 'Search people',
+ });
+
+ await waitFor(() => expect(search).toHaveFocus());
+ await user.keyboard(backwardKey);
+ expect(
+ screen.getByRole('dialog', { name: 'Choose person' }),
+ ).toBeVisible();
+ expect(search).toHaveFocus();
+ await user.keyboard('{ArrowDown}');
+ expect(
+ screen.getByRole('button', { name: 'Ada Lovelace' }),
+ ).toHaveFocus();
+ await user.keyboard(backwardKey);
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ expect(screen.getByRole('menu', { name: 'Filters' })).toBeVisible();
+ await waitFor(() => expect(people).toHaveFocus());
+ },
+ );
+
+ it('dismisses on Tab and continues to the next control outside the menu', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <>
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.ActionItem>Duplicate</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Export</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ <Button>Next control</Button>
+ </>,
+ );
+
+ await user.tab();
+ await user.keyboard('{ArrowDown}');
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveFocus(),
+ );
+ await user.tab();
+ await waitFor(() =>
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ expect(screen.getByRole('button', { name: 'Next control' })).toHaveFocus();
+ });
+
+ it('keeps popup keyboard activation from activating a parent record row', async () => {
+ const user = userEvent.setup();
+ const activateRow = vi.fn();
+ const duplicate = vi.fn();
+
+ render(
+ <div role="row" tabIndex={0} onKeyDown={activateRow}>
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.ActionItem onClick={duplicate}>
+ Duplicate
+ </Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ </div>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveFocus(),
+ );
+ await user.keyboard('{Enter}');
+ expect(duplicate).toHaveBeenCalledOnce();
+ expect(activateRow).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.pages.test.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.pages.test.tsx
new file mode 100644
index 00000000000..f4046129fe1
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.pages.test.tsx
@@ -0,0 +1,382 @@
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { useState } from 'react';
+import { describe, expect, it } from 'vitest';
+
+import { Input } from '@ui/primitives/input/Input/Input';
+
+import { Dropdown } from '../Dropdown';
+import { type DropdownType } from '../types/DropdownType';
+
+type FilterPagesProps = {
+ actions?: { label: string; page?: string }[];
+ keepMounted?: boolean;
+};
+
+const FilterPages = ({
+ actions = [
+ { label: 'People', page: 'people' },
+ { label: 'Recent people', page: 'people' },
+ { label: 'Clear filters' },
+ ],
+ keepMounted,
+}: FilterPagesProps) => {
+ const [search, setSearch] = useState('');
+
+ return (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Filters</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Filters" keepMounted={keepMounted}>
+ <Dropdown.Page id="root">
+ {actions.map(({ label, page }) => (
+ <Dropdown.ActionItem key={label} page={page}>
+ {label}
+ </Dropdown.ActionItem>
+ ))}
+ </Dropdown.Page>
+ <Dropdown.Page id="people" type="picker">
+ <Dropdown.Back>Back to filters</Dropdown.Back>
+ <Dropdown.Search
+ aria-label="Search people"
+ value={search}
+ onValueChange={setSearch}
+ />
+ <Dropdown.OptionItem selected={false}>
+ Ada Lovelace
+ </Dropdown.OptionItem>
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
+
+describe('Dropdown pages', () => {
+ it('keeps the current page and focus when navigation is prevented', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Page id="root">
+ <Dropdown.ActionItem
+ page="edit"
+ onClick={(event) => event.preventDefault()}
+ >
+ Edit
+ </Dropdown.ActionItem>
+ </Dropdown.Page>
+ <Dropdown.Page id="edit" type="panel">
+ <Input aria-label="Name" />
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ const edit = screen.getByRole('menuitem', { name: 'Edit' });
+
+ await user.click(edit);
+
+ expect(edit).toHaveFocus();
+ expect(
+ screen.queryByRole('textbox', { name: 'Name' }),
+ ).not.toBeInTheDocument();
+ });
+
+ it('preserves focus when the destination page arrives after navigation', async () => {
+ const user = userEvent.setup();
+ const DeferredPages = ({ isLoaded }: { isLoaded: boolean }) => (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Page id="root">
+ <Dropdown.ActionItem page="edit">Edit</Dropdown.ActionItem>
+ </Dropdown.Page>
+ {isLoaded && (
+ <Dropdown.Page id="edit" type="panel">
+ <Input aria-label="Name" />
+ <Dropdown.Back>Back to actions</Dropdown.Back>
+ </Dropdown.Page>
+ )}
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+ const { rerender } = render(<DeferredPages isLoaded={false} />);
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ await user.click(screen.getByRole('menuitem', { name: 'Edit' }));
+
+ const content = screen.getByRole('menu', { name: 'Record actions' });
+
+ await waitFor(() => expect(content).toHaveFocus());
+ rerender(<DeferredPages isLoaded />);
+
+ expect(screen.getByRole('textbox', { name: 'Name' })).toBeVisible();
+ expect(content).toHaveFocus();
+ });
+
+ it('does not repeat navigation focus when the active page remounts', async () => {
+ const user = userEvent.setup();
+ const EditPages = ({ revision }: { revision: number }) => (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Page id="root">
+ <Dropdown.ActionItem page="edit">Edit</Dropdown.ActionItem>
+ </Dropdown.Page>
+ <Dropdown.Page key={revision} id="edit" type="panel">
+ <Input aria-label="Name" />
+ </Dropdown.Page>
+ <Input aria-label="Notes" />
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+ const { rerender } = render(<EditPages revision={0} />);
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ await user.click(screen.getByRole('menuitem', { name: 'Edit' }));
+ await waitFor(() =>
+ expect(screen.getByRole('textbox', { name: 'Name' })).toHaveFocus(),
+ );
+ await user.tab();
+ const notes = screen.getByRole('textbox', { name: 'Notes' });
+
+ expect(notes).toHaveFocus();
+ rerender(<EditPages revision={1} />);
+
+ expect(screen.getByRole('textbox', { name: 'Name' })).toBeVisible();
+ expect(notes).toHaveFocus();
+ });
+
+ it('uses the default page type and preserves the initial keyboard focus edge', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="picker" defaultPage="actions">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Page id="actions" type="menu">
+ <Dropdown.ActionItem>Duplicate</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Export</Dropdown.ActionItem>
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.tab();
+ await user.keyboard('{ArrowUp}');
+ expect(screen.getByRole('menu', { name: 'Record actions' })).toBeVisible();
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Export' })).toHaveFocus(),
+ );
+ });
+
+ it('uses native form focus when the default page overrides a menu with a panel', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu" defaultPage="edit">
+ <Dropdown.Trigger>Edit details</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Edit details">
+ <Dropdown.Page id="edit" type="panel">
+ <Input aria-label="Name" />
+ <Dropdown.ActionItem>Save</Dropdown.ActionItem>
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.tab();
+ await user.keyboard('{ArrowUp}');
+ expect(screen.getByRole('dialog', { name: 'Edit details' })).toBeVisible();
+ await waitFor(() =>
+ expect(screen.getByRole('textbox', { name: 'Name' })).toHaveFocus(),
+ );
+ });
+
+ it('preserves editing focus when an active page rerenders or changes type', async () => {
+ const user = userEvent.setup();
+ const EditPages = ({ pageType }: { pageType: DropdownType }) => {
+ const [name, setName] = useState('Acme');
+ const [website, setWebsite] = useState('acme.example');
+
+ return (
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions">
+ <Dropdown.Page id="root">
+ <Dropdown.ActionItem page="edit">Edit</Dropdown.ActionItem>
+ </Dropdown.Page>
+ <Dropdown.Page id="edit" type={pageType}>
+ <Input aria-label="Name" value={name} onValueChange={setName} />
+ <Input
+ aria-label="Website"
+ value={website}
+ onValueChange={setWebsite}
+ />
+ <Dropdown.Back>Back to actions</Dropdown.Back>
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+ };
+ const { rerender } = render(<EditPages pageType="panel" />);
+
+ await user.click(screen.getByRole('button', { name: 'Record actions' }));
+ await user.click(screen.getByRole('menuitem', { name: 'Edit' }));
+
+ const name = screen.getByRole('textbox', { name: 'Name' });
+ const website = screen.getByRole('textbox', { name: 'Website' });
+
+ await waitFor(() => expect(name).toHaveFocus());
+ await user.keyboard(' company');
+ expect(name).toHaveValue('Acme company');
+ await user.tab();
+ expect(website).toHaveFocus();
+ await user.keyboard('{End}/contact');
+ expect(website).toHaveValue('acme.example/contact');
+ expect(website).toHaveFocus();
+
+ rerender(<EditPages pageType="menu" />);
+
+ expect(screen.getByRole('menu', { name: 'Record actions' })).toBeVisible();
+ expect(website).toHaveFocus();
+ await user.click(screen.getByRole('menuitem', { name: 'Back to actions' }));
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'Edit' })).toHaveFocus(),
+ );
+ });
+
+ it('respects disabled initial focus when the default page mounts', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Filters</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Filters" initialFocus={false}>
+ <Dropdown.Page id="root" type="picker">
+ <Dropdown.Search aria-label="Search people" />
+ </Dropdown.Page>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ const trigger = screen.getByRole('button', { name: 'Filters' });
+
+ await user.click(trigger);
+
+ expect(screen.getByRole('dialog', { name: 'Filters' })).toBeVisible();
+ expect(trigger).toHaveFocus();
+ });
+
+ it('changes interaction type in the same popup and restores the invoking row on back', async () => {
+ const user = userEvent.setup();
+
+ render(<FilterPages />);
+
+ await user.click(screen.getByRole('button', { name: 'Filters' }));
+ expect(screen.getByRole('menu', { name: 'Filters' })).toBeVisible();
+ await user.click(screen.getByRole('menuitem', { name: 'People' }));
+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();
+ expect(screen.getByRole('dialog', { name: 'Filters' })).toBeVisible();
+ await waitFor(() =>
+ expect(
+ screen.getByRole('searchbox', { name: 'Search people' }),
+ ).toHaveFocus(),
+ );
+ await user.click(screen.getByRole('button', { name: 'Back to filters' }));
+ expect(screen.getByRole('menu', { name: 'Filters' })).toBeVisible();
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'People' })).toHaveFocus(),
+ );
+ });
+
+ it.each([false, true])(
+ 'resets navigation to the root page after dismissal with keepMounted=%s',
+ async (keepMounted) => {
+ const user = userEvent.setup();
+
+ render(<FilterPages keepMounted={keepMounted} />);
+
+ const trigger = screen.getByRole('button', { name: 'Filters' });
+
+ await user.click(trigger);
+ await user.click(screen.getByRole('menuitem', { name: 'People' }));
+ await user.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ expect(trigger).toHaveFocus();
+ await user.click(trigger);
+ expect(screen.getByRole('menuitem', { name: 'People' })).toBeVisible();
+ expect(screen.queryByRole('searchbox')).not.toBeInTheDocument();
+ },
+ );
+
+ it('returns focus to the selected entrypoint when several actions open the same page', async () => {
+ const user = userEvent.setup();
+
+ render(<FilterPages />);
+
+ await user.click(screen.getByRole('button', { name: 'Filters' }));
+ await user.click(screen.getByRole('menuitem', { name: 'Recent people' }));
+ await user.click(screen.getByRole('button', { name: 'Back to filters' }));
+ await waitFor(() =>
+ expect(
+ screen.getByRole('menuitem', { name: 'Recent people' }),
+ ).toHaveFocus(),
+ );
+ });
+
+ it('restores the invoking action after its page remounts with reordered entrypoints', async () => {
+ const user = userEvent.setup();
+ const { rerender } = render(<FilterPages />);
+
+ await user.click(screen.getByRole('button', { name: 'Filters' }));
+ await user.click(screen.getByRole('menuitem', { name: 'Recent people' }));
+ rerender(
+ <FilterPages
+ actions={[
+ { label: 'Recent people', page: 'people' },
+ { label: 'People', page: 'people' },
+ ]}
+ />,
+ );
+ await user.click(screen.getByRole('button', { name: 'Back to filters' }));
+ await waitFor(() =>
+ expect(
+ screen.getByRole('menuitem', { name: 'Recent people' }),
+ ).toHaveFocus(),
+ );
+ });
+
+ it('restores the unique destination when its action moves and changes label', async () => {
+ const user = userEvent.setup();
+ const { rerender } = render(
+ <FilterPages
+ actions={[
+ { label: 'People', page: 'people' },
+ { label: 'Clear filters' },
+ ]}
+ />,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Filters' }));
+ await user.click(screen.getByRole('menuitem', { name: 'People' }));
+ rerender(
+ <FilterPages
+ actions={[
+ { label: 'Clear filters' },
+ { label: 'All people', page: 'people' },
+ ]}
+ />,
+ );
+ await user.click(screen.getByRole('button', { name: 'Back to filters' }));
+ await waitFor(() =>
+ expect(
+ screen.getByRole('menuitem', { name: 'All people' }),
+ ).toHaveFocus(),
+ );
+ });
+});
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.panel.test.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.panel.test.tsx
new file mode 100644
index 00000000000..ce2d13450d4
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.panel.test.tsx
@@ -0,0 +1,130 @@
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { createRef, useState } from 'react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { Button } from '@ui/primitives/input/Button/Button';
+import { Input } from '@ui/primitives/input/Input/Input';
+
+import { Dropdown } from '../Dropdown';
+
+describe('Dropdown panel', () => {
+ it('keeps form editing open and allows native tab navigation', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="panel">
+ <Dropdown.Trigger render={<Button>Edit details</Button>} />
+ <Dropdown.Content aria-label="Edit details">
+ <Input aria-label="Name" defaultValue="Acme" />
+ <Input aria-label="Website" defaultValue="https://acme.example" />
+ <Dropdown.ActionItem>Save</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ const trigger = screen.getByRole('button', { name: 'Edit details' });
+
+ await user.click(trigger);
+ const name = screen.getByRole('textbox', { name: 'Name' });
+
+ await waitFor(() => expect(name).toHaveFocus());
+ await user.type(name, ' company');
+ expect(name).toHaveValue('Acme company');
+ await user.tab();
+ expect(screen.getByRole('textbox', { name: 'Website' })).toHaveFocus();
+ expect(screen.getByRole('dialog')).toBeVisible();
+ await user.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ expect(trigger).toHaveFocus();
+ });
+
+ it('reports visibility requests while the owner retains control', async () => {
+ const user = userEvent.setup();
+ const onOpenChange = vi.fn();
+ const { rerender } = render(
+ <Dropdown.Root type="panel" open onOpenChange={onOpenChange}>
+ <Dropdown.Trigger>Details</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Details">
+ <Input aria-label="Name" />
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await screen.findByRole('dialog', { name: 'Details' });
+ await user.keyboard('{Escape}');
+ expect(onOpenChange).toHaveBeenCalledWith(false);
+ expect(screen.getByRole('dialog')).toBeVisible();
+ rerender(
+ <Dropdown.Root type="panel" open={false} onOpenChange={onOpenChange}>
+ <Dropdown.Trigger>Details</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Details">
+ <Input aria-label="Name" />
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('supports external opening through feature-owned state', async () => {
+ const user = userEvent.setup();
+ const ControlledPanel = () => {
+ const [open, setOpen] = useState(false);
+
+ return (
+ <>
+ <Button onClick={() => setOpen(true)}>Edit from toolbar</Button>
+ <Dropdown.Root type="panel" open={open} onOpenChange={setOpen}>
+ <Dropdown.Trigger>Details</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Details">
+ <Input aria-label="Name" />
+ <Dropdown.ActionItem>Save</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ </>
+ );
+ };
+
+ render(<ControlledPanel />);
+
+ await user.click(screen.getByRole('button', { name: 'Edit from toolbar' }));
+ expect(
+ await screen.findByRole('dialog', { name: 'Details' }),
+ ).toBeVisible();
+ await user.click(screen.getByRole('button', { name: 'Save' }));
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('restores focus to an explicit editor target after an action', async () => {
+ const user = userEvent.setup();
+ const editorRef = createRef<HTMLInputElement>();
+
+ render(
+ <>
+ <Input aria-label="Editor" ref={editorRef} />
+ <Dropdown.Root type="panel">
+ <Dropdown.Trigger>Insert link</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Insert link" finalFocus={editorRef}>
+ <Input aria-label="Link address" />
+ <Dropdown.ActionItem>Insert</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ </>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Insert link' }));
+ await user.click(screen.getByRole('button', { name: 'Insert' }));
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ await waitFor(() =>
+ expect(screen.getByRole('textbox', { name: 'Editor' })).toHaveFocus(),
+ );
+ });
+});
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.picker.test.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.picker.test.tsx
new file mode 100644
index 00000000000..069a5d3d67d
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.picker.test.tsx
@@ -0,0 +1,197 @@
+import { isNonEmptyArray } from '@sniptt/guards';
+import { render, screen, waitFor, within } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { useState } from 'react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { Dropdown } from '../Dropdown';
+
+const PEOPLE = ['Ada Lovelace', 'Grace Hopper', 'Margaret Hamilton'];
+
+const SearchablePicker = ({
+ multiple = false,
+ onCreate,
+}: {
+ multiple?: boolean;
+ onCreate: () => void;
+}) => {
+ const [search, setSearch] = useState('');
+ const [selectedPeople, setSelectedPeople] = useState<string[]>([]);
+ const results = PEOPLE.filter((person) =>
+ person.toLowerCase().includes(search.toLowerCase()),
+ );
+
+ return (
+ <Dropdown.Root type="picker" multiple={multiple}>
+ <Dropdown.Trigger>Assignees</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Choose assignees">
+ <Dropdown.Search
+ aria-label="Search people"
+ value={search}
+ onValueChange={setSearch}
+ />
+ <Dropdown.ActionItem onClick={onCreate}>
+ Create person
+ </Dropdown.ActionItem>
+ {results.map((person) => (
+ <Dropdown.OptionItem
+ key={person}
+ selected={selectedPeople.includes(person)}
+ onSelect={() =>
+ setSelectedPeople((current) =>
+ current.includes(person)
+ ? current.filter(
+ (selectedPerson) => selectedPerson !== person,
+ )
+ : [...current, person],
+ )
+ }
+ >
+ {person}
+ </Dropdown.OptionItem>
+ ))}
+ {!isNonEmptyArray(results) && (
+ <Dropdown.Empty>No people found</Dropdown.Empty>
+ )}
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
+
+describe('Dropdown picker', () => {
+ it('filters caller-owned results and navigates mixed commands and options from search', async () => {
+ const user = userEvent.setup();
+
+ render(<SearchablePicker onCreate={vi.fn()} />);
+
+ await user.click(screen.getByRole('button', { name: 'Assignees' }));
+ const dialog = await screen.findByRole('dialog', {
+ name: 'Choose assignees',
+ });
+ const search = within(dialog).getByRole('searchbox', {
+ name: 'Search people',
+ });
+
+ await waitFor(() => expect(search).toHaveFocus());
+ await user.type(search, 'grace');
+ expect(
+ screen.queryByRole('button', { name: 'Ada Lovelace' }),
+ ).not.toBeInTheDocument();
+ await user.keyboard('{ArrowDown}');
+ expect(screen.getByRole('button', { name: 'Create person' })).toHaveFocus();
+ await user.keyboard('{ArrowDown}');
+ expect(screen.getByRole('button', { name: 'Grace Hopper' })).toHaveFocus();
+ await user.keyboard('{Enter}');
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ expect(screen.getByRole('button', { name: 'Assignees' })).toHaveFocus();
+ });
+
+ it('keeps multiple selections open and exposes their selected state', async () => {
+ const user = userEvent.setup();
+
+ render(<SearchablePicker multiple onCreate={vi.fn()} />);
+
+ await user.click(screen.getByRole('button', { name: 'Assignees' }));
+ const ada = screen.getByRole('button', { name: 'Ada Lovelace' });
+ const grace = screen.getByRole('button', { name: 'Grace Hopper' });
+
+ await user.click(ada);
+ await user.click(grace);
+ expect(ada).toHaveAttribute('aria-pressed', 'true');
+ expect(grace).toHaveAttribute('aria-pressed', 'true');
+ await user.click(ada);
+ expect(ada).toHaveAttribute('aria-pressed', 'false');
+ expect(screen.getByRole('dialog')).toBeVisible();
+ });
+
+ it('closes a mixed picker after an inline action even with multiple selection enabled', async () => {
+ const user = userEvent.setup();
+ const createPerson = vi.fn();
+
+ render(<SearchablePicker multiple onCreate={createPerson} />);
+
+ await user.click(screen.getByRole('button', { name: 'Assignees' }));
+ await user.click(screen.getByRole('button', { name: 'Create person' }));
+ expect(createPerson).toHaveBeenCalledOnce();
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('announces empty results without treating the message as a selectable result', async () => {
+ const user = userEvent.setup();
+
+ render(<SearchablePicker onCreate={vi.fn()} />);
+
+ await user.click(screen.getByRole('button', { name: 'Assignees' }));
+ await user.type(
+ screen.getByRole('searchbox', { name: 'Search people' }),
+ 'unknown',
+ );
+ expect(screen.getByRole('status')).toHaveTextContent('No people found');
+ await user.keyboard('{ArrowDown}');
+ expect(screen.getByRole('button', { name: 'Create person' })).toHaveFocus();
+ });
+
+ it('supports selection close overrides and blocks disabled options', async () => {
+ const user = userEvent.setup();
+ const selectArchived = vi.fn();
+ const selectActive = vi.fn();
+
+ render(
+ <Dropdown.Root type="picker">
+ <Dropdown.Trigger>Status</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Choose status">
+ <Dropdown.OptionItem
+ selected={false}
+ disabled
+ onSelect={selectArchived}
+ >
+ Archived
+ </Dropdown.OptionItem>
+ <Dropdown.OptionItem
+ selected={false}
+ closeOnSelect={false}
+ onSelect={selectActive}
+ >
+ Active
+ </Dropdown.OptionItem>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'Status' }));
+ await user.click(screen.getByRole('button', { name: 'Archived' }));
+ expect(selectArchived).not.toHaveBeenCalled();
+ await user.click(screen.getByRole('button', { name: 'Active' }));
+ expect(selectActive).toHaveBeenCalledOnce();
+ expect(screen.getByRole('dialog')).toBeVisible();
+ });
+
+ it('renders caller-supplied loading status while server results are pending', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="picker">
+ <Dropdown.Trigger>People</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Choose a person">
+ <Dropdown.Search
+ aria-label="Search people"
+ value="Ada"
+ onValueChange={vi.fn()}
+ />
+ <Dropdown.Loading>Loading people</Dropdown.Loading>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'People' }));
+ expect(screen.getByRole('status')).toHaveTextContent('Loading people');
+ await user.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ });
+});
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.submenu.test.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.submenu.test.tsx
new file mode 100644
index 00000000000..41f476e1d19
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.submenu.test.tsx
@@ -0,0 +1,58 @@
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { describe, expect, it } from 'vitest';
+
+import { Dropdown } from '../Dropdown';
+
+describe('Dropdown submenu hover', () => {
+ it.each([
+ { direction: 'ltr', forwardKey: '{ArrowRight}', dismissKey: '{ArrowLeft}' },
+ { direction: 'rtl', forwardKey: '{ArrowLeft}', dismissKey: '{ArrowRight}' },
+ { direction: 'ltr', forwardKey: '{ArrowRight}', dismissKey: '{Escape}' },
+ ] as const)(
+ 'enters a hovered submenu and restores focus with $dismissKey in $direction layout',
+ async ({ direction, forwardKey, dismissKey }) => {
+ const user = userEvent.setup();
+
+ render(
+ <Dropdown.Root type="menu">
+ <Dropdown.Trigger>Record actions</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Record actions" style={{ direction }}>
+ <Dropdown.Submenu>
+ <Dropdown.SubmenuTrigger delay={0} style={{ direction }}>
+ Export
+ </Dropdown.SubmenuTrigger>
+ <Dropdown.Content
+ aria-label="Export formats"
+ style={{ direction }}
+ >
+ <Dropdown.ActionItem>CSV</Dropdown.ActionItem>
+ <Dropdown.ActionItem>Excel</Dropdown.ActionItem>
+ </Dropdown.Content>
+ </Dropdown.Submenu>
+ </Dropdown.Content>
+ </Dropdown.Root>,
+ );
+
+ await user.tab();
+ await user.keyboard('{ArrowDown}');
+ const trigger = await screen.findByRole('menuitem', { name: 'Export' });
+
+ await waitFor(() => expect(trigger).toHaveFocus());
+ await user.hover(trigger);
+ await screen.findByRole('menu', { name: 'Export formats' });
+ expect(trigger).toHaveFocus();
+ await user.keyboard(forwardKey);
+ await waitFor(() =>
+ expect(screen.getByRole('menuitem', { name: 'CSV' })).toHaveFocus(),
+ );
+ await user.keyboard(dismissKey);
+ await waitFor(() =>
+ expect(
+ screen.queryByRole('menu', { name: 'Export formats' }),
+ ).not.toBeInTheDocument(),
+ );
+ expect(trigger).toHaveFocus();
+ },
+ );
+});
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownActionItem.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownActionItem.tsx
new file mode 100644
index 00000000000..2cf95e0de0d
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownActionItem.tsx
@@ -0,0 +1,103 @@
+import { Button as ButtonPrimitive } from '@base-ui/react/button';
+import { useId } from 'react';
+
+import { ListItem } from '@ui/primitives/navigation/ListItem/ListItem';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type DropdownActionItemProps } from '../types/DropdownActionItemProps';
+import { getDropdownItemLabel } from './getDropdownItemLabel';
+import { getDropdownItems } from './getDropdownItems';
+import { useDropdownContext } from './useDropdownContext';
+import { useDropdownItemFocus } from './useDropdownItemFocus';
+
+export const DropdownActionItem = ({
+ color,
+ startIcon,
+ endIcon,
+ description,
+ descriptionPlacement,
+ hotkeys,
+ hasSubmenu,
+ children,
+ render,
+ disabled = false,
+ nativeButton = !isDefined(render),
+ closeOnClick = true,
+ onClick,
+ onFocus,
+ page,
+ id,
+ ...props
+}: DropdownActionItemProps) => {
+ const { type, closeTree, goToPage } = useDropdownContext();
+ const generatedId = useId();
+ const itemId = id ?? generatedId;
+ const itemFocus = useDropdownItemFocus({ id: itemId });
+
+ return (
+ <ButtonPrimitive
+ {...props}
+ id={itemId}
+ disabled={disabled}
+ nativeButton={nativeButton}
+ role={props.role ?? (type === 'menu' ? 'menuitem' : undefined)}
+ tabIndex={itemFocus.tabIndex}
+ onFocus={(event) => {
+ itemFocus.activate();
+ onFocus?.(event);
+ }}
+ data-dropdown-item=""
+ data-dropdown-page={page}
+ onClick={(event) => {
+ onClick?.(event);
+
+ if (event.defaultPrevented) {
+ return;
+ }
+
+ if (isDefined(page)) {
+ const content = event.currentTarget.closest<HTMLElement>(
+ '[data-dropdown-content]',
+ );
+
+ if (!isDefined(content)) {
+ return;
+ }
+
+ const index = getDropdownItems(content).indexOf(event.currentTarget);
+
+ goToPage({
+ id: page,
+ trigger: {
+ id,
+ index,
+ page,
+ label: getDropdownItemLabel(event.currentTarget),
+ },
+ });
+ return;
+ }
+
+ if (closeOnClick) {
+ closeTree();
+ }
+ }}
+ render={(renderProps) => (
+ <ListItem
+ {...renderProps}
+ render={render ?? <button type="button" />}
+ disabled={disabled}
+ color={color}
+ startIcon={startIcon}
+ endIcon={endIcon}
+ description={description}
+ descriptionPlacement={descriptionPlacement}
+ hotkeys={hotkeys}
+ hasSubmenu={hasSubmenu ?? isDefined(page)}
+ >
+ {children}
+ </ListItem>
+ )}
+ />
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownBack.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownBack.tsx
new file mode 100644
index 00000000000..07009f4bc96
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownBack.tsx
@@ -0,0 +1,39 @@
+import { clsx } from 'clsx';
+
+import { IconChevronLeft } from '@ui/icon';
+
+import styles from '../Dropdown.module.scss';
+import { type DropdownActionItemProps } from '../types/DropdownActionItemProps';
+import { DropdownActionItem } from './DropdownActionItem';
+import { useDropdownContext } from './useDropdownContext';
+
+export const DropdownBack = ({
+ children = 'Back',
+ className,
+ onClick,
+ ...props
+}: Omit<DropdownActionItemProps, 'page' | 'closeOnClick'>) => {
+ const { goBack, canGoBack } = useDropdownContext();
+
+ return (
+ <DropdownActionItem
+ {...props}
+ className={clsx(styles.back, className)}
+ data-dropdown-back=""
+ disabled={props.disabled || !canGoBack}
+ startIcon={<IconChevronLeft />}
+ closeOnClick={false}
+ onClick={(event) => {
+ onClick?.(event);
+
+ if (event.defaultPrevented) {
+ return;
+ }
+
+ goBack();
+ }}
+ >
+ {children}
+ </DropdownActionItem>
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx
new file mode 100644
index 00000000000..95dafede3df
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx
@@ -0,0 +1,107 @@
+import { useMergedRefs } from '@base-ui/utils/useMergedRefs';
+import { isFunction } from '@sniptt/guards';
+import { useRef } from 'react';
+
+import { Popover } from '@ui/primitives/surfaces/Popover/Popover';
+import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import styles from '../Dropdown.module.scss';
+import { type DropdownContentProps } from '../types/DropdownContentProps';
+import { DropdownPageFocusEffect } from './DropdownPageFocusEffect';
+import { getDropdownFocusTarget } from './getDropdownFocusTarget';
+import { useDropdownContext } from './useDropdownContext';
+import { useDropdownKeyboardNavigation } from './useDropdownKeyboardNavigation';
+
+export const DropdownContent = ({
+ side,
+ align = 'start',
+ sideOffset = 0,
+ alignOffset,
+ anchor,
+ container,
+ keepMounted,
+ width = 200,
+ className,
+ style,
+ children,
+ initialFocus,
+ onKeyDown,
+ onClick,
+ onMouseDown,
+ onPointerDown,
+ ref,
+ ...props
+}: DropdownContentProps) => {
+ const { type, isSubmenu, setOpen, initialFocusEdge, focusOnOpen } =
+ useDropdownContext();
+ const contentRef = useRef<HTMLDivElement>(null);
+ const mergedRef = useMergedRefs(contentRef, ref);
+ const handleNavigation = useDropdownKeyboardNavigation({
+ type,
+ isSubmenu,
+ setOpen,
+ });
+
+ return (
+ <>
+ <Popover.Popup
+ {...props}
+ ref={mergedRef}
+ side={side ?? (isSubmenu ? 'inline-end' : 'bottom')}
+ align={align}
+ sideOffset={sideOffset}
+ alignOffset={alignOffset}
+ anchor={anchor}
+ container={container}
+ keepMounted={keepMounted}
+ role={type === 'menu' ? 'menu' : 'dialog'}
+ data-dropdown-content=""
+ data-type={type}
+ className={mergeClassNames(styles.content, className)}
+ style={(state) => ({
+ width,
+ ...(isFunction(style) ? style(state) : style),
+ })}
+ initialFocus={
+ initialFocus ??
+ (() => {
+ if (!focusOnOpen) {
+ return false;
+ }
+
+ if (!isDefined(contentRef.current)) {
+ return true;
+ }
+
+ return getDropdownFocusTarget({
+ content: contentRef.current,
+ edge: initialFocusEdge,
+ type,
+ });
+ })
+ }
+ onKeyDown={(event) => {
+ event.stopPropagation();
+ onKeyDown?.(event);
+ handleNavigation(event);
+ }}
+ onClick={(event) => {
+ event.stopPropagation();
+ onClick?.(event);
+ }}
+ onMouseDown={(event) => {
+ event.stopPropagation();
+ onMouseDown?.(event);
+ }}
+ onPointerDown={(event) => {
+ event.stopPropagation();
+ onPointerDown?.(event);
+ }}
+ >
+ {children}
+ </Popover.Popup>
+ <DropdownPageFocusEffect contentRef={contentRef} />
+ </>
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContext.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContext.ts
new file mode 100644
index 00000000000..9836730279a
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContext.ts
@@ -0,0 +1,7 @@
+import { createContext } from 'react';
+
+import { type DropdownContextValue } from './DropdownContextValue';
+
+export const DropdownContext = createContext<DropdownContextValue | undefined>(
+ undefined,
+);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContextValue.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContextValue.ts
new file mode 100644
index 00000000000..52039ec3aa5
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContextValue.ts
@@ -0,0 +1,29 @@
+import { type DropdownType } from '../types/DropdownType';
+import { type DropdownFocusTarget } from './DropdownFocusTarget';
+import { type DropdownPageFocusRequest } from './DropdownPageFocusRequest';
+
+export type DropdownContextValue = {
+ type: DropdownType;
+ rootType: DropdownType;
+ open: boolean;
+ multiple: boolean;
+ isSubmenu: boolean;
+ parentType?: DropdownType;
+ activeItemId?: string;
+ parentActiveItemId?: string;
+ setActiveItemId: (id: string) => void;
+ setParentActiveItemId?: (id: string) => void;
+ pageId?: string;
+ pageFocusRequest?: DropdownPageFocusRequest;
+ setPageFocusRequest: (request: DropdownPageFocusRequest | undefined) => void;
+ canGoBack: boolean;
+ initialFocusEdge: 'first' | 'last';
+ setInitialFocusEdge: (edge: 'first' | 'last') => void;
+ focusOnOpen: boolean;
+ setFocusOnOpen: (focusOnOpen: boolean) => void;
+ setOpen: (open: boolean) => void;
+ closeTree: () => void;
+ goToPage: (page: { id: string; trigger: DropdownFocusTarget }) => void;
+ goBack: () => void;
+ registerPage: (page: { id: string; type?: DropdownType }) => void;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownEmpty.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownEmpty.tsx
new file mode 100644
index 00000000000..1042b656297
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownEmpty.tsx
@@ -0,0 +1,18 @@
+import { clsx } from 'clsx';
+import { type ComponentPropsWithRef } from 'react';
+
+import { Text } from '@ui/primitives/typography/Text/Text';
+
+import styles from '../Dropdown.module.scss';
+
+export const DropdownEmpty = ({
+ className,
+ ...props
+}: ComponentPropsWithRef<'div'>) => (
+ <Text
+ {...props}
+ role="status"
+ aria-live="polite"
+ className={clsx(styles.status, className)}
+ />
+);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownFocusTarget.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownFocusTarget.ts
new file mode 100644
index 00000000000..5ed3baef92f
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownFocusTarget.ts
@@ -0,0 +1,6 @@
+export type DropdownFocusTarget = {
+ id?: string;
+ index: number;
+ page: string;
+ label: string;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownLoading.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownLoading.tsx
new file mode 100644
index 00000000000..3c523deae5c
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownLoading.tsx
@@ -0,0 +1,19 @@
+import { clsx } from 'clsx';
+import { type ComponentPropsWithRef } from 'react';
+
+import { Text } from '@ui/primitives/typography/Text/Text';
+
+import styles from '../Dropdown.module.scss';
+
+export const DropdownLoading = ({
+ className,
+ ...props
+}: ComponentPropsWithRef<'div'>) => (
+ <Text
+ {...props}
+ role="status"
+ aria-live="polite"
+ aria-busy="true"
+ className={clsx(styles.status, className)}
+ />
+);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownOptionItem.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownOptionItem.tsx
new file mode 100644
index 00000000000..88297a0a34a
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownOptionItem.tsx
@@ -0,0 +1,86 @@
+import { Button as ButtonPrimitive } from '@base-ui/react/button';
+import { useId } from 'react';
+
+import { ListItem } from '@ui/primitives/navigation/ListItem/ListItem';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type DropdownOptionItemProps } from '../types/DropdownOptionItemProps';
+import { useDropdownContext } from './useDropdownContext';
+import { useDropdownItemFocus } from './useDropdownItemFocus';
+
+export const DropdownOptionItem = ({
+ selected,
+ onSelect,
+ closeOnSelect,
+ color,
+ startIcon,
+ endIcon,
+ description,
+ descriptionPlacement,
+ hotkeys,
+ hasSubmenu,
+ children,
+ render,
+ disabled = false,
+ nativeButton = !isDefined(render),
+ onClick,
+ onFocus,
+ id,
+ ...props
+}: DropdownOptionItemProps) => {
+ const { type, multiple, closeTree } = useDropdownContext();
+ const isMenu = type === 'menu';
+ const menuOptionRole = multiple ? 'menuitemcheckbox' : 'menuitemradio';
+ const generatedId = useId();
+ const itemId = id ?? generatedId;
+ const itemFocus = useDropdownItemFocus({ id: itemId });
+
+ return (
+ <ButtonPrimitive
+ {...props}
+ id={itemId}
+ disabled={disabled}
+ nativeButton={nativeButton}
+ role={isMenu ? menuOptionRole : undefined}
+ aria-checked={isMenu ? selected : undefined}
+ aria-pressed={isMenu ? undefined : selected}
+ tabIndex={itemFocus.tabIndex}
+ onFocus={(event) => {
+ itemFocus.activate();
+ onFocus?.(event);
+ }}
+ data-dropdown-item=""
+ onClick={(event) => {
+ onClick?.(event);
+
+ if (event.defaultPrevented) {
+ return;
+ }
+
+ onSelect?.();
+
+ if (closeOnSelect ?? !multiple) {
+ closeTree();
+ }
+ }}
+ render={(renderProps) => (
+ <ListItem
+ {...renderProps}
+ render={render ?? <button type="button" />}
+ disabled={disabled}
+ selected={selected}
+ indicator={multiple ? 'checkbox' : 'check'}
+ color={color}
+ startIcon={startIcon}
+ endIcon={endIcon}
+ description={description}
+ descriptionPlacement={descriptionPlacement}
+ hotkeys={hotkeys}
+ hasSubmenu={hasSubmenu}
+ >
+ {children}
+ </ListItem>
+ )}
+ />
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPage.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPage.tsx
new file mode 100644
index 00000000000..43896979a62
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPage.tsx
@@ -0,0 +1,39 @@
+import { useCallback } from 'react';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import styles from '../Dropdown.module.scss';
+import { type DropdownPageProps } from '../types/DropdownPageProps';
+import { DropdownContext } from './DropdownContext';
+import { useDropdownContext } from './useDropdownContext';
+
+export const DropdownPage = ({ id, type, children }: DropdownPageProps) => {
+ const context = useDropdownContext();
+ const { registerPage } = context;
+ const registerPageType = useCallback(
+ (element: HTMLDivElement | null) => {
+ if (isDefined(element)) {
+ registerPage({ id, type });
+ }
+ },
+ [id, type, registerPage],
+ );
+
+ if (context.pageId !== id) {
+ return null;
+ }
+
+ return (
+ <DropdownContext.Provider
+ value={{ ...context, type: type ?? context.rootType }}
+ >
+ <div
+ ref={registerPageType}
+ className={styles.page}
+ data-dropdown-page-type={type ?? context.rootType}
+ >
+ {children}
+ </div>
+ </DropdownContext.Provider>
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPageFocusEffect.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPageFocusEffect.tsx
new file mode 100644
index 00000000000..84da7441f68
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPageFocusEffect.tsx
@@ -0,0 +1,40 @@
+import { type RefObject, useLayoutEffect } from 'react';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { getDropdownFocusTarget } from './getDropdownFocusTarget';
+import { useDropdownContext } from './useDropdownContext';
+
+type DropdownPageFocusEffectProps = {
+ contentRef: RefObject<HTMLDivElement | null>;
+};
+
+export const DropdownPageFocusEffect = ({
+ contentRef,
+}: DropdownPageFocusEffectProps) => {
+ const { open, pageId, pageFocusRequest, setPageFocusRequest } =
+ useDropdownContext();
+
+ useLayoutEffect(() => {
+ if (!isDefined(pageFocusRequest)) {
+ return;
+ }
+
+ setPageFocusRequest(undefined);
+
+ if (
+ !open ||
+ pageFocusRequest.pageId !== pageId ||
+ !isDefined(contentRef.current)
+ ) {
+ return;
+ }
+
+ getDropdownFocusTarget({
+ content: contentRef.current,
+ target: pageFocusRequest.target,
+ }).focus();
+ }, [contentRef, open, pageId, pageFocusRequest, setPageFocusRequest]);
+
+ return null;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPageFocusRequest.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPageFocusRequest.ts
new file mode 100644
index 00000000000..201014a8fe6
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownPageFocusRequest.ts
@@ -0,0 +1,6 @@
+import { type DropdownFocusTarget } from './DropdownFocusTarget';
+
+export type DropdownPageFocusRequest = {
+ pageId?: string;
+ target?: DropdownFocusTarget;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx
new file mode 100644
index 00000000000..4e9cfed3946
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx
@@ -0,0 +1,157 @@
+import { useCallback, useContext, useState } from 'react';
+
+import { Popover } from '@ui/primitives/surfaces/Popover/Popover';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type DropdownRootProps } from '../types/DropdownRootProps';
+import { type DropdownType } from '../types/DropdownType';
+import { DropdownContext } from './DropdownContext';
+import { type DropdownFocusTarget } from './DropdownFocusTarget';
+import { type DropdownPageFocusRequest } from './DropdownPageFocusRequest';
+
+type PageHistoryEntry = { id?: string; trigger?: DropdownFocusTarget };
+
+export const DropdownRoot = ({
+ children,
+ type,
+ open: controlledOpen,
+ defaultOpen = false,
+ onOpenChange,
+ multiple = false,
+ defaultPage = 'root',
+ isSubmenu = false,
+}: DropdownRootProps & { isSubmenu?: boolean }) => {
+ const parent = useContext(DropdownContext);
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
+ const open = controlledOpen ?? uncontrolledOpen;
+ const [previousOpen, setPreviousOpen] = useState(open);
+ const [pageHistory, setPageHistory] = useState<PageHistoryEntry[]>([
+ { id: defaultPage },
+ ]);
+ const [activePage, setActivePage] = useState<{
+ id: string;
+ type: DropdownType;
+ }>();
+ const [activeItemId, setActiveItemId] = useState<string>();
+ const pageId = pageHistory[pageHistory.length - 1]?.id;
+ const [pageFocusRequest, setPageFocusRequest] =
+ useState<DropdownPageFocusRequest>();
+ const [initialFocusEdge, setInitialFocusEdge] = useState<'first' | 'last'>(
+ 'first',
+ );
+ const [focusOnOpen, setFocusOnOpen] = useState(true);
+
+ if (previousOpen !== open) {
+ setPreviousOpen(open);
+
+ if (!open) {
+ setPageHistory([{ id: defaultPage }]);
+ setActivePage(undefined);
+ setPageFocusRequest(undefined);
+ setInitialFocusEdge('first');
+ setFocusOnOpen(true);
+ }
+ }
+
+ const setOpen = (nextOpen: boolean) => {
+ if (!isDefined(controlledOpen)) {
+ setUncontrolledOpen(nextOpen);
+ }
+
+ onOpenChange?.(nextOpen);
+ };
+
+ const closeTree = () => {
+ setOpen(false);
+
+ if (isSubmenu) {
+ parent?.closeTree();
+ }
+ };
+
+ const goToPage = ({
+ id,
+ trigger,
+ }: {
+ id: string;
+ trigger: DropdownFocusTarget;
+ }) => {
+ setPageFocusRequest({ pageId: id });
+ setPageHistory((history) => [...history, { id, trigger }]);
+ };
+
+ const goBack = () => {
+ if (pageHistory.length < 2) {
+ return;
+ }
+
+ const previousPage = pageHistory[pageHistory.length - 2];
+ const trigger = pageHistory[pageHistory.length - 1]?.trigger;
+
+ setPageFocusRequest({
+ pageId: previousPage.id,
+ target: trigger,
+ });
+ setPageHistory((history) => history.slice(0, -1));
+ };
+
+ const registerPage = useCallback(
+ ({ id, type: pageType }: { id: string; type?: DropdownType }) => {
+ if (!open) {
+ return;
+ }
+
+ const resolvedType = pageType ?? type;
+
+ setActivePage((previousPage) =>
+ previousPage?.id === id && previousPage.type === resolvedType
+ ? previousPage
+ : { id, type: resolvedType },
+ );
+ },
+ [open, type],
+ );
+
+ return (
+ <Popover.Root
+ open={open}
+ onOpenChange={(nextOpen, eventDetails) => {
+ setFocusOnOpen(eventDetails.reason !== 'trigger-hover');
+ setOpen(nextOpen);
+ }}
+ >
+ <DropdownContext.Provider
+ value={{
+ type:
+ isDefined(activePage) && activePage.id === pageId
+ ? activePage.type
+ : type,
+ rootType: type,
+ open,
+ multiple,
+ isSubmenu,
+ parentType: parent?.type,
+ activeItemId,
+ parentActiveItemId: parent?.activeItemId,
+ setActiveItemId,
+ setParentActiveItemId: parent?.setActiveItemId,
+ pageId,
+ pageFocusRequest,
+ setPageFocusRequest,
+ canGoBack: pageHistory.length > 1,
+ initialFocusEdge,
+ setInitialFocusEdge,
+ focusOnOpen,
+ setFocusOnOpen,
+ setOpen,
+ closeTree,
+ goToPage,
+ goBack,
+ registerPage,
+ }}
+ >
+ {children}
+ </DropdownContext.Provider>
+ </Popover.Root>
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearch.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearch.tsx
new file mode 100644
index 00000000000..ef14279b8f1
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearch.tsx
@@ -0,0 +1,22 @@
+import { Input } from '@ui/primitives/input/Input/Input';
+import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
+
+import styles from '../Dropdown.module.scss';
+import { type DropdownSearchProps } from '../types/DropdownSearchProps';
+
+export const DropdownSearch = ({
+ onValueChange,
+ className,
+ ...props
+}: DropdownSearchProps) => (
+ <div className={styles.searchContainer}>
+ <Input
+ type="search"
+ autoComplete="off"
+ {...props}
+ data-dropdown-search=""
+ className={mergeClassNames(styles.search, className)}
+ onValueChange={(value) => onValueChange?.(value)}
+ />
+ </div>
+);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSection.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSection.tsx
new file mode 100644
index 00000000000..13be6b03f40
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSection.tsx
@@ -0,0 +1,20 @@
+import { clsx } from 'clsx';
+
+import { MenuGroup } from '@ui/primitives/surfaces/Menu/internal/MenuGroup';
+import { MenuGroupLabel } from '@ui/primitives/surfaces/Menu/internal/MenuGroupLabel';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import styles from '../Dropdown.module.scss';
+import { type DropdownSectionProps } from '../types/DropdownSectionProps';
+
+export const DropdownSection = ({
+ label,
+ className,
+ children,
+ ...props
+}: DropdownSectionProps) => (
+ <MenuGroup {...props} className={clsx(styles.section, className)}>
+ {isDefined(label) && <MenuGroupLabel>{label}</MenuGroupLabel>}
+ {children}
+ </MenuGroup>
+);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSeparator.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSeparator.tsx
new file mode 100644
index 00000000000..430d903d0bd
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSeparator.tsx
@@ -0,0 +1,18 @@
+import { clsx } from 'clsx';
+import { type ComponentPropsWithRef } from 'react';
+
+import { MenuSeparator } from '@ui/primitives/surfaces/Menu/internal/MenuSeparator';
+
+import styles from '../Dropdown.module.scss';
+
+export const DropdownSeparator = ({
+ className,
+ ...props
+}: ComponentPropsWithRef<'div'>) => (
+ <MenuSeparator
+ {...props}
+ role="separator"
+ data-dropdown-separator=""
+ className={clsx(styles.separator, className)}
+ />
+);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenu.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenu.tsx
new file mode 100644
index 00000000000..946d6c5671e
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenu.tsx
@@ -0,0 +1,7 @@
+import { type DropdownSubmenuProps } from '../types/DropdownSubmenuProps';
+import { DropdownRoot } from './DropdownRoot';
+
+export const DropdownSubmenu = ({
+ type = 'menu',
+ ...props
+}: DropdownSubmenuProps) => <DropdownRoot {...props} type={type} isSubmenu />;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenuTrigger.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenuTrigger.tsx
new file mode 100644
index 00000000000..8083d525e97
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenuTrigger.tsx
@@ -0,0 +1,100 @@
+import { useId } from 'react';
+
+import { ListItem } from '@ui/primitives/navigation/ListItem/ListItem';
+import { Popover } from '@ui/primitives/surfaces/Popover/Popover';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type DropdownSubmenuTriggerProps } from '../types/DropdownSubmenuTriggerProps';
+import { getDropdownFocusTarget } from './getDropdownFocusTarget';
+import { useDropdownContext } from './useDropdownContext';
+import { useDropdownItemFocus } from './useDropdownItemFocus';
+
+export const DropdownSubmenuTrigger = ({
+ color,
+ startIcon,
+ endIcon,
+ description,
+ descriptionPlacement,
+ hotkeys,
+ hasSubmenu = true,
+ children,
+ render,
+ disabled = false,
+ nativeButton = !isDefined(render),
+ openOnHover = true,
+ onKeyDown,
+ onFocus,
+ id,
+ ...props
+}: DropdownSubmenuTriggerProps) => {
+ const { type, parentType, open, setOpen, setFocusOnOpen } =
+ useDropdownContext();
+ const generatedId = useId();
+ const itemId = id ?? generatedId;
+ const itemFocus = useDropdownItemFocus({
+ id: itemId,
+ isSubmenuTrigger: true,
+ });
+
+ return (
+ <Popover.Trigger
+ {...props}
+ id={itemId}
+ disabled={disabled}
+ nativeButton={nativeButton}
+ openOnHover={openOnHover}
+ role={parentType === 'menu' ? 'menuitem' : undefined}
+ aria-haspopup={type === 'menu' ? 'menu' : 'dialog'}
+ tabIndex={itemFocus.tabIndex}
+ onFocus={(event) => {
+ itemFocus.activate();
+ onFocus?.(event);
+ }}
+ data-dropdown-item=""
+ onKeyDown={(event) => {
+ onKeyDown?.(event);
+
+ if (event.defaultPrevented || disabled) {
+ return;
+ }
+
+ const isRightToLeft =
+ getComputedStyle(event.currentTarget).direction === 'rtl';
+ const forwardKey = isRightToLeft ? 'ArrowLeft' : 'ArrowRight';
+
+ if (event.key === forwardKey) {
+ event.preventDefault();
+ event.stopPropagation();
+ setFocusOnOpen(true);
+ const contentId = event.currentTarget.getAttribute('aria-controls');
+ const content = isDefined(contentId)
+ ? event.currentTarget.ownerDocument.getElementById(contentId)
+ : null;
+
+ if (open && isDefined(content)) {
+ getDropdownFocusTarget({ content, type }).focus();
+ return;
+ }
+
+ setOpen(true);
+ }
+ }}
+ render={(renderProps) => (
+ <ListItem
+ {...renderProps}
+ render={render ?? <button type="button" />}
+ disabled={disabled}
+ color={color}
+ startIcon={startIcon}
+ endIcon={endIcon}
+ description={description}
+ descriptionPlacement={descriptionPlacement}
+ hotkeys={hotkeys}
+ hasSubmenu={hasSubmenu}
+ >
+ {children}
+ </ListItem>
+ )}
+ />
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownTrigger.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownTrigger.tsx
new file mode 100644
index 00000000000..23102ec67a1
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownTrigger.tsx
@@ -0,0 +1,40 @@
+import { Popover } from '@ui/primitives/surfaces/Popover/Popover';
+
+import { type DropdownTriggerProps } from '../types/DropdownTriggerProps';
+import { useDropdownContext } from './useDropdownContext';
+
+export const DropdownTrigger = ({
+ onKeyDown,
+ onClick,
+ ...props
+}: DropdownTriggerProps) => {
+ const { type, setOpen, setInitialFocusEdge, setFocusOnOpen } =
+ useDropdownContext();
+
+ return (
+ <Popover.Trigger
+ {...props}
+ aria-haspopup={type === 'menu' ? 'menu' : 'dialog'}
+ onClick={(event) => {
+ event.stopPropagation();
+ onClick?.(event);
+ }}
+ onKeyDown={(event) => {
+ onKeyDown?.(event);
+
+ if (event.defaultPrevented || props.disabled || type === 'panel') {
+ return;
+ }
+
+ if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') {
+ return;
+ }
+
+ event.preventDefault();
+ setFocusOnOpen(true);
+ setInitialFocusEdge(event.key === 'ArrowUp' ? 'last' : 'first');
+ setOpen(true);
+ }}
+ />
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts
new file mode 100644
index 00000000000..9402e22a1bf
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts
@@ -0,0 +1,81 @@
+import { isNonEmptyString } from '@sniptt/guards';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type DropdownType } from '../types/DropdownType';
+import { type DropdownFocusTarget } from './DropdownFocusTarget';
+import { getDropdownItemLabel } from './getDropdownItemLabel';
+import { getDropdownItems } from './getDropdownItems';
+
+export const getDropdownFocusTarget = ({
+ content,
+ target,
+ edge = 'first',
+ type,
+}: {
+ content: HTMLElement;
+ target?: DropdownFocusTarget;
+ edge?: 'first' | 'last';
+ type?: DropdownType;
+}) => {
+ const previousTrigger = isDefined(target?.id)
+ ? content.ownerDocument.getElementById(target.id)
+ : null;
+
+ if (isDefined(previousTrigger) && content.contains(previousTrigger)) {
+ return previousTrigger;
+ }
+
+ const items = getDropdownItems(content);
+ const pageTriggers = isDefined(target)
+ ? items.filter((item) => item.dataset.dropdownPage === target.page)
+ : [];
+
+ if (pageTriggers.length === 1) {
+ return pageTriggers[0];
+ }
+
+ const matchingPageTriggers = isNonEmptyString(target?.label)
+ ? pageTriggers.filter(
+ (item) => getDropdownItemLabel(item) === target?.label,
+ )
+ : [];
+
+ if (matchingPageTriggers.length === 1) {
+ return matchingPageTriggers[0];
+ }
+
+ const pageTrigger = isDefined(target) ? items[target.index] : undefined;
+
+ if (isDefined(pageTrigger)) {
+ return pageTrigger;
+ }
+
+ const firstFormControl = content.querySelector<HTMLElement>(
+ 'input:not(:disabled):not([type="hidden"]),button:not(:disabled),textarea:not(:disabled),select:not(:disabled),a[href],[tabindex="0"]',
+ );
+
+ const activePage = Array.from(
+ content.querySelectorAll<HTMLElement>('[data-dropdown-page-type]'),
+ ).find((page) => page.closest('[data-dropdown-content]') === content);
+ const resolvedType =
+ activePage?.dataset.dropdownPageType ?? type ?? content.dataset.type;
+
+ if (resolvedType === 'panel') {
+ return firstFormControl ?? content;
+ }
+
+ const search = content.querySelector<HTMLInputElement>(
+ '[data-dropdown-search]:not(:disabled)',
+ );
+
+ if (isDefined(search)) {
+ return search;
+ }
+
+ return (
+ (edge === 'last' ? items[items.length - 1] : items[0]) ??
+ firstFormControl ??
+ content
+ );
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItemLabel.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItemLabel.ts
new file mode 100644
index 00000000000..5f41efca084
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItemLabel.ts
@@ -0,0 +1,2 @@
+export const getDropdownItemLabel = (item: HTMLElement) =>
+ item.getAttribute('aria-label') ?? item.textContent ?? '';
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItems.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItems.ts
new file mode 100644
index 00000000000..11e4d867746
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItems.ts
@@ -0,0 +1,9 @@
+export const getDropdownItems = (content: HTMLElement) =>
+ Array.from(
+ content.querySelectorAll<HTMLElement>('[data-dropdown-item]'),
+ ).filter(
+ (item) =>
+ item.getAttribute('aria-disabled') !== 'true' &&
+ !item.hasAttribute('disabled') &&
+ item.closest('[data-dropdown-content]') === content,
+ );
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownTrigger.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownTrigger.ts
new file mode 100644
index 00000000000..9fab61b6e5b
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownTrigger.ts
@@ -0,0 +1,6 @@
+export const getDropdownTrigger = (content: HTMLElement) =>
+ Array.from(
+ content.ownerDocument.querySelectorAll<HTMLElement>(
+ '[data-dropdown-item][aria-controls]',
+ ),
+ ).find((trigger) => trigger.getAttribute('aria-controls') === content.id);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getNextDropdownItem.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getNextDropdownItem.ts
new file mode 100644
index 00000000000..445153ffaa8
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getNextDropdownItem.ts
@@ -0,0 +1,39 @@
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+export const getNextDropdownItem = ({
+ key,
+ items,
+ currentIndex,
+ search,
+ isSearch,
+}: {
+ key: string;
+ items: HTMLElement[];
+ currentIndex: number;
+ search: HTMLInputElement | null;
+ isSearch: boolean;
+}): HTMLElement | undefined => {
+ const lastIndex = items.length - 1;
+
+ if (key === 'ArrowDown') {
+ return items[currentIndex === lastIndex ? 0 : currentIndex + 1];
+ }
+
+ if (key === 'ArrowUp' && currentIndex === 0 && isDefined(search)) {
+ return search;
+ }
+
+ if (key === 'ArrowUp') {
+ return items[currentIndex <= 0 ? lastIndex : currentIndex - 1];
+ }
+
+ if (!isSearch && key === 'Home') {
+ return items[0];
+ }
+
+ if (!isSearch && key === 'End') {
+ return items[lastIndex];
+ }
+
+ return undefined;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownContext.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownContext.ts
new file mode 100644
index 00000000000..b346b053bee
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownContext.ts
@@ -0,0 +1,15 @@
+import { useContext } from 'react';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { DropdownContext } from './DropdownContext';
+
+export const useDropdownContext = () => {
+ const context = useContext(DropdownContext);
+
+ if (!isDefined(context)) {
+ throw new Error('Dropdown components must be inside Dropdown.Root');
+ }
+
+ return context;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownItemFocus.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownItemFocus.ts
new file mode 100644
index 00000000000..526f0b97162
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownItemFocus.ts
@@ -0,0 +1,23 @@
+import { useDropdownContext } from './useDropdownContext';
+
+export const useDropdownItemFocus = ({
+ id,
+ isSubmenuTrigger = false,
+}: {
+ id: string;
+ isSubmenuTrigger?: boolean;
+}) => {
+ const context = useDropdownContext();
+ const type = isSubmenuTrigger ? context.parentType : context.type;
+ const activeItemId = isSubmenuTrigger
+ ? context.parentActiveItemId
+ : context.activeItemId;
+ const setActiveItemId = isSubmenuTrigger
+ ? context.setParentActiveItemId
+ : context.setActiveItemId;
+
+ return {
+ tabIndex: type === 'menu' && activeItemId !== id ? -1 : 0,
+ activate: () => setActiveItemId?.(id),
+ };
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts
new file mode 100644
index 00000000000..63ad5db44a7
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts
@@ -0,0 +1,121 @@
+import { useState, type KeyboardEvent } from 'react';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type DropdownType } from '../types/DropdownType';
+import { getDropdownItemLabel } from './getDropdownItemLabel';
+import { getDropdownItems } from './getDropdownItems';
+import { getDropdownTrigger } from './getDropdownTrigger';
+import { getNextDropdownItem } from './getNextDropdownItem';
+
+const TYPEAHEAD_RESET_DELAY = 500;
+
+export const useDropdownKeyboardNavigation = ({
+ type,
+ isSubmenu,
+ setOpen,
+}: {
+ type: DropdownType;
+ isSubmenu: boolean;
+ setOpen: (open: boolean) => void;
+}) => {
+ const [typeahead, setTypeahead] = useState({ text: '', timestamp: 0 });
+
+ return (event: KeyboardEvent<HTMLDivElement>) => {
+ if (event.defaultPrevented) {
+ return;
+ }
+
+ const content = event.currentTarget;
+ const target = event.target;
+
+ if (
+ !(target instanceof HTMLElement) ||
+ target.closest('[data-dropdown-content]') !== content
+ ) {
+ return;
+ }
+
+ const isEditable = target.matches(
+ 'input,textarea,select,[contenteditable="true"]',
+ );
+ const isRightToLeft = getComputedStyle(content).direction === 'rtl';
+ const backwardKey = isRightToLeft ? 'ArrowRight' : 'ArrowLeft';
+
+ const shouldCloseSubmenu =
+ isSubmenu &&
+ (event.key === 'Escape' || (!isEditable && event.key === backwardKey));
+
+ if (shouldCloseSubmenu) {
+ event.preventDefault();
+ event.stopPropagation();
+ getDropdownTrigger(content)?.focus();
+ setOpen(false);
+ return;
+ }
+
+ if (type === 'panel') {
+ return;
+ }
+
+ const search = content.querySelector<HTMLInputElement>(
+ '[data-dropdown-search]:not(:disabled)',
+ );
+ const isSearch = target === search;
+ if (isEditable && !isSearch) {
+ return;
+ }
+
+ const items = getDropdownItems(content).filter(
+ (item) => !isDefined(search) || !item.hasAttribute('data-dropdown-back'),
+ );
+ const currentIndex = items.indexOf(target);
+ const nextItem = getNextDropdownItem({
+ key: event.key,
+ items,
+ currentIndex,
+ search,
+ isSearch,
+ });
+
+ if (isDefined(nextItem)) {
+ event.preventDefault();
+ nextItem.focus();
+ return;
+ }
+
+ if (
+ isEditable ||
+ event.key.length !== 1 ||
+ event.key === ' ' ||
+ event.altKey ||
+ event.ctrlKey ||
+ event.metaKey
+ ) {
+ return;
+ }
+
+ const now = Date.now();
+ const text =
+ now - typeahead.timestamp > TYPEAHEAD_RESET_DELAY
+ ? event.key
+ : typeahead.text + event.key;
+ setTypeahead({ text, timestamp: now });
+ const isRepeatedCharacter = [...text].every(
+ (character) => character === text[0],
+ );
+ const query = (isRepeatedCharacter ? event.key : text).toLocaleLowerCase();
+ const orderedItems = [
+ ...items.slice(currentIndex + 1),
+ ...items.slice(0, currentIndex + 1),
+ ];
+ const match = orderedItems.find((item) =>
+ getDropdownItemLabel(item).trim().toLocaleLowerCase().startsWith(query),
+ );
+
+ if (isDefined(match)) {
+ event.preventDefault();
+ match.focus();
+ }
+ };
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownActionItemProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownActionItemProps.ts
new file mode 100644
index 00000000000..0831ff6cba4
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownActionItemProps.ts
@@ -0,0 +1,25 @@
+import { type Button as ButtonPrimitive } from '@base-ui/react/button';
+import { type ReactElement } from 'react';
+
+import { type ListItemProps } from '@ui/primitives/navigation/ListItem/types/ListItemProps';
+
+export type DropdownActionItemProps = Omit<
+ ButtonPrimitive.Props,
+ 'render' | 'className' | 'style'
+> &
+ Pick<
+ ListItemProps,
+ | 'color'
+ | 'startIcon'
+ | 'endIcon'
+ | 'description'
+ | 'descriptionPlacement'
+ | 'hotkeys'
+ | 'hasSubmenu'
+ > & {
+ render?: ReactElement;
+ className?: string;
+ style?: React.CSSProperties;
+ closeOnClick?: boolean;
+ page?: string;
+ };
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownContentProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownContentProps.ts
new file mode 100644
index 00000000000..b22cf7305af
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownContentProps.ts
@@ -0,0 +1,7 @@
+import { type CSSProperties } from 'react';
+
+import { type PopoverPopupProps } from '@ui/primitives/surfaces/Popover/types/PopoverPopupProps';
+
+export type DropdownContentProps = Omit<PopoverPopupProps, 'arrow'> & {
+ width?: CSSProperties['width'];
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownOptionItemProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownOptionItemProps.ts
new file mode 100644
index 00000000000..dc6985879ba
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownOptionItemProps.ts
@@ -0,0 +1,10 @@
+import { type DropdownActionItemProps } from './DropdownActionItemProps';
+
+export type DropdownOptionItemProps = Omit<
+ DropdownActionItemProps,
+ 'page' | 'closeOnClick' | 'onSelect'
+> & {
+ selected: boolean;
+ onSelect?: () => void;
+ closeOnSelect?: boolean;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownPageProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownPageProps.ts
new file mode 100644
index 00000000000..e799c23cc13
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownPageProps.ts
@@ -0,0 +1,9 @@
+import { type ReactNode } from 'react';
+
+import { type DropdownType } from './DropdownType';
+
+export type DropdownPageProps = {
+ id: string;
+ type?: DropdownType;
+ children: ReactNode;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownRootProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownRootProps.ts
new file mode 100644
index 00000000000..f11269f9efa
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownRootProps.ts
@@ -0,0 +1,13 @@
+import { type ReactNode } from 'react';
+
+import { type DropdownType } from './DropdownType';
+
+export type DropdownRootProps = {
+ children: ReactNode;
+ type: DropdownType;
+ open?: boolean;
+ defaultOpen?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ multiple?: boolean;
+ defaultPage?: string;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSearchProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSearchProps.ts
new file mode 100644
index 00000000000..ac6eaa9735f
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSearchProps.ts
@@ -0,0 +1,5 @@
+import { type InputProps } from '@ui/primitives/input/Input/types/InputProps';
+
+export type DropdownSearchProps = Omit<InputProps, 'onValueChange' | 'size'> & {
+ onValueChange?: (value: string) => void;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSectionProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSectionProps.ts
new file mode 100644
index 00000000000..c9707e2e492
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSectionProps.ts
@@ -0,0 +1,5 @@
+import { type ComponentPropsWithRef, type ReactNode } from 'react';
+
+export type DropdownSectionProps = ComponentPropsWithRef<'div'> & {
+ label?: ReactNode;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSubmenuProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSubmenuProps.ts
new file mode 100644
index 00000000000..329b163fcd9
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSubmenuProps.ts
@@ -0,0 +1,4 @@
+import { type DropdownRootProps } from './DropdownRootProps';
+
+export type DropdownSubmenuProps = Omit<DropdownRootProps, 'type'> &
+ Partial<Pick<DropdownRootProps, 'type'>>;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSubmenuTriggerProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSubmenuTriggerProps.ts
new file mode 100644
index 00000000000..cee86560a5c
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownSubmenuTriggerProps.ts
@@ -0,0 +1,10 @@
+import { type DropdownActionItemProps } from './DropdownActionItemProps';
+
+export type DropdownSubmenuTriggerProps = Omit<
+ DropdownActionItemProps,
+ 'page' | 'closeOnClick'
+> & {
+ openOnHover?: boolean;
+ delay?: number;
+ closeDelay?: number;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownTriggerProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownTriggerProps.ts
new file mode 100644
index 00000000000..3c00db661dd
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownTriggerProps.ts
@@ -0,0 +1,3 @@
+import { type Popover as PopoverPrimitive } from '@base-ui/react/popover';
+
+export type DropdownTriggerProps = PopoverPrimitive.Trigger.Props;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownType.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownType.ts
new file mode 100644
index 00000000000..e4a98459dd7
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownType.ts
@@ -0,0 +1 @@
+export type DropdownType = 'menu' | 'picker' | 'panel';