Skip to content

The open alternative to Salesforce, designed for AI.

Align Dropdown search activation (#28275)

Raphaël Bosi54fcd884ee42
diff --git a/packages/twenty-docs/ui/components/navigation/dropdown.mdx b/packages/twenty-docs/ui/components/navigation/dropdown.mdx
index 2983312e18f..271c3354899 100644
--- a/packages/twenty-docs/ui/components/navigation/dropdown.mdx
+++ b/packages/twenty-docs/ui/components/navigation/dropdown.mdx
@@ -210,7 +210,9 @@ import { Dropdown } from 'twenty-ui/components/navigation';
</Dropdown.SelectionGroup>;
```
-Search receives focus when the picker opens. Without search, the first enabled selected option receives focus, or the first enabled row when no selected option is present. While `Search` holds text, the first enabled `OptionItem` is highlighted and Enter activates it. Action rows are never picked this way. With an empty search, Enter does nothing; ArrowDown moves focus into the results. When rows are pinned above matches, such as the current value or a "none" row, render them only when they match the search text. The popup stays open when no option matches. Filtering remains caller-owned.
+Search receives focus when the picker opens. Without search, the first enabled selected option receives focus, or the first enabled row when no selected option is present. While `Search` has focus and a nonempty query, the first eligible `OptionItem` across selection groups is highlighted and Enter activates it. Action rows are never picked this way. ArrowDown moves focus to the first enabled row, including actions. Leaving search clears the preview and `aria-activedescendant`, even when the popup stays open. Returning to search restores the preview for the current query.
+
+Enter does nothing for an empty or whitespace-only query, or when no eligible option remains. Composing text with an input method does not activate an option or move focus with arrow keys. When rows are pinned above matches, such as the current value or a "none" row, render them only when they match the search text. The popup stays open when no option matches. Filtering remains caller-owned.
<StoryEmbed
storyId="ui-components-dropdown--multiple-selection-documentation"
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 3c1aa28ef6e..73baccad841 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,7 +22,7 @@ In standalone React, when a popup click override allows bubbling, the installed
The SDK registers native handlers on physical elements. The API fixture overrides the default click blocking and asserts native trigger bubbling and popup callback preservation. Logical portal bubbling to a surrounding React ancestor remains a separate C04 gap in React and Preact: the diagnostic parent count reaches 1 after the trigger click and stays at 1 after the popup item click, instead of reaching 2.
-Dropdown checks controlled opening, native action refs and Button render composition, disabled callback suppression, action callbacks, page navigation, option selection and click-to-close in both runtimes. The portal fixture preserves all 16 rows and checks attachment along the physical collision side, overlap with the trigger and confinement to the owner portal area. A temporary constrained long-menu probe passed End-key focus and scrolling in both runtimes: a 128px popup scrolled to 386px and kept the last item visible. Outside-host dismissal remains a C07 renderer limitation. Clicking the host action invokes that action, while Dropdown remains expanded with its popup mounted. Its picker page checks initial search focus, a single Tab stop across option and action rows, arrow navigation, Tab reentry to the last focused row and a search highlight that follows a keyed reorder in both runtimes. Escape and Back focus restoration are not established by these checks.
+Dropdown checks controlled opening, native action refs and Button render composition, disabled callback suppression, action callbacks, page navigation, option selection and click-to-close in both runtimes. The portal fixture preserves all 16 rows and checks attachment along the physical collision side, overlap with the trigger and confinement to the owner portal area. A temporary constrained long-menu probe passed End-key focus and scrolling in both runtimes: a 128px popup scrolled to 386px and kept the last item visible. Outside-host dismissal remains a C07 renderer limitation. Clicking the host action invokes that action, while Dropdown remains expanded with its popup mounted. Its picker page checks initial search focus, a single Tab stop across option and action rows, arrow navigation and Tab reentry to the last focused row. Search preview clears when focus moves to a row, action or sibling button outside a popup whose outside dismissal is canceled, stays cleared during a keyed reorder, and returns when search regains focus. Nonempty-query Enter selects the first eligible option. Escape and Back focus restoration are not established by these checks.
Typography composition checks constrained text, explicit links, semantic elements, refs and native focus handlers in both runtimes. Overflow tooltip popup acceptance still depends on renderer portal and geometry support.
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-dropdown.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-dropdown.front-component.tsx
index 79fe5b54e2c..86ee60a4e0f 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-dropdown.front-component.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-dropdown.front-component.tsx
@@ -26,7 +26,12 @@ const DropdownExample = () => {
return (
<TwentyUiGalleryCard title="Dropdown">
- <Dropdown.Root type="menu" open={open} onOpenChange={setOpen}>
+ <Dropdown.Root
+ type="menu"
+ open={open}
+ onOpenChange={setOpen}
+ onInteractOutside={(event) => event.preventDefault()}
+ >
<Dropdown.Trigger render={<Button>Choose assignee</Button>} />
<Dropdown.Content aria-label="Assignee actions">
<Dropdown.Page id="root">
@@ -100,6 +105,7 @@ const DropdownExample = () => {
</Dropdown.Page>
</Dropdown.Content>
</Dropdown.Root>
+ <Button>Outside picker</Button>
<Text role="status" aria-label="Assignee">
Assignee: {selection ?? 'Unassigned'}
</Text>
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownTest.ts
index 96082fbb6ff..f901223b89b 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownTest.ts
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownTest.ts
@@ -77,8 +77,59 @@ export const dropdownTest: TwentyUiGalleryPlayFunction = async ({
expect(canvas.getByLabelText('Assignee')).toHaveTextContent(
'Assignee: Unassigned',
);
- await userEvent.click(page.getByRole('button', { name: 'Rank last first' }));
await userEvent.type(search, 'e');
+ await waitFor(() => expect(ada).toHaveAttribute('data-highlighted'), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ expect(search).toHaveAttribute('aria-activedescendant', ada.id);
+ const outsidePicker = canvas.getByRole('button', { name: 'Outside picker' });
+ await userEvent.click(outsidePicker);
+ await waitFor(() => expect(outsidePicker).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
+ expect(page.getByRole('dialog', { name: 'Assignee actions' })).toBeVisible();
+ await waitFor(
+ () => expect(search).not.toHaveAttribute('aria-activedescendant'),
+ { timeout: INTERACTION_TIMEOUT },
+ );
+ expect(ada).not.toHaveAttribute('data-highlighted');
+ expect(grace).not.toHaveAttribute('data-highlighted');
+ await userEvent.click(search);
+ await waitFor(() => expect(ada).toHaveAttribute('data-highlighted'), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ expect(search).toHaveAttribute('aria-activedescendant', ada.id);
+ await userEvent.keyboard('{ArrowDown}');
+ await waitFor(() => expect(ada).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ expect(search).not.toHaveAttribute('aria-activedescendant');
+ expect(ada).not.toHaveAttribute('data-highlighted');
+ await userEvent.keyboard('{ArrowDown}');
+ await waitFor(() => expect(grace).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ expect(ada).not.toHaveAttribute('data-highlighted');
+ await userEvent.keyboard('{ArrowUp}');
+ await waitFor(() => expect(ada).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ await userEvent.keyboard('{ArrowUp}');
+ await waitFor(() => expect(search).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ await waitFor(() => expect(ada).toHaveAttribute('data-highlighted'), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ await userEvent.click(page.getByRole('button', { name: 'Rank last first' }));
+ await waitFor(() => expect(page.getAllByRole('option')[0]).toBe(grace));
+ await waitFor(() =>
+ expect(search).not.toHaveAttribute('aria-activedescendant'),
+ );
+ expect(ada).not.toHaveAttribute('data-highlighted');
+ expect(grace).not.toHaveAttribute('data-highlighted');
+ await userEvent.click(search);
await waitFor(() => expect(grace).toHaveAttribute('data-highlighted'), {
timeout: INTERACTION_TIMEOUT,
});
@@ -138,6 +189,25 @@ export const dropdownTest: TwentyUiGalleryPlayFunction = async ({
await waitFor(() =>
expect(trigger).toHaveAttribute('aria-expanded', 'false'),
);
+ await userEvent.click(trigger);
+ await userEvent.click(
+ await page.findByRole('menuitem', { name: /^Assign person/ }),
+ );
+ const activationSearch = await page.findByRole('searchbox', {
+ name: 'Search people',
+ });
+ await waitFor(() => expect(activationSearch).toHaveFocus());
+ await userEvent.type(activationSearch, 'Grace');
+ await waitFor(() => expect(activationSearch).toHaveValue('Grace'));
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() =>
+ expect(canvas.getByLabelText('Assignee')).toHaveTextContent(
+ 'Assignee: Grace Hopper',
+ ),
+ );
+ await waitFor(() =>
+ expect(trigger).toHaveAttribute('aria-expanded', 'false'),
+ );
await dropdownSelectionGroupsTest({ canvasElement });
expect(errorHandler).not.toHaveBeenCalled();
};
diff --git a/packages/twenty-ui/.size-limit.json b/packages/twenty-ui/.size-limit.json
index 4d6fd482be5..155f70b8ef8 100644
--- a/packages/twenty-ui/.size-limit.json
+++ b/packages/twenty-ui/.size-limit.json
@@ -13,7 +13,7 @@
{
"name": "components",
"path": "dist/components.mjs",
- "limit": "160 kB"
+ "limit": "161 kB"
},
{
"name": "components/code-editor",
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.search.stories.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.search.stories.tsx
new file mode 100644
index 00000000000..938cef590d3
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.search.stories.tsx
@@ -0,0 +1,328 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import {
+ expect,
+ fireEvent,
+ fn,
+ userEvent,
+ waitFor,
+ within,
+} from 'storybook/test';
+
+import { ComponentDecorator } from '@ui/testing';
+import { Button } from '@ui/primitives/input/Button/Button';
+
+import { Dropdown } from '../Dropdown';
+import { type DropdownRootProps } from '../types/DropdownRootProps';
+import { createStoryState } from './createStoryState';
+import { DROPDOWN_STORY_A11Y_PARAMETERS } from './dropdownStoryA11yParameters';
+
+const PEOPLE = ['Ada Lovelace', 'Grace Hopper'];
+const POPUP_OPEN_TIMEOUT = 5000;
+const query = createStoryState('');
+const people = createStoryState(PEOPLE);
+const isAdaDisabled = createStoryState(false);
+const isFirstGroupDisabled = createStoryState(false);
+const onSelect = fn();
+const onInvite = fn();
+const onSearchBlur = fn();
+
+const SearchActivationExample = ({
+ filterResults = false,
+ onInteractOutside,
+}: {
+ filterResults?: boolean;
+} & Pick<DropdownRootProps, 'onInteractOutside'>) => {
+ const search = query.useValue();
+ const orderedPeople = people.useValue();
+ const isAdaDisabledValue = isAdaDisabled.useValue();
+ const isFirstGroupDisabledValue = isFirstGroupDisabled.useValue();
+ const results = filterResults
+ ? orderedPeople.filter((person) =>
+ person.toLowerCase().includes(search.toLowerCase()),
+ )
+ : orderedPeople;
+
+ return (
+ <Dropdown.Root type="picker" onInteractOutside={onInteractOutside}>
+ <Dropdown.Trigger>Reviewers</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Choose reviewers">
+ <Dropdown.Search
+ aria-label="Search reviewers"
+ value={search}
+ onValueChange={query.set}
+ onBlur={onSearchBlur}
+ />
+ <Dropdown.ActionItem onClick={onInvite}>
+ Invite reviewer
+ </Dropdown.ActionItem>
+ <Dropdown.SelectionGroup
+ id="people"
+ aria-label="People"
+ defaultValue="Grace Hopper"
+ closeOnSelect={false}
+ onValueChange={onSelect}
+ >
+ {results.map((person) => (
+ <Dropdown.OptionItem
+ key={person}
+ value={person}
+ disabled={
+ isFirstGroupDisabledValue ||
+ (isAdaDisabledValue && person === 'Ada Lovelace')
+ }
+ >
+ {person}
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.SelectionGroup>
+ <Dropdown.SelectionGroup
+ id="other-reviewers"
+ aria-label="Other reviewers"
+ closeOnSelect={false}
+ onValueChange={onSelect}
+ >
+ <Dropdown.OptionItem value="Margaret Hamilton">
+ Margaret Hamilton
+ </Dropdown.OptionItem>
+ </Dropdown.SelectionGroup>
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
+};
+
+const openPicker = async (canvasElement: HTMLElement) => {
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Reviewers' }),
+ );
+ const popup = await within(canvasElement.ownerDocument.body).findByRole(
+ 'dialog',
+ { name: 'Choose reviewers' },
+ );
+
+ await waitFor(() => expect(popup).toBeVisible(), {
+ timeout: POPUP_OPEN_TIMEOUT,
+ });
+ const search = within(popup).getByRole('searchbox', {
+ name: 'Search reviewers',
+ });
+
+ await waitFor(() => expect(search).toHaveFocus());
+
+ return { popup, search };
+};
+
+const meta: Meta = {
+ id: 'ui-components-dropdown-interactions-search',
+ title: 'UI/Components/Navigation/Dropdown/Interactions/Search',
+ tags: ['!autodocs'],
+ decorators: [ComponentDecorator],
+ parameters: { a11y: DROPDOWN_STORY_A11Y_PARAMETERS },
+ beforeEach: () => {
+ query.set('');
+ people.set(PEOPLE);
+ isAdaDisabled.set(false);
+ isFirstGroupDisabled.set(false);
+ onSelect.mockClear();
+ onInvite.mockClear();
+ onSearchBlur.mockClear();
+ },
+};
+
+export default meta;
+type Story = StoryObj;
+
+export const PreviewFollowsSearchFocus: Story = {
+ render: () => <SearchActivationExample />,
+ play: async ({ canvasElement }) => {
+ const { popup, search } = await openPicker(canvasElement);
+ const picker = within(popup);
+ const ada = picker.getByRole('option', { name: 'Ada Lovelace' });
+ const grace = picker.getByRole('option', { name: 'Grace Hopper' });
+ const invite = picker.getByRole('button', { name: 'Invite reviewer' });
+
+ await userEvent.type(search, 'a');
+ await waitFor(() =>
+ expect(search).toHaveAttribute('aria-activedescendant', ada.id),
+ );
+ await userEvent.keyboard('{ArrowDown}');
+
+ expect(invite).toHaveFocus();
+ expect(search).not.toHaveAttribute('aria-activedescendant');
+ expect(ada).not.toHaveAttribute('data-highlighted');
+ expect(onSelect).not.toHaveBeenCalled();
+
+ people.set(['Grace Hopper', 'Ada Lovelace']);
+ isAdaDisabled.set(true);
+ await waitFor(() => expect(ada).toBeDisabled());
+ expect(invite).toHaveFocus();
+ expect(search).not.toHaveAttribute('aria-activedescendant');
+ expect(grace).not.toHaveAttribute('data-highlighted');
+
+ await userEvent.keyboard('{ArrowDown}');
+ expect(grace).toHaveFocus();
+ expect(search).not.toHaveAttribute('aria-activedescendant');
+ await userEvent.keyboard('{ArrowUp}{ArrowUp}');
+
+ expect(search).toHaveFocus();
+ await waitFor(() =>
+ expect(search).toHaveAttribute('aria-activedescendant', grace.id),
+ );
+ expect(grace).toHaveAttribute('data-highlighted');
+ expect(onSelect).not.toHaveBeenCalled();
+ await userEvent.keyboard('{Escape}');
+ },
+};
+
+export const PreviewClearsWhenFocusLeavesOpenPopup: Story = {
+ render: () => (
+ <>
+ <SearchActivationExample
+ onInteractOutside={(event) => event.preventDefault()}
+ />
+ <Button>Outside</Button>
+ </>
+ ),
+ play: async ({ canvasElement }) => {
+ const { popup, search } = await openPicker(canvasElement);
+ const picker = within(popup);
+ const ada = picker.getByRole('option', { name: 'Ada Lovelace' });
+ const grace = picker.getByRole('option', { name: 'Grace Hopper' });
+ const outside = within(canvasElement).getByRole('button', {
+ name: 'Outside',
+ });
+
+ await userEvent.type(search, 'a');
+ await waitFor(() =>
+ expect(search).toHaveAttribute('aria-activedescendant', ada.id),
+ );
+ await userEvent.click(outside);
+
+ expect(outside).toHaveFocus();
+ expect(popup).toBeVisible();
+ expect(onSearchBlur).toHaveBeenCalledOnce();
+ await waitFor(() =>
+ expect(search).not.toHaveAttribute('aria-activedescendant'),
+ );
+ expect(ada).not.toHaveAttribute('data-highlighted');
+
+ people.set(['Grace Hopper', 'Ada Lovelace']);
+ await waitFor(() => expect(picker.getAllByRole('option')[0]).toBe(grace));
+ expect(search).not.toHaveAttribute('aria-activedescendant');
+ expect(grace).not.toHaveAttribute('data-highlighted');
+
+ await userEvent.click(search);
+ await waitFor(() =>
+ expect(search).toHaveAttribute('aria-activedescendant', grace.id),
+ );
+ await userEvent.keyboard('{Escape}');
+ },
+};
+
+export const EnterFindsEligibleResultAcrossGroups: Story = {
+ render: () => <SearchActivationExample filterResults />,
+ play: async ({ canvasElement }) => {
+ isFirstGroupDisabled.set(true);
+ const { popup, search } = await openPicker(canvasElement);
+ const picker = within(popup);
+ const ada = picker.getByRole('option', { name: 'Ada Lovelace' });
+ const margaret = picker.getByRole('option', { name: 'Margaret Hamilton' });
+
+ await userEvent.type(search, 'a');
+ await waitFor(() =>
+ expect(search).toHaveAttribute('aria-activedescendant', margaret.id),
+ );
+ expect(ada).toBeDisabled();
+ expect(picker.getByRole('option', { name: 'Grace Hopper' })).toBeDisabled();
+ await userEvent.clear(search);
+ await userEvent.type(search, 'margaret');
+ expect(
+ picker.queryByRole('option', { name: 'Grace Hopper' }),
+ ).not.toBeInTheDocument();
+ expect(
+ picker.queryByRole('option', { name: 'Ada Lovelace' }),
+ ).not.toBeInTheDocument();
+ expect(search).toHaveAttribute('aria-activedescendant', margaret.id);
+ await userEvent.keyboard('{Enter}');
+
+ expect(onSelect).toHaveBeenCalledOnce();
+ expect(onSelect.mock.calls[0]?.[0]).toBe('Margaret Hamilton');
+ expect(margaret).toHaveAttribute('aria-selected', 'true');
+ expect(onInvite).not.toHaveBeenCalled();
+ expect(search).toHaveFocus();
+ await userEvent.keyboard('{Escape}');
+ },
+};
+
+export const WhitespaceDoesNotActivate: Story = {
+ render: () => <SearchActivationExample />,
+ play: async ({ canvasElement }) => {
+ const { popup, search } = await openPicker(canvasElement);
+
+ await userEvent.type(search, ' ');
+ expect(search).not.toHaveAttribute('aria-activedescendant');
+ await userEvent.keyboard('{Enter}');
+
+ expect(onSelect).not.toHaveBeenCalled();
+ expect(onInvite).not.toHaveBeenCalled();
+ expect(search).toHaveFocus();
+ expect(popup).toBeVisible();
+ await userEvent.keyboard('{Escape}');
+ },
+};
+
+export const CompositionKeepsSearchFocus: Story = {
+ render: () => <SearchActivationExample />,
+ play: async ({ canvasElement }) => {
+ const { popup, search } = await openPicker(canvasElement);
+
+ await userEvent.type(search, 'ada');
+ await fireEvent.compositionStart(search);
+ await fireEvent.keyDown(search, { key: 'Enter', isComposing: true });
+ await fireEvent.keyDown(search, { key: 'ArrowDown', isComposing: true });
+
+ expect(search).toHaveFocus();
+ expect(onSelect).not.toHaveBeenCalled();
+ expect(onInvite).not.toHaveBeenCalled();
+
+ await fireEvent.compositionEnd(search);
+ await fireEvent.keyDown(search, { key: 'Enter', keyCode: 229 });
+ await fireEvent.keyDown(search, { key: 'ArrowDown', keyCode: 229 });
+
+ expect(search).toHaveFocus();
+ expect(onSelect).not.toHaveBeenCalled();
+ await userEvent.keyboard('{Enter}');
+
+ expect(onSelect).toHaveBeenCalledOnce();
+ expect(onSelect.mock.calls[0]?.[0]).toBe('Ada Lovelace');
+ expect(
+ within(popup).getByRole('option', { name: 'Ada Lovelace' }),
+ ).toHaveAttribute('aria-selected', 'true');
+ await userEvent.keyboard('{Escape}');
+ },
+};
+
+export const ControlledQueryUpdatesPreview: Story = {
+ render: () => <SearchActivationExample />,
+ play: async ({ canvasElement }) => {
+ const { popup, search } = await openPicker(canvasElement);
+ const ada = within(popup).getByRole('option', { name: 'Ada Lovelace' });
+
+ query.set('reviewer');
+ await waitFor(() => expect(search).toHaveValue('reviewer'));
+ await waitFor(() =>
+ expect(search).toHaveAttribute('aria-activedescendant', ada.id),
+ );
+ expect(within(popup).getByRole('option', { name: 'Ada Lovelace' })).toBe(
+ ada,
+ );
+
+ query.set('');
+ await waitFor(() => expect(search).toHaveValue(''));
+ await waitFor(() =>
+ expect(search).not.toHaveAttribute('aria-activedescendant'),
+ );
+ expect(ada).not.toHaveAttribute('data-highlighted');
+ expect(onSelect).not.toHaveBeenCalled();
+ await userEvent.keyboard('{Escape}');
+ },
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx
index c28760ab2d4..721ab22172e 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx
@@ -112,6 +112,9 @@ export const DropdownContent = ({
}}
onFocus={(event) => {
onFocus?.(event);
+ setSearchTargetId(
+ getDropdownSearchTarget(event.currentTarget)?.id,
+ );
const { target } = event;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearch.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearch.tsx
index 353500ba63e..07b3b23f804 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearch.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearch.tsx
@@ -1,16 +1,25 @@
+import { useMergedRefs } from '@base-ui/utils/useMergedRefs';
+import { useRef } from 'react';
+
import { Input } from '@ui/primitives/input/Input/Input';
import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
import styles from '../Dropdown.module.scss';
import { type DropdownSearchProps } from '../types/DropdownSearchProps';
+import { DropdownSearchEffect } from './DropdownSearchEffect';
import { useDropdownContext } from './useDropdownContext';
export const DropdownSearch = ({
onValueChange,
+ onBlur,
className,
+ value,
+ ref,
...props
}: DropdownSearchProps) => {
- const { searchTargetId } = useDropdownContext();
+ const { searchTargetId, setSearchTargetId } = useDropdownContext();
+ const searchRef = useRef<HTMLInputElement>(null);
+ const mergedRef = useMergedRefs(searchRef, ref);
return (
<div className={styles.searchContainer}>
@@ -19,10 +28,17 @@ export const DropdownSearch = ({
autoComplete="off"
aria-activedescendant={searchTargetId}
{...props}
+ ref={mergedRef}
+ value={value}
data-dropdown-search=""
className={mergeClassNames(styles.search, className)}
onValueChange={(value) => onValueChange?.(value)}
+ onBlur={(event) => {
+ setSearchTargetId(undefined);
+ onBlur?.(event);
+ }}
/>
+ <DropdownSearchEffect searchRef={searchRef} value={value} />
</div>
);
};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearchEffect.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearchEffect.tsx
new file mode 100644
index 00000000000..6c46c3ec876
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearchEffect.tsx
@@ -0,0 +1,31 @@
+import { useLayoutEffect, type RefObject } from 'react';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type DropdownSearchProps } from '../types/DropdownSearchProps';
+import { getDropdownSearchTarget } from './getDropdownSearchTarget';
+import { useDropdownContext } from './useDropdownContext';
+
+type DropdownSearchEffectProps = {
+ searchRef: RefObject<HTMLInputElement | null>;
+ value: DropdownSearchProps['value'];
+};
+
+export const DropdownSearchEffect = ({
+ searchRef,
+ value,
+}: DropdownSearchEffectProps) => {
+ const { setSearchTargetId } = useDropdownContext();
+
+ useLayoutEffect(() => {
+ const content = searchRef.current?.closest<HTMLElement>(
+ '[data-dropdown-content]',
+ );
+
+ if (isDefined(content)) {
+ setSearchTargetId(getDropdownSearchTarget(content)?.id);
+ }
+ }, [searchRef, value, setSearchTargetId]);
+
+ return null;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearchTarget.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearchTarget.ts
index a3aa30ad8aa..6f7b3baccd7 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearchTarget.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearchTarget.ts
@@ -12,7 +12,11 @@ export const getDropdownSearchTarget = (content: HTMLElement) => {
const search = getDropdownSearch(content);
- if (!isDefined(search) || !isNonEmptyString(search.value.trim())) {
+ if (
+ !isDefined(search) ||
+ search !== content.ownerDocument.activeElement ||
+ !isNonEmptyString(search.value.trim())
+ ) {
return undefined;
}
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts
index bf7250dd843..1dcbc497f3b 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts
@@ -16,6 +16,7 @@ import { useDropdownContext } from './useDropdownContext';
import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';
const TYPEAHEAD_RESET_DELAY = 500;
+const IME_PROCESS_KEY_CODE = 229;
export const useDropdownKeyboardNavigation = () => {
const { type, isSubmenu, setOpen, closeTree, tabForwardOutOfTree } =
@@ -24,7 +25,11 @@ export const useDropdownKeyboardNavigation = () => {
const [typeahead, setTypeahead] = useState({ text: '', timestamp: 0 });
return (event: KeyboardEvent<HTMLDivElement>) => {
- if (event.defaultPrevented) {
+ if (
+ event.defaultPrevented ||
+ event.nativeEvent.isComposing ||
+ event.nativeEvent.keyCode === IME_PROCESS_KEY_CODE
+ ) {
return;
}
@@ -100,7 +105,7 @@ export const useDropdownKeyboardNavigation = () => {
const items = getDropdownRows(content);
const searchTarget =
- isSearch && event.key === 'Enter' && !event.nativeEvent.isComposing
+ isSearch && event.key === 'Enter'
? getDropdownSearchTarget(content)
: undefined;