Skip to content

The open alternative to Salesforce, designed for AI.

Migrate phone country picker to Twenty UI (#27125)

Raphaël Bosi12d9ee48a05d
diff --git a/packages/twenty-docs/docs.json b/packages/twenty-docs/docs.json
index 1f5edde3212..e6d18690ff3 100644
--- a/packages/twenty-docs/docs.json
+++ b/packages/twenty-docs/docs.json
@@ -630,6 +630,7 @@
"ui/components/overflowing-list",
"ui/components/settings-row",
"ui/components/dropdown",
+ "ui/components/phone-country-picker",
"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 e72080e219a..be917f6106f 100644
--- a/packages/twenty-docs/navigation/base-structure.json
+++ b/packages/twenty-docs/navigation/base-structure.json
@@ -648,6 +648,7 @@
"ui/components/overflowing-list",
"ui/components/settings-row",
"ui/components/dropdown",
+ "ui/components/phone-country-picker",
"ui/components/tab-button",
"ui/components/code-editor",
"ui/components/toast",
diff --git a/packages/twenty-docs/snippets/ui/generated/components/dropdown.mdx b/packages/twenty-docs/snippets/ui/generated/components/dropdown.mdx
index b2343468cbc..44505a6bbb4 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/dropdown.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/dropdown.mdx
@@ -65,10 +65,6 @@
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).
@@ -84,10 +80,6 @@
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.
diff --git a/packages/twenty-docs/snippets/ui/generated/components/phone-country-picker.mdx b/packages/twenty-docs/snippets/ui/generated/components/phone-country-picker.mdx
new file mode 100644
index 00000000000..6e56dedda55
--- /dev/null
+++ b/packages/twenty-docs/snippets/ui/generated/components/phone-country-picker.mdx
@@ -0,0 +1,80 @@
+{/*
+ * _____ _
+ *|_ _|_ _____ _ __ | |_ _ _
+ * | | \ \ /\ / / _ \ '_ \| __| | | | 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
+ */}
+
+### PhoneCountryPicker.Trigger
+
+<ParamField body="Trigger.aria-label" type="string" required>
+ Required accessible name for the country selector button.
+</ParamField>
+
+<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.country" type="PhoneCountryOption">
+ Prepared country whose flag is displayed and whose label describes the trigger. Omit it to show a world icon.
+</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.disabled" type="boolean">
+ Disables the native trigger button.
+</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.openOnHover" type="boolean" default="false">
+ Whether the popover should also open when the trigger is hovered.
+</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>
+
+### PhoneCountryPicker.Options
+
+<ParamField body="Options.countries" type="readonly PhoneCountryOption[]" required>
+ Prepared choices with a unique value, localized label, calling code without a plus sign, and flag node. The supplied order is preserved after the matching selected country.
+</ParamField>
+
+<ParamField body="Options.emptyLabel" type="string" default="No results">
+ Status message shown when no country names match. Defaults to No results.
+</ParamField>
+
+<ParamField body="Options.onValueChange" type="(value: string) =&gt; void" required>
+ Called with the chosen country value. The host owns the selected country and phone number.
+</ParamField>
+
+<ParamField body="Options.searchLabel" type="string" default="Search">
+ Accessible name and placeholder of the country search field. Defaults to Search.
+</ParamField>
+
+<ParamField body="Options.value" type="string">
+ Selected country value. Its row appears first only while it matches the search.
+</ParamField>
diff --git a/packages/twenty-docs/ui/components/overview.mdx b/packages/twenty-docs/ui/components/overview.mdx
index 7119062f40e..d7e28e41a76 100644
--- a/packages/twenty-docs/ui/components/overview.mdx
+++ b/packages/twenty-docs/ui/components/overview.mdx
@@ -20,6 +20,7 @@ Import shared components from `twenty-ui/components`. The code editor has its ow
| [SettingsRow](/ui/components/settings-row) | Labeled switches for settings and filters. |
| [MetricRow](/ui/components/metric-row) | Labels and formatted values with optional determinate progress. |
| [Dropdown](/ui/components/dropdown) | Action menus, searchable pickers, and form panels. |
+| [PhoneCountryPicker](/ui/components/phone-country-picker) | Searchable country flags and calling-code selection. |
| [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-docs/ui/components/phone-country-picker.mdx b/packages/twenty-docs/ui/components/phone-country-picker.mdx
new file mode 100644
index 00000000000..8df25f51fab
--- /dev/null
+++ b/packages/twenty-docs/ui/components/phone-country-picker.mdx
@@ -0,0 +1,86 @@
+---
+title: PhoneCountryPicker
+description: Country flags, calling codes, search, and selection for phone inputs.
+---
+
+import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
+import PhoneCountryPickerReference from '/snippets/ui/generated/components/phone-country-picker.mdx';
+
+`PhoneCountryPicker` displays a country flag trigger and searchable calling-code choices. Compose its two parts inside [Dropdown](/ui/components/dropdown). Your application supplies country data, owns the selected value, and handles the phone number.
+
+<StoryEmbed
+ storyId="ui-input-phonecountrypicker--documentation"
+ title="Phone country selection"
+ height={400}
+/>
+
+## Prepared choices
+
+Each `PhoneCountryOption` has a unique `value`, a localized country `label`, a `callingCode` without the leading plus sign, and a `flag` node. Supply the country list in the order you want it displayed. The picker adds the plus sign to calling-code labels and keeps calling codes left to right next to right-to-left country names.
+
+```tsx
+import { useState } from 'react';
+import {
+ Dropdown,
+ PhoneCountryPicker,
+ type PhoneCountryOption,
+} from 'twenty-ui/components';
+
+const COUNTRIES: PhoneCountryOption[] = [
+ { value: 'FR', label: 'France', callingCode: '33', flag: '🇫🇷' },
+ { value: 'GB', label: 'United Kingdom', callingCode: '44', flag: '🇬🇧' },
+ { value: 'US', label: 'United States', callingCode: '1', flag: '🇺🇸' },
+];
+
+export const PhoneCountryExample = () => {
+ const [value, setValue] = useState('FR');
+
+ return (
+ <Dropdown.Root type="picker">
+ <PhoneCountryPicker.Trigger
+ aria-label="Phone country"
+ country={COUNTRIES.find((country) => country.value === value)}
+ />
+ <Dropdown.Content width={280}>
+ <PhoneCountryPicker.Options
+ countries={COUNTRIES}
+ value={value}
+ onValueChange={setValue}
+ searchLabel="Search countries"
+ emptyLabel="No countries found"
+ />
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
+```
+
+The picker ships without a country catalog, flag asset package, or phone-input runtime. Full phone-number parsing, validation, formatting, drafts, and submission belong to the host application.
+
+## Search and selection
+
+Search matches a substring of the country name, ignoring case and accents. It does not trim whitespace or match country values or calling codes. For example, `united` matches United Kingdom and United States, `reunion` matches Réunion, and `+44` does not match a calling code.
+
+The selected country appears first when it matches the query. Remaining matches retain their supplied order. A query that excludes the current selection also removes its row. Empty results show the supplied status message.
+
+The search field receives focus when the popup opens. Arrow keys and typed letters navigate options. Enter chooses the highlighted matching result after typing, or the focused option. Enter with an empty query does not select a country while focus remains in the search field. Pointer selection calls `onValueChange` with the country value. The dropdown closes after selection and returns focus according to its focus settings. Search clears when the popup content unmounts.
+
+## Trigger and host integration
+
+`Trigger` is a native button with a required accessible name. Its flag and chevron are decorative, and the selected country label becomes its accessible description. Pass the selected `country` to display its flag, or omit it for a world icon. Native attributes, event handlers, `disabled`, and the button ref reach the trigger.
+
+Keep `Dropdown.Root` and `Dropdown.Content` in the host when coordinating controlled open state, popup placement, an explicit return-focus target, or application editing lifecycle. The shared parts use the root's picker behavior. Use one root per selector to keep instances independent.
+
+A phone library adapter maps the library's country value, country-change callback, and disabled or read-only state onto this composition, and supplies its own translated trigger label. The adapter owns the library-specific country values and any subsequent focus on the phone input.
+
+## Labels
+
+Supply localized country labels in `countries` and an accessible name on `Trigger`. The popup takes the trigger name unless a `Dropdown.Title` or an explicit label on `Dropdown.Content` names it. `searchLabel` defaults to `Search` and names both the search field and its placeholder. `emptyLabel` defaults to `No results`.
+
+## Front component renderer
+
+In [front components](/developers/extend/apps/layout/front-components), the React and Preact renderers display the trigger, its flag, and its disabled state. Opening the popup is not supported yet: both renderers lack the native pointer data Dropdown reads, and in React the popup also fails while mounting because sandbox elements have no `dataset`, which stops the front component from rendering. These limitations do not affect normal React rendering.
+
+## Props
+
+<PhoneCountryPickerReference />
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 08d43e21189..f40a764c257 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx
@@ -1,4 +1,6 @@
+import { createPhoneCountryPickerSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createPhoneCountryPickerSandboxFailureTest';
import { currencyPickerSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/currencyPickerSandboxFailureTest';
+import { phoneCountryPickerTriggerTest } from '@/__stories__/twenty-ui-gallery/utils/phoneCountryPickerTriggerTest';
import { breadcrumbTest } from '@/__stories__/twenty-ui-gallery/utils/breadcrumbTest';
import { imageInputTest } from '@/__stories__/twenty-ui-gallery/utils/imageInputTest';
import { overflowingListEventIsolationFailureTest } from '@/__stories__/twenty-ui-gallery/utils/overflowingListEventIsolationFailureTest';
@@ -375,6 +377,32 @@ export const DropdownPreact: Story = createGalleryStory({
play: dropdownSandboxFailureTest,
});
+export const PhoneCountryPickerTriggersReact: Story = createGalleryStory({
+ frontComponentBundleName: 'twenty-ui-phone-country-picker',
+ runtime: 'react',
+ play: phoneCountryPickerTriggerTest,
+});
+
+export const PhoneCountryPickerTriggersPreact: Story = createGalleryStory({
+ frontComponentBundleName: 'twenty-ui-phone-country-picker',
+ runtime: 'preact',
+ play: phoneCountryPickerTriggerTest,
+});
+
+export const PhoneCountryPickerSandboxFailureReact: Story = createGalleryStory({
+ frontComponentBundleName: 'twenty-ui-phone-country-picker',
+ runtime: 'react',
+ play: createPhoneCountryPickerSandboxFailureTest('react'),
+});
+
+export const PhoneCountryPickerSandboxFailurePreact: Story = createGalleryStory(
+ {
+ frontComponentBundleName: 'twenty-ui-phone-country-picker',
+ runtime: 'preact',
+ play: createPhoneCountryPickerSandboxFailureTest('preact'),
+ },
+);
+
export const SelectReact: Story = createGalleryStory({
frontComponentBundleName: 'twenty-ui-select',
runtime: 'react',
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md
index 5db9f653bb0..a44f833f1a5 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md
@@ -22,6 +22,7 @@ requiring them to occur.
| `twenty-ui-list-item` | ListItem |
| `twenty-ui-tabs` | Tabs |
| `twenty-ui-overflowing-list` | OverflowingList |
+| `twenty-ui-phone-country-picker` | PhoneCountryPicker |
| `twenty-ui-popover` | Popover |
| `twenty-ui-menu` | Menu |
| `twenty-ui-select` | Select |
@@ -59,6 +60,7 @@ No stories are skipped or marked as expected-to-fail by the runner.
| Tabs | Activation fails on the missing `nativeEvent` for `composedPath` in both runtimes. |
| Popover, Dialog, AlertDialog | Opening fails while reading pointer contact data from the missing `nativeEvent`. |
| OverflowingList | Both runtimes measure, resize, and unmount the inline list, and keep rendering afterwards. A scoped light provider keeps popup portals inside the connected remote root and matches the gallery theme. Popup lifecycle checks verify selection, dismissal, focus restoration, and independent lists while requiring the missing native pointer width error; missing native `defaultPrevented` data and event constructor errors are optional. Focus restoration can also call a stale host listener, which is checked with the existing exact host-error assertion. Separate event isolation failure stories verify that opening the trigger activates the surrounding host, then check that popup selection adds no host activation. Full popup compatibility remains blocked on the event bridge work in [#26356](https://github.com/twentyhq/twenty/pull/26356). |
+| PhoneCountryPicker | Both runtimes render the triggers, flags, and disabled state. Opening fails while reading pointer contact data from the missing `nativeEvent`. In React the popup still mounts, and the Dropdown search effect then reads `dataset`, which sandbox elements lack; the uncaught error unmounts the React tree, so the React story requires that error and keeps the pointer error optional. See the [PhoneCountryPicker documentation](../../../../twenty-docs/ui/components/phone-country-picker.mdx). |
| Menu | Opening fails on the missing `nativeEvent.pointerType` and pointer contact data. |
| Select | Opening fails on missing native event data and focus support. Preact can report only the last of these failures when the host coalesces sandbox errors. |
| Switch, Checkbox, Radio (standard and card), SegmentedControl | Activation attempts to construct an unavailable `PointerEvent`. `RadioCardReact` never gets that far: React drops the click handler Base UI adds through `React.cloneElement`, so only the group's focus handling fails on the missing `nativeEvent` for `composedPath`. |
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.ts
index 0821fd968e0..3472bafa513 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.ts
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.ts
@@ -3,6 +3,8 @@ export const SANDBOX_ERROR_PATTERNS = {
"Uncaught TypeError: Cannot use 'in' operator to search for 'composedPath' in undefined",
VIEWPORT_WIDTH:
"Uncaught TypeError: Cannot read properties of undefined (reading 'width')",
+ ELEMENT_DATASET:
+ "Uncaught TypeError: Cannot read properties of undefined (reading 'type')",
NATIVE_EVENT_DEFAULT_PREVENTED:
"Uncaught TypeError: Cannot read properties of undefined (reading 'defaultPrevented')",
MISSING_EVENT_CONSTRUCTOR:
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-phone-country-picker.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-phone-country-picker.front-component.tsx
new file mode 100644
index 00000000000..13d780b2d1e
--- /dev/null
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-phone-country-picker.front-component.tsx
@@ -0,0 +1,68 @@
+import { useState } from 'react';
+import { defineFrontComponent } from 'twenty-sdk/define';
+import {
+ Dropdown,
+ PhoneCountryPicker,
+ type PhoneCountryOption,
+} from 'twenty-ui/components';
+import { Text } from 'twenty-ui/primitives/typography';
+
+import { TwentyUiGalleryCard } from '@/__stories__/shared/front-components/twenty-ui-gallery-card';
+
+const COUNTRIES: PhoneCountryOption[] = [
+ { value: 'FR', label: 'France', callingCode: '33', flag: '🇫🇷' },
+ { value: 'GB', label: 'United Kingdom', callingCode: '44', flag: '🇬🇧' },
+ { value: 'US', label: 'United States', callingCode: '1', flag: '🇺🇸' },
+];
+
+const PhoneCountrySelector = ({
+ label,
+ initialValue,
+ disabled = false,
+}: {
+ label: string;
+ initialValue?: string;
+ disabled?: boolean;
+}) => {
+ const [value, setValue] = useState(initialValue);
+
+ return (
+ <>
+ <Dropdown.Root type="picker">
+ <PhoneCountryPicker.Trigger
+ aria-label={label}
+ country={COUNTRIES.find((country) => country.value === value)}
+ disabled={disabled}
+ />
+ <Dropdown.Content aria-label={`Choose ${label}`} width={280}>
+ <PhoneCountryPicker.Options
+ countries={COUNTRIES}
+ value={value}
+ onValueChange={setValue}
+ searchLabel={`Search ${label}`}
+ emptyLabel="No countries found"
+ />
+ </Dropdown.Content>
+ </Dropdown.Root>
+ <Text role="status" aria-label={`${label} selection`}>
+ Country: {value ?? 'none'}
+ </Text>
+ </>
+ );
+};
+
+const PhoneCountryPickerExample = () => (
+ <TwentyUiGalleryCard title="PhoneCountryPicker">
+ <PhoneCountrySelector label="Primary phone country" initialValue="US" />
+ <PhoneCountrySelector label="Secondary phone country" initialValue="FR" />
+ <PhoneCountrySelector label="Disabled phone country" disabled />
+ </TwentyUiGalleryCard>
+);
+
+export default defineFrontComponent({
+ universalIdentifier: 'e87226d5-27b6-4876-979b-b9567e0b94f9',
+ name: 'twenty-ui-phone-country-picker',
+ description:
+ 'Country search, calling-code selection, and independent phone selectors',
+ component: PhoneCountryPickerExample,
+});
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createPhoneCountryPickerSandboxFailureTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createPhoneCountryPickerSandboxFailureTest.ts
new file mode 100644
index 00000000000..f8de3ecfcef
--- /dev/null
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createPhoneCountryPickerSandboxFailureTest.ts
@@ -0,0 +1,16 @@
+import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';
+import { createSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest';
+
+export const createPhoneCountryPickerSandboxFailureTest = (
+ runtime: 'react' | 'preact',
+) =>
+ createSandboxFailureTest({
+ trigger: { role: 'button', name: 'Primary phone country' },
+ requiredErrors: [
+ runtime === 'react'
+ ? SANDBOX_ERROR_PATTERNS.ELEMENT_DATASET
+ : SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH,
+ ],
+ allowedAdditionalErrors:
+ runtime === 'react' ? [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH] : [],
+ });
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/phoneCountryPickerTriggerTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/phoneCountryPickerTriggerTest.ts
new file mode 100644
index 00000000000..4b9dea5832e
--- /dev/null
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/phoneCountryPickerTriggerTest.ts
@@ -0,0 +1,40 @@
+import { expect, within } from 'storybook/test';
+
+import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';
+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';
+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';
+
+export const phoneCountryPickerTriggerTest: TwentyUiGalleryPlayFunction =
+ async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await expectFrontComponentMounted(canvas);
+
+ const primary = canvas.getByRole('button', {
+ name: 'Primary phone country',
+ });
+ const secondary = canvas.getByRole('button', {
+ name: 'Secondary phone country',
+ });
+ const disabled = canvas.getByRole('button', {
+ name: 'Disabled phone country',
+ });
+
+ expect(primary).toHaveAttribute('type', 'button');
+ expect(primary).toHaveTextContent('🇺🇸');
+ expect(primary).toHaveAccessibleDescription('United States');
+ expect(secondary).toHaveTextContent('🇫🇷');
+ expect(secondary).toHaveAccessibleDescription('France');
+ expect(disabled).toBeDisabled();
+ expect(disabled).not.toHaveAccessibleDescription();
+ expect(
+ canvas.getByRole('status', { name: 'Primary phone country selection' }),
+ ).toHaveTextContent('Country: US');
+ expect(
+ canvas.getByRole('status', { name: 'Secondary phone country selection' }),
+ ).toHaveTextContent('Country: FR');
+ expect(
+ canvas.getByRole('status', { name: 'Disabled phone country selection' }),
+ ).toHaveTextContent('Country: none');
+ expect(errorHandler).not.toHaveBeenCalled();
+ };
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/PhonesFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/PhonesFieldInput.stories.tsx
index 4cea4645896..08b6934b79d 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/PhonesFieldInput.stories.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/PhonesFieldInput.stories.tsx
@@ -1,6 +1,6 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { useEffect } from 'react';
-import { expect, userEvent, within } from 'storybook/test';
+import { expect, userEvent, waitFor, within } from 'storybook/test';
import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';
import { usePhonesField } from '@/object-record/record-field/ui/meta-types/hooks/usePhonesField';
@@ -161,6 +161,37 @@ export const TrimInput: Story = {
},
};
+export const CountryPickerReopensOnEnter: Story = {
+ args: {
+ value: {
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneNumber: '642646272',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: [],
+ },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(await canvas.findByText('Add Phone'));
+ const trigger = await canvas.findByRole('button', { name: 'Country' });
+
+ await userEvent.click(trigger);
+ await body.findByRole('dialog', { name: 'Country' });
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() => expect(body.queryByRole('dialog')).toBeNull());
+ await waitFor(() => expect(trigger).toHaveFocus());
+
+ await userEvent.keyboard('{Enter}');
+
+ const reopenedPopup = await body.findByRole('dialog', { name: 'Country' });
+ await waitFor(() => expect(reopenedPopup).toBeVisible());
+ expect(canvas.getByPlaceholderText('Phone')).toBeVisible();
+ await userEvent.keyboard('{Escape}');
+ },
+};
+
export const CanNotSetPrimaryLinkAsPrimaryLink: Story = {
args: {
value: {
diff --git a/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsx b/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsx
index e4ba6ffede4..3bb52c233a8 100644
--- a/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsx
+++ b/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsx
@@ -1,5 +1,4 @@
import { ConfigVariableDatabaseInput } from '@/settings/admin-panel/config-variables/components/ConfigVariableDatabaseInput';
-import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton';
import { DropdownMenuInnerSelect } from '@/ui/layout/dropdown/components/DropdownMenuInnerSelect';
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
@@ -7,13 +6,6 @@ import { expect, userEvent, waitFor, within } from 'storybook/test';
import { ComponentDecorator } from 'twenty-ui/testing';
import { ConfigVariableType } from '~/generated-admin/graphql';
-const PhoneExample = () => {
- const [country, setCountry] = useState('US');
- return (
- <PhoneCountryPickerDropdownButton value={country} onChange={setCountry} />
- );
-};
-
const ArrayExample = ({ disabled = false }: { disabled?: boolean }) => {
const [values, setValues] = useState<string[]>(['Alpha']);
return (
@@ -53,38 +45,6 @@ const meta: Meta = {
export default meta;
type Story = StoryObj;
-export const PhoneSearchAndSelection: Story = {
- render: () => <PhoneExample />,
- play: async ({ canvasElement }) => {
- const body = within(canvasElement.ownerDocument.body);
- const trigger = within(canvasElement).getByRole('button');
- await userEvent.click(trigger);
- expect(await body.findByRole('dialog', { name: 'Country' })).toBeVisible();
- await userEvent.type(
- await body.findByRole('searchbox', { name: 'Search' }),
- 'france',
- );
- const france = await body.findByRole('button', {
- name: /France \(\+33\)/,
- });
- expect(
- body.queryByRole('button', { pressed: true }),
- ).not.toBeInTheDocument();
- await waitFor(() => expect(france).toHaveAttribute('data-highlighted'));
- await userEvent.keyboard('{Enter}');
- await waitFor(() =>
- expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
- );
- await userEvent.click(trigger);
- expect(
- await body.findByRole('button', { name: /France \(\+33\)/ }),
- ).toHaveAttribute('aria-pressed', 'true');
- expect(body.getByRole('searchbox', { name: 'Search' })).toHaveValue('');
- await userEvent.keyboard('{Escape}');
- await waitFor(() => expect(trigger).toHaveFocus());
- },
-};
-
export const MultipleOptionsStayOpen: Story = {
render: () => <ArrayExample />,
play: async ({ canvasElement }) => {
diff --git a/packages/twenty-front/src/modules/ui/input/components/__stories__/PhoneCountryPicker.stories.tsx b/packages/twenty-front/src/modules/ui/input/components/__stories__/PhoneCountryPicker.stories.tsx
new file mode 100644
index 00000000000..8c955039864
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/input/components/__stories__/PhoneCountryPicker.stories.tsx
@@ -0,0 +1,235 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { type E164Number } from 'libphonenumber-js';
+import { useState } from 'react';
+import ReactPhoneNumberInput from 'react-phone-number-input';
+import 'react-phone-number-input/style.css';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
+import { Button } from 'twenty-ui/primitives/input';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton';
+
+const onCountryChange = fn();
+
+const LibraryPhoneInput = ({
+ label = 'Phone',
+ disabled = false,
+ readOnly = false,
+}: {
+ label?: string;
+ disabled?: boolean;
+ readOnly?: boolean;
+}) => {
+ const [value, setValue] = useState<E164Number>();
+
+ return (
+ <ReactPhoneNumberInput
+ aria-label={label}
+ value={value}
+ onChange={setValue}
+ onCountryChange={onCountryChange}
+ international
+ withCountryCallingCode
+ defaultCountry="US"
+ disabled={disabled}
+ readOnly={readOnly}
+ countrySelectComponent={PhoneCountryPickerDropdownButton}
+ />
+ );
+};
+
+const ControlledCountryPicker = () => {
+ const [value, setValue] = useState<string | undefined>('US');
+
+ return (
+ <>
+ <PhoneCountryPickerDropdownButton value={value} onChange={setValue} />
+ <Button onClick={() => setValue(undefined)}>Clear country</Button>
+ </>
+ );
+};
+
+const meta: Meta = {
+ title: 'UI/Input/PhoneCountryPicker',
+ decorators: [ComponentDecorator],
+ beforeEach: () => {
+ onCountryChange.mockClear();
+ },
+};
+
+export default meta;
+type Story = StoryObj;
+
+export const PhoneLibrarySelectionAndFocus: Story = {
+ render: () => <LibraryPhoneInput />,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const trigger = canvas.getByRole('button', { name: 'Country' });
+ const phoneInput = canvas.getByRole('textbox', { name: 'Phone' });
+
+ await userEvent.tab();
+ expect(trigger).toHaveFocus();
+ expect(trigger).toHaveAccessibleDescription('United States');
+ await userEvent.keyboard('{Enter}');
+
+ const popup = await body.findByRole('dialog', { name: 'Country' });
+ const search = within(popup).getByRole('searchbox', { name: 'Search' });
+ await waitFor(() => expect(search).toHaveFocus());
+ expect(within(popup).getAllByRole('button')[0]).toHaveAccessibleName(
+ 'United States (+1)',
+ );
+ await userEvent.type(search, 'france');
+ const france = await within(popup).findByRole('button', {
+ name: 'France (+33)',
+ });
+ expect(within(popup).queryByRole('button', { pressed: true })).toBeNull();
+ await waitFor(() => expect(france).toHaveAttribute('data-highlighted'));
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() => expect(popup).not.toBeInTheDocument());
+ expect(onCountryChange).toHaveBeenLastCalledWith('FR');
+ await waitFor(() => expect(phoneInput).toHaveFocus());
+ expect(trigger).toHaveAccessibleDescription('France');
+
+ await userEvent.click(trigger);
+ const reopenedPopup = await body.findByRole('dialog', { name: 'Country' });
+ const reopenedSearch = within(reopenedPopup).getByRole('searchbox', {
+ name: 'Search',
+ });
+ expect(reopenedSearch).toHaveValue('');
+ expect(
+ within(reopenedPopup).getByRole('button', { name: 'France (+33)' }),
+ ).toHaveAttribute('aria-pressed', 'true');
+ await userEvent.type(reopenedSearch, 'germany');
+ await userEvent.click(
+ await within(reopenedPopup).findByRole('button', {
+ name: 'Germany (+49)',
+ }),
+ );
+ await waitFor(() => expect(reopenedPopup).not.toBeInTheDocument());
+ expect(onCountryChange).toHaveBeenLastCalledWith('DE');
+ await waitFor(() => expect(phoneInput).toHaveFocus());
+
+ await userEvent.click(trigger);
+ await body.findByRole('dialog', { name: 'Country' });
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() => expect(body.queryByRole('dialog')).toBeNull());
+ await waitFor(() => expect(trigger).toHaveFocus());
+ },
+};
+
+export const IndependentPhoneInputs: Story = {
+ render: () => (
+ <>
+ <LibraryPhoneInput label="Work phone" />
+ <LibraryPhoneInput label="Personal phone" />
+ </>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const [workTrigger, personalTrigger] = canvas.getAllByRole('button', {
+ name: 'Country',
+ });
+
+ await userEvent.click(workTrigger);
+ const workPopup = await body.findByRole('dialog', { name: 'Country' });
+ expect(body.getAllByRole('dialog')).toHaveLength(1);
+ expect(personalTrigger).toHaveAttribute('aria-expanded', 'false');
+ await userEvent.type(
+ within(workPopup).getByRole('searchbox', { name: 'Search' }),
+ 'france',
+ );
+ await userEvent.click(
+ await within(workPopup).findByRole('button', { name: 'France (+33)' }),
+ );
+ await waitFor(() => expect(workPopup).not.toBeInTheDocument());
+ await waitFor(() =>
+ expect(canvas.getByRole('textbox', { name: 'Work phone' })).toHaveFocus(),
+ );
+ expect(workTrigger).toHaveAccessibleDescription('France');
+ expect(personalTrigger).toHaveAccessibleDescription('United States');
+
+ await userEvent.click(personalTrigger);
+ const personalPopup = await body.findByRole('dialog', { name: 'Country' });
+ expect(body.getAllByRole('dialog')).toHaveLength(1);
+ expect(workTrigger).toHaveAttribute('aria-expanded', 'false');
+ expect(
+ within(personalPopup).getByRole('searchbox', { name: 'Search' }),
+ ).toHaveValue('');
+ expect(
+ within(personalPopup).getByRole('button', {
+ name: 'United States (+1)',
+ }),
+ ).toHaveAttribute('aria-pressed', 'true');
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() => expect(personalTrigger).toHaveFocus());
+ },
+};
+
+export const DisabledAndReadOnlyPhoneInputs: Story = {
+ render: () => (
+ <>
+ <LibraryPhoneInput label="Disabled phone" disabled />
+ <LibraryPhoneInput label="Read-only phone" readOnly />
+ </>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const [disabledTrigger, readOnlyTrigger] = canvas.getAllByRole('button', {
+ name: 'Country',
+ });
+
+ expect(disabledTrigger).toBeDisabled();
+ expect(readOnlyTrigger).toBeDisabled();
+ expect(
+ canvas.getByRole('textbox', { name: 'Disabled phone' }),
+ ).toBeDisabled();
+ expect(
+ canvas.getByRole('textbox', { name: 'Read-only phone' }),
+ ).toHaveAttribute('readonly');
+ await userEvent.click(disabledTrigger);
+ await userEvent.click(readOnlyTrigger);
+ expect(body.queryByRole('dialog')).toBeNull();
+ },
+};
+
+export const ClearedCountryRemovesSelection: Story = {
+ render: () => <ControlledCountryPicker />,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const trigger = canvas.getByRole('button', { name: 'Country' });
+
+ expect(trigger).toHaveAccessibleDescription('United States');
+ await userEvent.click(trigger);
+ const popup = await body.findByRole('dialog', { name: 'Country' });
+ expect(
+ within(popup).getByRole('button', { name: 'United States (+1)' }),
+ ).toHaveAttribute('aria-pressed', 'true');
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() => expect(popup).not.toBeInTheDocument());
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Clear country' }),
+ );
+ expect(trigger).not.toHaveAccessibleDescription();
+ await userEvent.click(trigger);
+ const clearedPopup = await body.findByRole('dialog', { name: 'Country' });
+ expect(
+ within(clearedPopup).queryByRole('button', { pressed: true }),
+ ).toBeNull();
+ await userEvent.type(
+ within(clearedPopup).getByRole('searchbox', { name: 'Search' }),
+ 'france',
+ );
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() => expect(clearedPopup).not.toBeInTheDocument());
+ expect(trigger).toHaveAccessibleDescription('France');
+ await userEvent.click(trigger);
+ expect(
+ await body.findByRole('button', { name: 'France (+33)', pressed: true }),
+ ).toBeVisible();
+ await userEvent.keyboard('{Escape}');
+ },
+};
diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton.tsx b/packages/twenty-front/src/modules/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton.tsx
index 6eaa8e2fd51..55f7fea7da8 100644
--- a/packages/twenty-front/src/modules/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton.tsx
+++ b/packages/twenty-front/src/modules/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton.tsx
@@ -1,124 +1,70 @@
-import { useCountries } from '@/ui/input/components/internal/hooks/useCountries';
-import { type Country } from '@/ui/input/components/internal/types/Country';
-import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
-import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
-import { useEffect, useState } from 'react';
-import { Dropdown } from 'twenty-ui/components';
+import { type KeyboardEvent, useId, useMemo } from 'react';
+import { PhoneCountryPicker } from 'twenty-ui/components';
-import { PhoneCountryPickerDropdownSelect } from './PhoneCountryPickerDropdownSelect';
-
-import { PHONE_COUNTRY_CODE_PICKER_DROPDOWN_ID } from '@/ui/input/components/internal/phone/constants/PhoneCountryCodePickerDropdownId';
-import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
-import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
-import 'react-phone-number-input/style.css';
-import { isDefined } from 'twenty-shared/utils';
-import { IconChevronDown, IconWorld } from 'twenty-ui/icon';
-import { useTheme, themeCssVariables } from 'twenty-ui/theme';
+import { useCountries } from '@/ui/input/components/internal/hooks/useCountries';
+import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
-type StyledDropdownButtonProps = {
- isUnfolded: boolean;
+type PhoneCountryPickerDropdownButtonProps = {
+ value?: string;
+ onChange: (countryCode: string) => void;
+ disabled?: boolean;
+ readOnly?: boolean;
};
-const StyledDropdownButtonContainer = styled.div<StyledDropdownButtonProps>`
- align-items: center;
- background: none;
- border-radius: ${themeCssVariables.border.radius.xs} 0 0
- ${themeCssVariables.border.radius.xs};
- border-right: 1px solid ${themeCssVariables.border.color.medium};
- color: ${({ color }) => color ?? 'none'};
- cursor: pointer;
-
- display: flex;
-
- height: 32px;
- padding-left: ${themeCssVariables.spacing[2]};
- padding-right: ${themeCssVariables.spacing[1]};
-
- user-select: none;
-
- &:hover {
- background-color: ${themeCssVariables.background.transparent.light};
+const keepEnterAwayFromFieldHotkeys = (
+ event: KeyboardEvent<HTMLButtonElement>,
+) => {
+ if (event.key !== 'Enter') {
+ return;
}
-`;
-const StyledIconContainer = styled.div`
- align-items: center;
- color: ${themeCssVariables.font.color.tertiary};
- display: flex;
- gap: ${themeCssVariables.spacing[0.5]};
- justify-content: center;
-
- svg {
- align-items: center;
- display: flex;
- height: 12px;
- justify-content: center;
- width: 16px;
- }
-`;
-
-const StyledCheveronIconContainer = styled.div`
- svg {
- align-items: center;
- display: flex;
- height: 14px;
- justify-content: center;
- width: 14px;
- }
-`;
+ event.stopPropagation();
+};
export const PhoneCountryPickerDropdownButton = ({
value,
onChange,
-}: {
- value: string;
- onChange: (countryCode: string) => void;
-}) => {
- const [selectedCountry, setSelectedCountry] = useState<Country>();
-
- const isDropdownOpen = useAtomComponentStateValue(
- isDropdownOpenComponentState,
- PHONE_COUNTRY_CODE_PICKER_DROPDOWN_ID,
+ disabled,
+ readOnly,
+}: PhoneCountryPickerDropdownButtonProps) => {
+ const dropdownId = useId();
+ const availableCountries = useCountries();
+ const countries = useMemo(
+ () =>
+ availableCountries.map(
+ ({ countryCode, countryName, callingCode, Flag }) => ({
+ value: countryCode,
+ label: countryName,
+ callingCode,
+ flag: <Flag />,
+ }),
+ ),
+ [availableCountries],
);
-
- const countries = useCountries();
- const theme = useTheme();
-
- useEffect(() => {
- const country = countries.find(({ countryCode }) => countryCode === value);
- if (isDefined(country)) {
- setSelectedCountry(country);
- }
- }, [countries, value]);
+ const selectedCountry = countries.find((country) => country.value === value);
return (
- <DropdownRoot
- dropdownId={PHONE_COUNTRY_CODE_PICKER_DROPDOWN_ID}
- type="picker"
- >
- <Dropdown.Trigger render={<div />} nativeButton={false}>
- <StyledDropdownButtonContainer isUnfolded={isDropdownOpen}>
- <StyledIconContainer>
- {selectedCountry ? <selectedCountry.Flag /> : <IconWorld />}
- <StyledCheveronIconContainer>
- <IconChevronDown size={theme.icon.size.sm} />
- </StyledCheveronIconContainer>
- </StyledIconContainer>
- </StyledDropdownButtonContainer>
- </Dropdown.Trigger>
+ <DropdownRoot dropdownId={dropdownId} type="picker">
+ <PhoneCountryPicker.Trigger
+ country={selectedCountry}
+ disabled={disabled || readOnly}
+ aria-label={t`Country`}
+ onKeyDown={keepEnterAwayFromFieldHotkeys}
+ />
<DropdownContent
side="bottom"
align="start"
sideOffset={4}
alignOffset={0}
- aria-label={t`Country`}
>
- <PhoneCountryPickerDropdownSelect
+ <PhoneCountryPicker.Options
countries={countries}
- selectedCountry={selectedCountry}
- onChange={onChange}
+ value={value}
+ onValueChange={onChange}
+ searchLabel={t`Search`}
+ emptyLabel={t`No results`}
/>
</DropdownContent>
</DropdownRoot>
diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownSelect.tsx b/packages/twenty-front/src/modules/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownSelect.tsx
deleted file mode 100644
index ac741b86d87..00000000000
--- a/packages/twenty-front/src/modules/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownSelect.tsx
+++ /dev/null
@@ -1,107 +0,0 @@
-import { type Country } from '@/ui/input/components/internal/types/Country';
-import { styled } from '@linaria/react';
-import { t } from '@lingui/core/macro';
-import { useMemo, useState } from 'react';
-import 'react-phone-number-input/style.css';
-import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
-import { Dropdown } from 'twenty-ui/components';
-import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
-import { themeCssVariables } from 'twenty-ui/theme';
-
-const StyledIconContainer = styled.div`
- align-items: center;
- color: ${themeCssVariables.font.color.tertiary};
- display: flex;
- padding-right: ${themeCssVariables.spacing[1]};
-
- svg {
- align-items: center;
- border-radius: ${themeCssVariables.border.radius.xs};
- display: flex;
- height: 12px;
- justify-content: center;
- }
-`;
-
-export const PhoneCountryPickerDropdownSelect = ({
- countries,
- selectedCountry,
- onChange,
-}: {
- countries: Country[];
- selectedCountry?: Country;
- onChange: (countryCode: string) => void;
-}) => {
- const [searchFilter, setSearchFilter] = useState<string>('');
-
- const filteredCountries = useMemo(
- () =>
- countries.filter(({ countryName }) =>
- countryName
- .toLocaleLowerCase()
- .includes(searchFilter.toLocaleLowerCase()),
- ),
- [countries, searchFilter],
- );
-
- const isSelectedCountryMatchingSearch =
- isDefined(selectedCountry) &&
- filteredCountries.some(
- ({ countryCode }) => countryCode === selectedCountry.countryCode,
- );
-
- return (
- <>
- <Dropdown.Search
- value={searchFilter}
- placeholder={t`Search`}
- aria-label={t`Search`}
- onValueChange={setSearchFilter}
- />
- <Dropdown.Separator />
- <Dropdown.Section scrollable>
- {!isNonEmptyArray(filteredCountries) ? (
- <Dropdown.Empty>{t`No results`}</Dropdown.Empty>
- ) : (
- <>
- {isSelectedCountryMatchingSearch && (
- <Dropdown.OptionItem
- key={selectedCountry.countryCode}
- onSelect={() => onChange(selectedCountry.countryCode)}
- selected={true}
- startIcon={
- <StyledIconContainer>
- <selectedCountry.Flag />
- </StyledIconContainer>
- }
- >
- <OverflowingTextWithTooltip
- text={`${selectedCountry.countryName} (+${selectedCountry.callingCode})`}
- />
- </Dropdown.OptionItem>
- )}
- {filteredCountries.map(
- ({ countryCode, countryName, callingCode, Flag }) =>
- selectedCountry?.countryCode === countryCode ? null : (
- <Dropdown.OptionItem
- key={countryCode}
- onSelect={() => onChange(countryCode)}
- selected={selectedCountry?.countryCode === countryCode}
- startIcon={
- <StyledIconContainer>
- <Flag />
- </StyledIconContainer>
- }
- >
- <OverflowingTextWithTooltip
- text={`${countryName} (+${callingCode})`}
- />
- </Dropdown.OptionItem>
- ),
- )}
- </>
- )}
- </Dropdown.Section>
- </>
- );
-};
diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/phone/constants/PhoneCountryCodePickerDropdownId.ts b/packages/twenty-front/src/modules/ui/input/components/internal/phone/constants/PhoneCountryCodePickerDropdownId.ts
deleted file mode 100644
index 0d24f89a1f3..00000000000
--- a/packages/twenty-front/src/modules/ui/input/components/internal/phone/constants/PhoneCountryCodePickerDropdownId.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export const PHONE_COUNTRY_CODE_PICKER_DROPDOWN_ID =
- 'phone-country-picker-dropdown-id';
diff --git a/packages/twenty-shared/src/constants/DocumentationPaths.ts b/packages/twenty-shared/src/constants/DocumentationPaths.ts
index ce97e0ab5e2..820c30b391a 100644
--- a/packages/twenty-shared/src/constants/DocumentationPaths.ts
+++ b/packages/twenty-shared/src/constants/DocumentationPaths.ts
@@ -150,6 +150,7 @@ export const DOCUMENTATION_PATHS = {
UI_COMPONENTS_NOTIFICATION_COUNTER: '/ui/components/notification-counter',
UI_COMPONENTS_OVERFLOWING_LIST: '/ui/components/overflowing-list',
UI_COMPONENTS_OVERVIEW: '/ui/components/overview',
+ UI_COMPONENTS_PHONE_COUNTRY_PICKER: '/ui/components/phone-country-picker',
UI_COMPONENTS_SEARCH_INPUT: '/ui/components/search-input',
UI_COMPONENTS_SECTION: '/ui/components/section',
UI_COMPONENTS_SETTINGS_ROW: '/ui/components/settings-row',
diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.ts
index 79f83214069..384193b5347 100644
--- a/packages/twenty-ui/docs/components.ts
+++ b/packages/twenty-ui/docs/components.ts
@@ -12,6 +12,7 @@ import { INLINE_BANNER_PROP_DESCRIPTIONS } from './inlineBannerPropDescriptions'
import { TOAST_PROVIDER_PROP_DESCRIPTIONS } from './toastProviderPropDescriptions';
import { TOASTER_PROP_DESCRIPTIONS } from './toasterPropDescriptions';
import { RADIO_PROP_DESCRIPTIONS } from './radioPropDescriptions';
+import { PHONE_COUNTRY_PICKER_PART_PROP_DESCRIPTIONS } from './phoneCountryPickerPartPropDescriptions';
import { SEARCH_INPUT_PROP_DESCRIPTIONS } from './searchInputPropDescriptions';
import { NUMBER_STEPPER_PROP_DESCRIPTIONS } from './numberStepperPropDescriptions';
import { IMAGE_INPUT_PROP_DESCRIPTIONS } from './imageInputPropDescriptions';
@@ -462,6 +463,14 @@ export const DOCUMENTED_COMPONENTS = [
slug: 'components/settings-row',
propDescriptions: SETTINGS_ROW_PROP_DESCRIPTIONS,
},
+ {
+ name: 'PhoneCountryPicker',
+ source: 'components/input/PhoneCountryPicker/PhoneCountryPicker.tsx',
+ entryPoint: 'twenty-ui/components',
+ slug: 'components/phone-country-picker',
+ parts: ['Trigger', 'Options'],
+ partPropDescriptions: PHONE_COUNTRY_PICKER_PART_PROP_DESCRIPTIONS,
+ },
{
name: 'Dropdown',
source: 'components/navigation/Dropdown/Dropdown.tsx',
diff --git a/packages/twenty-ui/docs/label-ownership.md b/packages/twenty-ui/docs/label-ownership.md
index 0f8616d5551..f81abe31fca 100644
--- a/packages/twenty-ui/docs/label-ownership.md
+++ b/packages/twenty-ui/docs/label-ownership.md
@@ -12,6 +12,7 @@ This covers production exports under components, primitives, and icons, includin
| Button, MainButton, LightButton | Children and native accessible attributes. Applications compose upcoming-feature labels with Pill. Loading preserves the supplied name and marks the button busy; its spinner is decorative. Button hints use the shared Shortcut presentation and remain decorative. `shortcutJoinLabel` supplies the sequence join label. |
| IconButton and LightIconButton | Caller-supplied accessible label and optional tooltip. Native `aria-labelledby` remains available and takes precedence. |
| SearchInput | Caller-owned placeholder and native accessible name; `filterButtonAriaLabel` defaults to `Filter`. Referenced labels take precedence over explicit labels and placeholder fallback. |
+| PhoneCountryPicker | Callers supply country labels and the trigger accessible name. The popup takes the trigger name unless a `Dropdown.Title` or an explicit `Dropdown.Content` label names it, and the selected country label describes the trigger. `searchLabel` defaults to `Search`; `emptyLabel` defaults to `No results`. Calling codes are supplied as data without a leading plus sign. |
| ImageInput | `uploadLabel`, `removeLabel`, and `abortLabel` default to `Upload`, `Remove`, and `Abort`. The upload label names the visible upload button and the preview button. Applications supply `helperText` and `errorMessage`, including validation instructions and translated strings. |
| Toast and Toaster | Children, description and action slots, `iconLabel`, `cancelLabel` (default `Cancel`), and `closeLabel` (default `Close`). Toaster accepts native accessible attributes over its `Notifications` region default. |
| Chip and Avatar | Chip `emptyLabel` defaults to `Untitled`. Avatar accepts native accessible names over its interactive fallback of the supplied name or `Avatar`. The visual initial or dash is hidden from assistive technology; the image has empty alternative text. |
diff --git a/packages/twenty-ui/docs/module-ownership.json b/packages/twenty-ui/docs/module-ownership.json
index e515274ae60..8c27b096e04 100644
--- a/packages/twenty-ui/docs/module-ownership.json
+++ b/packages/twenty-ui/docs/module-ownership.json
@@ -67,6 +67,7 @@
"MetricRow",
"NotificationCounter",
"OverflowingList",
+ "PhoneCountryPicker",
"SearchInput",
"Section",
"SettingsRow",
diff --git a/packages/twenty-ui/docs/phoneCountryPickerPartPropDescriptions.ts b/packages/twenty-ui/docs/phoneCountryPickerPartPropDescriptions.ts
new file mode 100644
index 00000000000..1fea162674e
--- /dev/null
+++ b/packages/twenty-ui/docs/phoneCountryPickerPartPropDescriptions.ts
@@ -0,0 +1,28 @@
+import { type ComponentProps } from 'react';
+
+import { type PhoneCountryPicker } from '../src/components/input/PhoneCountryPicker/PhoneCountryPicker';
+
+export const PHONE_COUNTRY_PICKER_PART_PROP_DESCRIPTIONS = {
+ Trigger: {
+ country:
+ 'Prepared country whose flag is displayed and whose label describes the trigger. Omit it to show a world icon.',
+ 'aria-label': 'Required accessible name for the country selector button.',
+ disabled: 'Disables the native trigger button.',
+ } satisfies Partial<
+ Record<keyof ComponentProps<typeof PhoneCountryPicker.Trigger>, string>
+ >,
+ Options: {
+ countries:
+ 'Prepared choices with a unique value, localized label, calling code without a plus sign, and flag node. The supplied order is preserved after the matching selected country.',
+ value:
+ 'Selected country value. Its row appears first only while it matches the search.',
+ onValueChange:
+ 'Called with the chosen country value. The host owns the selected country and phone number.',
+ searchLabel:
+ 'Accessible name and placeholder of the country search field. Defaults to Search.',
+ emptyLabel:
+ 'Status message shown when no country names match. Defaults to No results.',
+ } satisfies Partial<
+ Record<keyof ComponentProps<typeof PhoneCountryPicker.Options>, string>
+ >,
+};
diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.json
index 70ec26197b0..6b97c612d1c 100644
--- a/packages/twenty-ui/docs/public-exports.json
+++ b/packages/twenty-ui/docs/public-exports.json
@@ -35,6 +35,7 @@
"MetricRow": "components/data-display/MetricRow/MetricRow",
"NotificationCounter": "components/data-display/NotificationCounter/NotificationCounter",
"OverflowingList": "components/layout/OverflowingList/OverflowingList",
+ "PhoneCountryPicker": "components/input/PhoneCountryPicker/PhoneCountryPicker",
"SearchInput": "components/input/SearchInput/SearchInput",
"Section": "components/layout/Section/Section",
"SettingsRow": "components/input/SettingsRow/SettingsRow",
@@ -90,6 +91,9 @@
"MenuPickerProps": "components/navigation/MenuPicker/types/MenuPickerProps",
"MetricRowProps": "components/data-display/MetricRow/types/MetricRowProps",
"OverflowingListProps": "components/layout/OverflowingList/types/OverflowingListProps",
+ "PhoneCountryOption": "components/input/PhoneCountryPicker/types/PhoneCountryOption",
+ "PhoneCountryPickerOptionsProps": "components/input/PhoneCountryPicker/types/PhoneCountryPickerOptionsProps",
+ "PhoneCountryPickerTriggerProps": "components/input/PhoneCountryPicker/types/PhoneCountryPickerTriggerProps",
"SearchInputProps": "components/input/SearchInput/types/SearchInputProps",
"SectionHeaderProps": "components/layout/Section/types/SectionHeaderProps",
"SectionRootProps": "components/layout/Section/types/SectionRootProps",
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 433ee1e0c7a..cf1c5fde16b 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -7238,6 +7238,122 @@
}
]
},
+ {
+ "name": "PhoneCountryPicker",
+ "entryPoint": "twenty-ui/components",
+ "slug": "components/phone-country-picker",
+ "props": [],
+ "parts": [
+ {
+ "name": "Trigger",
+ "props": [
+ {
+ "name": "aria-label",
+ "type": "string",
+ "required": true,
+ "defaultValue": null,
+ "description": "Required accessible name for the country selector button."
+ },
+ {
+ "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": "country",
+ "type": "PhoneCountryOption",
+ "required": false,
+ "defaultValue": null,
+ "description": "Prepared country whose flag is displayed and whose label describes the trigger. Omit it to show a world icon."
+ },
+ {
+ "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": "disabled",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": "Disables the native trigger button."
+ },
+ {
+ "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": "openOnHover",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Whether the popover should also open when the trigger is hovered."
+ },
+ {
+ "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": "Options",
+ "props": [
+ {
+ "name": "countries",
+ "type": "readonly PhoneCountryOption[]",
+ "required": true,
+ "defaultValue": null,
+ "description": "Prepared choices with a unique value, localized label, calling code without a plus sign, and flag node. The supplied order is preserved after the matching selected country."
+ },
+ {
+ "name": "emptyLabel",
+ "type": "string",
+ "required": false,
+ "defaultValue": "No results",
+ "description": "Status message shown when no country names match. Defaults to No results."
+ },
+ {
+ "name": "onValueChange",
+ "type": "(value: string) => void",
+ "required": true,
+ "defaultValue": null,
+ "description": "Called with the chosen country value. The host owns the selected country and phone number."
+ },
+ {
+ "name": "searchLabel",
+ "type": "string",
+ "required": false,
+ "defaultValue": "Search",
+ "description": "Accessible name and placeholder of the country search field. Defaults to Search."
+ },
+ {
+ "name": "value",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Selected country value. Its row appears first only while it matches the search."
+ }
+ ]
+ }
+ ]
+ },
{
"name": "Dropdown",
"entryPoint": "twenty-ui/components",
@@ -7329,13 +7445,6 @@
"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",
@@ -7357,13 +7466,6 @@
"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>",
diff --git a/packages/twenty-ui/src/components/index.ts b/packages/twenty-ui/src/components/index.ts
index 057d0d2caff..5196f6bd692 100644
--- a/packages/twenty-ui/src/components/index.ts
+++ b/packages/twenty-ui/src/components/index.ts
@@ -53,6 +53,10 @@ export type { LightButtonProps } from './input/LightButton/types/LightButtonProp
export { LightIconButton } from './input/LightIconButton/LightIconButton';
export type { LightIconButtonProps } from './input/LightIconButton/types/LightIconButtonProps';
export { MainButton } from './input/MainButton/MainButton';
+export { PhoneCountryPicker } from './input/PhoneCountryPicker/PhoneCountryPicker';
+export type { PhoneCountryOption } from './input/PhoneCountryPicker/types/PhoneCountryOption';
+export type { PhoneCountryPickerOptionsProps } from './input/PhoneCountryPicker/types/PhoneCountryPickerOptionsProps';
+export type { PhoneCountryPickerTriggerProps } from './input/PhoneCountryPicker/types/PhoneCountryPickerTriggerProps';
export { SearchInput } from './input/SearchInput/SearchInput';
export type { SearchInputProps } from './input/SearchInput/types/SearchInputProps';
export { SettingsRow } from './input/SettingsRow/SettingsRow';
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.module.scss b/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.module.scss
new file mode 100644
index 00000000000..37226aefb51
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.module.scss
@@ -0,0 +1,67 @@
+.trigger {
+ @include focus-ring;
+
+ align-items: center;
+ background: none;
+ block-size: var(--t-spacing-8);
+ border: 0;
+ border-end-start-radius: var(--t-border-radius-xs);
+ border-inline-end: 1px solid var(--t-border-color-medium);
+ border-start-start-radius: var(--t-border-radius-xs);
+ color: var(--t-font-color-tertiary);
+ cursor: pointer;
+ display: inline-flex;
+ flex-shrink: 0;
+ gap: var(--t-spacing-0_5);
+ padding-block: 0;
+ padding-inline: var(--t-spacing-2) var(--t-spacing-1);
+ user-select: none;
+
+ &:disabled,
+ &[aria-disabled='true'] {
+ cursor: not-allowed;
+ }
+
+ &:not(:disabled, [aria-disabled='true']) {
+ @include hover-capable {
+ &:hover {
+ background: var(--t-background-transparent-light);
+ }
+ }
+ }
+}
+
+.triggerFlag,
+.optionFlag {
+ align-items: center;
+ color: var(--t-font-color-tertiary);
+ display: inline-flex;
+ justify-content: center;
+
+ svg {
+ block-size: 12px;
+ border-radius: var(--t-border-radius-xs);
+ }
+}
+
+.triggerFlag svg {
+ inline-size: 16px;
+}
+
+.optionFlag {
+ padding-inline-end: var(--t-spacing-1);
+}
+
+.chevron {
+ block-size: 14px;
+ inline-size: 14px;
+}
+
+.selectedCountryLabel {
+ block-size: 1px;
+ clip-path: inset(50%);
+ inline-size: 1px;
+ overflow: hidden;
+ position: absolute;
+ white-space: nowrap;
+}
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.module.scss.d.ts b/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.module.scss.d.ts
new file mode 100644
index 00000000000..417cb0fe949
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.module.scss.d.ts
@@ -0,0 +1,8 @@
+declare const classNames: {
+ readonly trigger: 'trigger';
+ readonly triggerFlag: 'triggerFlag';
+ readonly optionFlag: 'optionFlag';
+ readonly chevron: 'chevron';
+ readonly selectedCountryLabel: 'selectedCountryLabel';
+};
+export default classNames;
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.tsx
new file mode 100644
index 00000000000..32f431ebbeb
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/PhoneCountryPicker.tsx
@@ -0,0 +1,7 @@
+import { PhoneCountryPickerOptions } from './internal/PhoneCountryPickerOptions';
+import { PhoneCountryPickerTrigger } from './internal/PhoneCountryPickerTrigger';
+
+export const PhoneCountryPicker = {
+ Trigger: PhoneCountryPickerTrigger,
+ Options: PhoneCountryPickerOptions,
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPicker.interactions.stories.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPicker.interactions.stories.tsx
new file mode 100644
index 00000000000..019fcd8a640
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPicker.interactions.stories.tsx
@@ -0,0 +1,246 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
+
+import { Button } from '@ui/primitives/input/Button/Button';
+import { Text } from '@ui/primitives/typography/Text/Text';
+import { ComponentDecorator } from '@ui/testing';
+
+import { PhoneCountryPickerExample } from './PhoneCountryPickerExample';
+import { openPhoneCountryPicker } from './openPhoneCountryPicker';
+import { PHONE_COUNTRY_OPTIONS } from './phoneCountryOptions';
+import { PHONE_COUNTRY_PICKER_STORY_A11Y_PARAMETERS } from './phoneCountryPickerStoryA11yParameters';
+
+const meta: Meta<typeof PhoneCountryPickerExample> = {
+ title: 'UI/Input/PhoneCountryPicker/Interactions',
+ component: PhoneCountryPickerExample,
+ render: (args) => (
+ <PhoneCountryPickerExample key={args.initialValue} {...args} />
+ ),
+ tags: ['!autodocs'],
+ decorators: [ComponentDecorator],
+ parameters: {
+ container: { width: 360, height: 360 },
+ a11y: PHONE_COUNTRY_PICKER_STORY_A11Y_PARAMETERS,
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof PhoneCountryPickerExample>;
+
+export const CountryNameSearch: Story = {
+ args: {
+ countries: [
+ ...PHONE_COUNTRY_OPTIONS,
+ { value: 'RE', label: 'Réunion', callingCode: '262', flag: '🇷🇪' },
+ ],
+ onValueChange: fn(),
+ },
+ play: async ({ canvasElement, args }) => {
+ const { dialog, search } = await openPhoneCountryPicker({ canvasElement });
+
+ for (const query of ['reunion', 'RÉUNION']) {
+ await userEvent.clear(search);
+ await userEvent.type(search, query);
+ await expect(within(dialog).getAllByRole('button')).toHaveLength(1);
+ await expect(
+ within(dialog).getByRole('button', { name: 'Réunion (+262)' }),
+ ).toBeVisible();
+ }
+ await userEvent.clear(search);
+ await userEvent.type(search, 'a');
+ await expect(
+ within(dialog)
+ .getAllByRole('button')
+ .map((choice) => choice.textContent),
+ ).toEqual([
+ expect.stringContaining('France (+33)'),
+ expect.stringContaining('Canada (+1)'),
+ expect.stringContaining('Germany (+49)'),
+ expect.stringContaining('United States (+1)'),
+ ]);
+ await userEvent.clear(search);
+ await userEvent.type(search, 'uNiTeD');
+ await expect(within(dialog).getAllByRole('button')).toHaveLength(2);
+ await expect(
+ within(dialog).queryByRole('button', { name: 'France (+33)' }),
+ ).not.toBeInTheDocument();
+ await expect(within(dialog).getAllByRole('button')[0]).toHaveAccessibleName(
+ 'United Kingdom (+44)',
+ );
+
+ for (const query of [' France ', '+33', '33', 'GB', 'unknown']) {
+ await userEvent.clear(search);
+ await userEvent.type(search, query);
+ await expect(within(dialog).queryAllByRole('button')).toHaveLength(0);
+ await expect(within(dialog).getByRole('status')).toHaveTextContent(
+ 'No results',
+ );
+ await userEvent.keyboard('{Enter}');
+ await expect(dialog).toBeVisible();
+ await expect(search).toHaveFocus();
+ }
+ await expect(args.onValueChange).not.toHaveBeenCalled();
+ },
+};
+
+export const KeyboardSelection: Story = {
+ args: { onValueChange: fn() },
+ play: async ({ canvasElement, args }) => {
+ const trigger = within(canvasElement).getByRole('button', {
+ name: 'Phone country',
+ });
+
+ await userEvent.tab();
+ await expect(trigger).toHaveFocus();
+ await userEvent.keyboard('{Enter}');
+ const dialog = await within(canvasElement.ownerDocument.body).findByRole(
+ 'dialog',
+ { name: 'Phone country choices' },
+ );
+ const search = within(dialog).getByRole('searchbox');
+
+ await waitFor(() => expect(search).toHaveFocus());
+ await userEvent.keyboard('{Enter}');
+ await expect(args.onValueChange).not.toHaveBeenCalled();
+ await userEvent.keyboard('{ArrowDown}{ArrowDown}');
+ await expect(
+ within(dialog).getByRole('button', { name: 'Canada (+1)' }),
+ ).toHaveFocus();
+ await userEvent.keyboard('{Enter}');
+ await expect(args.onValueChange).toHaveBeenCalledWith('CA');
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ await waitFor(() => expect(trigger).toHaveFocus());
+
+ const reopened = await openPhoneCountryPicker({ canvasElement });
+
+ await userEvent.type(reopened.search, 'germany');
+ await userEvent.keyboard('{Enter}');
+ await expect(args.onValueChange).toHaveBeenLastCalledWith('DE');
+ await waitFor(() => expect(reopened.dialog).not.toBeInTheDocument());
+ await waitFor(() => expect(trigger).toHaveFocus());
+ },
+};
+
+export const LetterNavigation: Story = {
+ args: { onValueChange: fn() },
+ play: async ({ canvasElement, args }) => {
+ const { dialog } = await openPhoneCountryPicker({ canvasElement });
+
+ await userEvent.keyboard('{ArrowDown}');
+ await expect(
+ within(dialog).getByRole('button', { name: 'France (+33)' }),
+ ).toHaveFocus();
+ await userEvent.keyboard('g');
+ await expect(
+ within(dialog).getByRole('button', { name: 'Germany (+49)' }),
+ ).toHaveFocus();
+ await userEvent.keyboard('{Enter}');
+ await expect(args.onValueChange).toHaveBeenCalledWith('DE');
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ },
+};
+
+export const DismissalResetsSearch: Story = {
+ args: { onValueChange: fn() },
+ render: (args) => (
+ <Text style={{ display: 'grid', gap: 16 }}>
+ <PhoneCountryPickerExample key={args.initialValue} {...args} />
+ <Button>Next field</Button>
+ </Text>
+ ),
+ play: async ({ canvasElement, args }) => {
+ const { dialog, search, trigger } = await openPhoneCountryPicker({
+ canvasElement,
+ });
+
+ await userEvent.type(search, 'Germany');
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ await waitFor(() => expect(trigger).toHaveFocus());
+ const reopened = await openPhoneCountryPicker({ canvasElement });
+
+ await expect(reopened.search).toHaveValue('');
+ await expect(within(reopened.dialog).getAllByRole('button')).toHaveLength(
+ 5,
+ );
+ const nextField = within(canvasElement).getByRole('button', {
+ name: 'Next field',
+ });
+
+ await userEvent.click(nextField);
+ await waitFor(() => expect(reopened.dialog).not.toBeInTheDocument());
+ await expect(nextField).toHaveFocus();
+ await expect(args.onValueChange).not.toHaveBeenCalled();
+ },
+};
+
+export const IndependentInstances: Story = {
+ render: (args) => (
+ <Text style={{ display: 'flex', gap: 24 }}>
+ <PhoneCountryPickerExample
+ key={args.initialValue}
+ {...args}
+ label="Primary country"
+ />
+ <PhoneCountryPickerExample label="Secondary country" initialValue="GB" />
+ </Text>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const primary = await openPhoneCountryPicker({
+ canvasElement,
+ label: 'Primary country',
+ });
+
+ await userEvent.type(primary.search, 'Canada');
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() => expect(primary.dialog).not.toBeInTheDocument());
+ await expect(
+ canvas.getByRole('status', { name: 'Primary country selection' }),
+ ).toHaveTextContent('Canada (+1)');
+ await expect(
+ canvas.getByRole('status', { name: 'Secondary country selection' }),
+ ).toHaveTextContent('United Kingdom (+44)');
+
+ const secondary = await openPhoneCountryPicker({
+ canvasElement,
+ label: 'Secondary country',
+ });
+
+ await expect(secondary.search).toHaveValue('');
+ await expect(
+ within(secondary.dialog).getAllByRole('button')[0],
+ ).toHaveAccessibleName('United Kingdom (+44)');
+ await userEvent.click(
+ within(secondary.dialog).getByRole('button', { name: 'Germany (+49)' }),
+ );
+ await waitFor(() => expect(secondary.dialog).not.toBeInTheDocument());
+ await expect(
+ canvas.getByRole('status', { name: 'Primary country selection' }),
+ ).toHaveTextContent('Canada (+1)');
+ await expect(
+ canvas.getByRole('status', { name: 'Secondary country selection' }),
+ ).toHaveTextContent('Germany (+49)');
+ },
+};
+
+export const CustomLabelsAndEmptyChoices: Story = {
+ args: {
+ countries: [],
+ searchLabel: 'Find a country',
+ emptyLabel: 'No countries available',
+ onValueChange: fn(),
+ },
+ play: async ({ canvasElement, args }) => {
+ const { dialog, search } = await openPhoneCountryPicker({ canvasElement });
+
+ await expect(search).toHaveAccessibleName('Find a country');
+ await expect(within(dialog).getByRole('status')).toHaveTextContent(
+ 'No countries available',
+ );
+ await userEvent.keyboard('{ArrowDown}{Enter}');
+ await expect(search).toHaveFocus();
+ await expect(dialog).toBeVisible();
+ await expect(args.onValueChange).not.toHaveBeenCalled();
+ },
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPicker.stories.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPicker.stories.tsx
new file mode 100644
index 00000000000..a91543e2533
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPicker.stories.tsx
@@ -0,0 +1,142 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
+
+import { TextDirectionProvider } from '@ui/primitives/layout/TextDirectionProvider/TextDirectionProvider';
+import { Text } from '@ui/primitives/typography/Text/Text';
+import { ComponentDecorator } from '@ui/testing';
+
+import { PhoneCountryPickerExample } from './PhoneCountryPickerExample';
+import { openPhoneCountryPicker } from './openPhoneCountryPicker';
+import { PHONE_COUNTRY_PICKER_STORY_A11Y_PARAMETERS } from './phoneCountryPickerStoryA11yParameters';
+
+const meta: Meta<typeof PhoneCountryPickerExample> = {
+ title: 'UI/Input/PhoneCountryPicker',
+ component: PhoneCountryPickerExample,
+ render: (args) => (
+ <PhoneCountryPickerExample key={args.initialValue} {...args} />
+ ),
+ decorators: [ComponentDecorator],
+ parameters: {
+ container: { width: 320, height: 360 },
+ a11y: PHONE_COUNTRY_PICKER_STORY_A11Y_PARAMETERS,
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof PhoneCountryPickerExample>;
+
+export const Documentation: Story = {};
+
+export const Default: Story = {
+ args: { onValueChange: fn() },
+ play: async ({ canvasElement, args }) => {
+ const { dialog, trigger } = await openPhoneCountryPicker({ canvasElement });
+ const choices = within(dialog).getAllByRole('button');
+
+ await expect(trigger).toHaveAccessibleDescription('France');
+ await expect(choices.map((choice) => choice.textContent)).toEqual([
+ expect.stringContaining('France (+33)'),
+ expect.stringContaining('Canada (+1)'),
+ expect.stringContaining('Germany (+49)'),
+ expect.stringContaining('United Kingdom (+44)'),
+ expect.stringContaining('United States (+1)'),
+ ]);
+ await expect(
+ within(dialog).getByRole('button', { name: 'France (+33)' }),
+ ).toHaveAttribute('aria-pressed', 'true');
+ await userEvent.click(
+ within(dialog).getByRole('button', { name: 'Canada (+1)' }),
+ );
+ await expect(args.onValueChange).toHaveBeenCalledOnce();
+ await expect(args.onValueChange).toHaveBeenCalledWith('CA');
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ await waitFor(() => expect(trigger).toHaveFocus());
+ await expect(trigger).toHaveAccessibleDescription('Canada');
+ await expect(
+ within(canvasElement).getByRole('status', {
+ name: 'Phone country selection',
+ }),
+ ).toHaveTextContent('Canada (+1)');
+
+ const reopened = await openPhoneCountryPicker({ canvasElement });
+
+ await expect(
+ within(reopened.dialog).getAllByRole('button')[0],
+ ).toHaveAccessibleName('Canada (+1)');
+ await expect(
+ within(reopened.dialog).getByRole('button', { name: 'Canada (+1)' }),
+ ).toHaveAttribute('aria-pressed', 'true');
+ },
+};
+
+export const Dark: Story = {
+ ...Default,
+ args: { onValueChange: fn() },
+ globals: { colorScheme: 'dark' },
+};
+
+export const International: Story = {
+ args: { initialValue: '' },
+ play: async ({ canvasElement }) => {
+ const { dialog, trigger } = await openPhoneCountryPicker({ canvasElement });
+
+ await expect(trigger).not.toHaveAccessibleDescription();
+ for (const choice of within(dialog).getAllByRole('button')) {
+ await expect(choice).toHaveAttribute('aria-pressed', 'false');
+ }
+ await userEvent.click(
+ within(dialog).getByRole('button', { name: 'United States (+1)' }),
+ );
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ await expect(trigger).toHaveAccessibleDescription('United States');
+ await expect(
+ within(canvasElement).getByRole('status', {
+ name: 'Phone country selection',
+ }),
+ ).toHaveTextContent('United States (+1)');
+ },
+};
+
+export const Disabled: Story = {
+ args: { disabled: true, onValueChange: fn() },
+ play: async ({ canvasElement, args }) => {
+ const trigger = within(canvasElement).getByRole('button', {
+ name: 'Phone country',
+ });
+
+ await expect(trigger).toBeDisabled();
+ await userEvent.click(trigger);
+ await expect(
+ within(canvasElement.ownerDocument.body).queryByRole('dialog'),
+ ).not.toBeInTheDocument();
+ await expect(args.onValueChange).not.toHaveBeenCalled();
+ },
+};
+
+export const RightToLeft: Story = {
+ render: (args) => (
+ <TextDirectionProvider direction="rtl">
+ <Text dir="rtl">
+ <PhoneCountryPickerExample key={args.initialValue} {...args} />
+ </Text>
+ </TextDirectionProvider>
+ ),
+ play: async ({ canvasElement }) => {
+ const { dialog, trigger } = await openPhoneCountryPicker({ canvasElement });
+
+ await expect(getComputedStyle(trigger).direction).toBe('rtl');
+ await expect(getComputedStyle(trigger).borderLeftWidth).toBe('1px');
+ await expect(getComputedStyle(trigger).borderRightWidth).toBe('0px');
+ await expect(getComputedStyle(dialog).direction).toBe('rtl');
+ await userEvent.click(
+ within(dialog).getByRole('button', { name: 'United Kingdom (+44)' }),
+ );
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ await waitFor(() => expect(trigger).toHaveFocus());
+ await expect(
+ within(canvasElement).getByRole('status', {
+ name: 'Phone country selection',
+ }),
+ ).toHaveTextContent('United Kingdom (+44)');
+ },
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPickerExample.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPickerExample.tsx
new file mode 100644
index 00000000000..9ad44f13e02
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/PhoneCountryPickerExample.tsx
@@ -0,0 +1,62 @@
+import { useState } from 'react';
+
+import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';
+import { Text } from '@ui/primitives/typography/Text/Text';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { PhoneCountryPicker } from '../PhoneCountryPicker';
+import { type PhoneCountryOption } from '../types/PhoneCountryOption';
+import { PHONE_COUNTRY_OPTIONS } from './phoneCountryOptions';
+
+type PhoneCountryPickerExampleProps = {
+ initialValue?: string;
+ disabled?: boolean;
+ label?: string;
+ countries?: readonly PhoneCountryOption[];
+ searchLabel?: string;
+ emptyLabel?: string;
+ onValueChange?: (value: string) => void;
+};
+
+export const PhoneCountryPickerExample = ({
+ initialValue = 'FR',
+ disabled = false,
+ label = 'Phone country',
+ countries = PHONE_COUNTRY_OPTIONS,
+ searchLabel,
+ emptyLabel,
+ onValueChange,
+}: PhoneCountryPickerExampleProps) => {
+ const [value, setValue] = useState(initialValue);
+ const country = countries.find((choice) => choice.value === value);
+
+ return (
+ <Text style={{ display: 'grid', gap: 8, justifyItems: 'start' }}>
+ <Text>{label}</Text>
+ <Dropdown.Root type="picker">
+ <PhoneCountryPicker.Trigger
+ aria-label={label}
+ country={country}
+ disabled={disabled}
+ />
+ <Dropdown.Content aria-label={`${label} choices`} width={280}>
+ <PhoneCountryPicker.Options
+ countries={countries}
+ value={value}
+ onValueChange={(nextValue) => {
+ setValue(nextValue);
+ onValueChange?.(nextValue);
+ }}
+ searchLabel={searchLabel}
+ emptyLabel={emptyLabel}
+ />
+ </Dropdown.Content>
+ </Dropdown.Root>
+ <Text role="status" aria-label={`${label} selection`}>
+ {isDefined(country)
+ ? `${country.label} (+${country.callingCode})`
+ : 'International'}
+ </Text>
+ </Text>
+ );
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/openPhoneCountryPicker.ts b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/openPhoneCountryPicker.ts
new file mode 100644
index 00000000000..4fd68ef8ae7
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/openPhoneCountryPicker.ts
@@ -0,0 +1,23 @@
+import { expect, userEvent, waitFor, within } from 'storybook/test';
+
+export const openPhoneCountryPicker = async ({
+ canvasElement,
+ label = 'Phone country',
+}: {
+ canvasElement: HTMLElement;
+ label?: string;
+}) => {
+ const trigger = within(canvasElement).getByRole('button', { name: label });
+
+ await userEvent.click(trigger);
+ const dialog = await within(canvasElement.ownerDocument.body).findByRole(
+ 'dialog',
+ { name: `${label} choices` },
+ );
+ const search = within(dialog).getByRole('searchbox');
+
+ await waitFor(() => expect(dialog).toBeVisible());
+ await waitFor(() => expect(search).toHaveFocus());
+
+ return { dialog, search, trigger };
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/phoneCountryOptions.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/phoneCountryOptions.tsx
new file mode 100644
index 00000000000..caf33210feb
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/phoneCountryOptions.tsx
@@ -0,0 +1,9 @@
+import { type PhoneCountryOption } from '../types/PhoneCountryOption';
+
+export const PHONE_COUNTRY_OPTIONS: readonly PhoneCountryOption[] = [
+ { value: 'CA', label: 'Canada', callingCode: '1', flag: '🇨🇦' },
+ { value: 'FR', label: 'France', callingCode: '33', flag: '🇫🇷' },
+ { value: 'DE', label: 'Germany', callingCode: '49', flag: '🇩🇪' },
+ { value: 'GB', label: 'United Kingdom', callingCode: '44', flag: '🇬🇧' },
+ { value: 'US', label: 'United States', callingCode: '1', flag: '🇺🇸' },
+];
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/phoneCountryPickerStoryA11yParameters.ts b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/phoneCountryPickerStoryA11yParameters.ts
new file mode 100644
index 00000000000..8a0fe6a36b2
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__stories__/phoneCountryPickerStoryA11yParameters.ts
@@ -0,0 +1,14 @@
+import { A11Y_DEFER_COLOR_CONTRAST } from '@ui/testing';
+
+export const PHONE_COUNTRY_PICKER_STORY_A11Y_PARAMETERS = {
+ ...A11Y_DEFER_COLOR_CONTRAST,
+ config: {
+ rules: [
+ ...A11Y_DEFER_COLOR_CONTRAST.config.rules,
+ {
+ id: 'aria-hidden-focus',
+ selector: '[aria-hidden="true"]:not([data-base-ui-focus-guard])',
+ },
+ ],
+ },
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/__tests__/PhoneCountryPicker.test.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__tests__/PhoneCountryPicker.test.tsx
new file mode 100644
index 00000000000..4de91df46e6
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/__tests__/PhoneCountryPicker.test.tsx
@@ -0,0 +1,85 @@
+import { render, screen } from '@testing-library/react';
+import { type ReactNode } from 'react';
+import { describe, expect, it } from 'vitest';
+
+import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
+import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';
+
+import { PhoneCountryPicker } from '../PhoneCountryPicker';
+import styles from '../PhoneCountryPicker.module.scss';
+
+const PhoneCountryPickerWrapper = ({ children }: { children: ReactNode }) => (
+ <Dropdown.Root type="picker">{children}</Dropdown.Root>
+);
+
+runComponentConformance({
+ name: 'PhoneCountryPicker.Trigger',
+ element: <PhoneCountryPicker.Trigger aria-label="Phone country" />,
+ refInstanceOf: HTMLButtonElement,
+ wrapper: PhoneCountryPickerWrapper,
+ ownClassName: styles.trigger,
+ skip: ['renderProp'],
+});
+
+describe('PhoneCountryPicker.Trigger', () => {
+ it('preserves native button attributes and the accessible name with a decorative flag', () => {
+ render(
+ <PhoneCountryPickerWrapper>
+ <PhoneCountryPicker.Trigger
+ aria-label="Phone country"
+ name="phone-country"
+ value="CA"
+ country={{
+ value: 'CA',
+ label: 'Canada',
+ callingCode: '1',
+ flag: <svg role="img" aria-label="Canada flag" />,
+ }}
+ />
+ </PhoneCountryPickerWrapper>,
+ );
+
+ const trigger = screen.getByRole('button', { name: 'Phone country' });
+
+ expect(trigger).toHaveAttribute('type', 'button');
+ expect(trigger).toHaveAttribute('name', 'phone-country');
+ expect(trigger).toHaveAttribute('value', 'CA');
+ expect(trigger).toHaveAttribute('aria-haspopup', 'dialog');
+ expect(trigger).toHaveAccessibleDescription('Canada');
+ expect(screen.queryByRole('img')).not.toBeInTheDocument();
+ });
+
+ it('describes the selected country after a supplied description', () => {
+ render(
+ <PhoneCountryPickerWrapper>
+ <span id="phone-country-hint">Used for text messages</span>
+ <PhoneCountryPicker.Trigger
+ aria-label="Phone country"
+ aria-describedby="phone-country-hint"
+ country={{
+ value: 'FR',
+ label: 'France',
+ callingCode: '33',
+ flag: <svg />,
+ }}
+ />
+ </PhoneCountryPickerWrapper>,
+ );
+
+ expect(
+ screen.getByRole('button', { name: 'Phone country' }),
+ ).toHaveAccessibleDescription('France Used for text messages');
+ });
+
+ it('has no description without a selected country', () => {
+ render(
+ <PhoneCountryPickerWrapper>
+ <PhoneCountryPicker.Trigger aria-label="Phone country" />
+ </PhoneCountryPickerWrapper>,
+ );
+
+ expect(
+ screen.getByRole('button', { name: 'Phone country' }),
+ ).not.toHaveAccessibleDescription();
+ });
+});
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/PhoneCountryPickerOptions.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/PhoneCountryPickerOptions.tsx
new file mode 100644
index 00000000000..9b06b6c46b2
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/PhoneCountryPickerOptions.tsx
@@ -0,0 +1,78 @@
+import { isNonEmptyArray } from '@sniptt/guards';
+import { useState } from 'react';
+
+import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';
+import { OverflowingTextWithTooltip } from '@ui/primitives/typography/OverflowingTextWithTooltip/OverflowingTextWithTooltip';
+import { normalizeSearchText } from '@ui/utilities/internal/normalizeSearchText';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import styles from '../PhoneCountryPicker.module.scss';
+import { type PhoneCountryPickerOptionsProps } from '../types/PhoneCountryPickerOptionsProps';
+import { getPhoneCountryOptionLabel } from './getPhoneCountryOptionLabel';
+
+export const PhoneCountryPickerOptions = ({
+ countries,
+ value,
+ onValueChange,
+ searchLabel = 'Search',
+ emptyLabel = 'No results',
+}: PhoneCountryPickerOptionsProps) => {
+ const [search, setSearch] = useState('');
+ const normalizedSearch = normalizeSearchText(search);
+ const matchingCountries = countries.filter(({ label }) =>
+ normalizeSearchText(label).includes(normalizedSearch),
+ );
+ const selectedCountry = matchingCountries.find(
+ (country) => country.value === value,
+ );
+ const orderedCountries = isDefined(selectedCountry)
+ ? [
+ selectedCountry,
+ ...matchingCountries.filter((country) => country.value !== value),
+ ]
+ : matchingCountries;
+
+ return (
+ <>
+ <Dropdown.Search
+ value={search}
+ onValueChange={setSearch}
+ placeholder={searchLabel}
+ aria-label={searchLabel}
+ />
+ <Dropdown.Separator />
+ <Dropdown.Section scrollable>
+ {!isNonEmptyArray(orderedCountries) && (
+ <Dropdown.Empty>{emptyLabel}</Dropdown.Empty>
+ )}
+ {orderedCountries.map((country) => {
+ const optionLabel = getPhoneCountryOptionLabel(country);
+
+ return (
+ <Dropdown.OptionItem
+ key={country.value}
+ aria-label={optionLabel}
+ selected={country.value === value}
+ onSelect={() => onValueChange(country.value)}
+ startIcon={
+ <span className={styles.optionFlag} aria-hidden>
+ {country.flag}
+ </span>
+ }
+ >
+ <OverflowingTextWithTooltip
+ text={
+ <>
+ {country.label} (<bdi dir="ltr">+{country.callingCode}</bdi>
+ )
+ </>
+ }
+ tooltipContent={optionLabel}
+ />
+ </Dropdown.OptionItem>
+ );
+ })}
+ </Dropdown.Section>
+ </>
+ );
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/PhoneCountryPickerTrigger.tsx b/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/PhoneCountryPickerTrigger.tsx
new file mode 100644
index 00000000000..d077943b6d0
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/PhoneCountryPickerTrigger.tsx
@@ -0,0 +1,44 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { useId } from 'react';
+
+import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';
+import { IconChevronDown, IconWorld } from '@ui/icon';
+import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import styles from '../PhoneCountryPicker.module.scss';
+import { type PhoneCountryPickerTriggerProps } from '../types/PhoneCountryPickerTriggerProps';
+
+export const PhoneCountryPickerTrigger = ({
+ country,
+ className,
+ 'aria-describedby': ariaDescribedBy,
+ ...props
+}: PhoneCountryPickerTriggerProps) => {
+ const selectedCountryLabelId = useId();
+ const describedBy =
+ [isDefined(country) && selectedCountryLabelId, ariaDescribedBy]
+ .filter(isNonEmptyString)
+ .join(' ') || undefined;
+
+ return (
+ <Dropdown.Trigger
+ {...props}
+ aria-describedby={describedBy}
+ className={mergeClassNames(styles.trigger, className)}
+ >
+ <span className={styles.triggerFlag} aria-hidden>
+ {country?.flag ?? <IconWorld />}
+ </span>
+ {isDefined(country) && (
+ <span
+ id={selectedCountryLabelId}
+ className={styles.selectedCountryLabel}
+ >
+ {country.label}
+ </span>
+ )}
+ <IconChevronDown className={styles.chevron} aria-hidden />
+ </Dropdown.Trigger>
+ );
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/getPhoneCountryOptionLabel.ts b/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/getPhoneCountryOptionLabel.ts
new file mode 100644
index 00000000000..5ff1ee9d8cb
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/internal/getPhoneCountryOptionLabel.ts
@@ -0,0 +1,6 @@
+import { type PhoneCountryOption } from '../types/PhoneCountryOption';
+
+export const getPhoneCountryOptionLabel = ({
+ label,
+ callingCode,
+}: PhoneCountryOption) => `${label} (+${callingCode})`;
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryOption.ts b/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryOption.ts
new file mode 100644
index 00000000000..41cc105bf4c
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryOption.ts
@@ -0,0 +1,8 @@
+import { type ReactNode } from 'react';
+
+export type PhoneCountryOption = {
+ value: string;
+ label: string;
+ callingCode: string;
+ flag: ReactNode;
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryPickerOptionsProps.ts b/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryPickerOptionsProps.ts
new file mode 100644
index 00000000000..96f65ca4739
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryPickerOptionsProps.ts
@@ -0,0 +1,9 @@
+import { type PhoneCountryOption } from './PhoneCountryOption';
+
+export type PhoneCountryPickerOptionsProps = {
+ countries: readonly PhoneCountryOption[];
+ value?: string;
+ onValueChange: (value: string) => void;
+ searchLabel?: string;
+ emptyLabel?: string;
+};
diff --git a/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryPickerTriggerProps.ts b/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryPickerTriggerProps.ts
new file mode 100644
index 00000000000..d7e99b8e4f7
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/PhoneCountryPicker/types/PhoneCountryPickerTriggerProps.ts
@@ -0,0 +1,11 @@
+import { type DropdownTriggerProps } from '@ui/components/navigation/Dropdown/types/DropdownTriggerProps';
+
+import { type PhoneCountryOption } from './PhoneCountryOption';
+
+export type PhoneCountryPickerTriggerProps = Omit<
+ DropdownTriggerProps,
+ 'children' | 'render' | 'nativeButton' | 'aria-label'
+> & {
+ country?: PhoneCountryOption;
+ 'aria-label': string;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownTriggerProps.ts b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownTriggerProps.ts
index 3c00db661dd..4766b0c57e6 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownTriggerProps.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/types/DropdownTriggerProps.ts
@@ -1,3 +1,6 @@
import { type Popover as PopoverPrimitive } from '@base-ui/react/popover';
-export type DropdownTriggerProps = PopoverPrimitive.Trigger.Props;
+export type DropdownTriggerProps = Omit<
+ PopoverPrimitive.Trigger.Props,
+ 'handle' | 'payload'
+>;
diff --git a/packages/twenty-ui/src/theme/__stories__/ThemeProvider.stories.tsx b/packages/twenty-ui/src/theme/__stories__/ThemeProvider.stories.tsx
index 31eaea35eea..d5ca38e9adf 100644
--- a/packages/twenty-ui/src/theme/__stories__/ThemeProvider.stories.tsx
+++ b/packages/twenty-ui/src/theme/__stories__/ThemeProvider.stories.tsx
@@ -377,5 +377,6 @@ export const NestedScopesAndPortals: Story = {
await userEvent.click(
canvas.getByRole('button', { name: 'Close explicit portal' }),
);
+ await waitFor(() => expect(explicitPortal).not.toBeInTheDocument());
},
};
diff --git a/packages/twenty-ui/src/utilities/internal/__tests__/normalizeSearchText.test.ts b/packages/twenty-ui/src/utilities/internal/__tests__/normalizeSearchText.test.ts
new file mode 100644
index 00000000000..d0d84aefe4b
--- /dev/null
+++ b/packages/twenty-ui/src/utilities/internal/__tests__/normalizeSearchText.test.ts
@@ -0,0 +1,32 @@
+import { normalizeSearchText } from '../normalizeSearchText';
+
+describe('normalizeSearchText', () => {
+ it('lowercases without depending on the default locale', () => {
+ expect(normalizeSearchText('United Kingdom')).toBe('united kingdom');
+ expect(normalizeSearchText('India')).toBe('india');
+ expect(normalizeSearchText('İtalya')).toBe('italya');
+ });
+
+ it('removes accents', () => {
+ expect(normalizeSearchText("Côte d'Ivoire")).toBe("cote d'ivoire");
+ expect(normalizeSearchText('Curaçao')).toBe('curacao');
+ expect(normalizeSearchText('RÉUNION')).toBe('reunion');
+ expect(normalizeSearchText('Türkiye')).toBe('turkiye');
+ expect(normalizeSearchText('Åland Islands')).toBe('aland islands');
+ });
+
+ it('replaces letters that have no accent decomposition', () => {
+ expect(normalizeSearchText('Øresund')).toBe('oresund');
+ expect(normalizeSearchText('Æther')).toBe('aether');
+ expect(normalizeSearchText('Straße')).toBe('strasse');
+ expect(normalizeSearchText('Ðakovo')).toBe('dakovo');
+ expect(normalizeSearchText('Þingvellir')).toBe('thingvellir');
+ expect(normalizeSearchText('Łódź')).toBe('lodz');
+ expect(normalizeSearchText('Œuvre')).toBe('oeuvre');
+ });
+
+ it('keeps whitespace, digits, and punctuation', () => {
+ expect(normalizeSearchText(' France ')).toBe(' france ');
+ expect(normalizeSearchText('+44')).toBe('+44');
+ });
+});
diff --git a/packages/twenty-ui/src/utilities/internal/normalizeSearchText.ts b/packages/twenty-ui/src/utilities/internal/normalizeSearchText.ts
new file mode 100644
index 00000000000..771ac4d9cf2
--- /dev/null
+++ b/packages/twenty-ui/src/utilities/internal/normalizeSearchText.ts
@@ -0,0 +1,13 @@
+export const normalizeSearchText = (text: string) =>
+ text
+ .normalize('NFD')
+ .replace(/\p{Diacritic}/gu, '')
+ .replace(/[øØ]/g, 'o')
+ .replace(/[åÅ]/g, 'a')
+ .replace(/[æÆ]/g, 'ae')
+ .replace(/[ßẞ]/g, 'ss')
+ .replace(/[ðÐ]/g, 'd')
+ .replace(/[þÞ]/g, 'th')
+ .replace(/[łŁ]/g, 'l')
+ .replace(/[œŒ]/g, 'oe')
+ .toLowerCase();