Skip to content

The open alternative to Salesforce, designed for AI.

Centralize Dropdown page focus (#27951)

Raphaël Bosi1705148e6bc6
diff --git a/packages/twenty-docs/ui/components/navigation/dropdown.mdx b/packages/twenty-docs/ui/components/navigation/dropdown.mdx
index 47e32f5b043..263dbdbd8a6 100644
--- a/packages/twenty-docs/ui/components/navigation/dropdown.mdx
+++ b/packages/twenty-docs/ui/components/navigation/dropdown.mdx
@@ -178,6 +178,12 @@ export const IconGrid = () => {
};
```
+## Keyboard focus
+
+In `menu` and `picker` pages, the rows form a single Tab stop. Arrow keys move focus across sections, actions and options, and Home and End move to the first and last enabled rows unless the search field has focus. Moving focus never selects an option; Enter or Space activates the focused row. Tabbing back to the rows returns to the last focused row, or to the first enabled row once that row is gone. Search, `Back` beside a search, header buttons and other controls inside the popup keep their own Tab stops.
+
+Tab and Shift+Tab close a `menu`, along with its parent menus when focus is in a submenu. In a `picker`, Tab moves through the popup's controls and closes the popup when focus leaves it. A `panel` keeps the native Tab order of its controls.
+
## Pages and submenus
Use `Page` for navigation that replaces the contents of the same popup. Wrap the first page in `Page id="root"`, or choose another initial page with `defaultPage`. Set `page` on an action to navigate without closing. `Back` returns to the previous page and restores focus to its invoking row. Closing the dropdown resets its page history.
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 2b39270c47c..78d17fd308c 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. Search, broader keyboard navigation and 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, 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.
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.
@@ -84,7 +84,7 @@ effect within the interaction timeout.
| `twenty-ui-dialog` | SDK `openCommandConfirmationModal` confirmation request |
| `twenty-ui-select` | Select |
| `twenty-ui-portals` | Body portal callbacks, removal, nearby overflow, menu placement and confinement |
-| `twenty-ui-dropdown` | Dropdown (controlled opening, action refs and callbacks, disabled actions, page navigation and selection) |
+| `twenty-ui-dropdown` | Dropdown (controlled opening, action refs and callbacks, disabled actions, page navigation, picker Tab stop and selection) |
| `twenty-ui-toast` | Toast |
| `twenty-ui-switch` | Switch (interaction coverage in addition to the original input gallery) |
| `twenty-ui-checkbox` | Checkbox |
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 51f4fcab056..a15767edce8 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
@@ -14,7 +14,11 @@ const DropdownExample = () => {
const [query, setQuery] = useState('');
const [selection, setSelection] = useState('Unassigned');
const [actionCount, setActionCount] = useState(0);
- const matchingAssignees = ASSIGNEES.filter((assignee) =>
+ const [isLastAssigneeFirst, setIsLastAssigneeFirst] = useState(false);
+ const rankedAssignees = isLastAssigneeFirst
+ ? [...ASSIGNEES].reverse()
+ : ASSIGNEES;
+ const matchingAssignees = rankedAssignees.filter((assignee) =>
assignee.toLowerCase().includes(query.toLowerCase()),
);
@@ -78,6 +82,12 @@ const DropdownExample = () => {
<Dropdown.ActionItem onClick={() => setSelection('New person')}>
Create person
</Dropdown.ActionItem>
+ <Dropdown.ActionItem
+ closeOnClick={false}
+ onClick={() => setIsLastAssigneeFirst(true)}
+ >
+ Rank last first
+ </Dropdown.ActionItem>
</Dropdown.Section>
</Dropdown.Page>
</Dropdown.Content>
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createOverlayOpenTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createOverlayOpenTest.ts
index 51170818cda..9f9a2ab89df 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createOverlayOpenTest.ts
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createOverlayOpenTest.ts
@@ -3,6 +3,7 @@ import { isDefined } from 'twenty-shared/utils';
import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';
import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';
+import { INTERACTION_TIMEOUT } from '@/__stories__/shared/test-utils/timeouts';
import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';
type CreateOverlayOpenTestOptions = {
@@ -40,8 +41,9 @@ export const createOverlayOpenTest =
expect(canvas.getByRole('status')).toHaveTextContent(expectedOpenStatus);
}
- await waitFor(() =>
- expect(page.getByText(popupText, { exact: false })).toBeVisible(),
+ await waitFor(
+ () => expect(page.getByText(popupText, { exact: false })).toBeVisible(),
+ { timeout: INTERACTION_TIMEOUT },
);
expect(errorHandler).not.toHaveBeenCalled();
};
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 31fb36c963c..67da8d60e7a 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
@@ -2,6 +2,7 @@ import { expect, userEvent, waitFor, within } from 'storybook/test';
import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';
import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';
+import { INTERACTION_TIMEOUT } from '@/__stories__/shared/test-utils/timeouts';
import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';
export const dropdownTest: TwentyUiGalleryPlayFunction = async ({
@@ -17,7 +18,9 @@ export const dropdownTest: TwentyUiGalleryPlayFunction = async ({
const assignment = await page.findByRole('menuitem', {
name: /^Assign person/,
});
- await waitFor(() => expect(assignment).toBeVisible());
+ await waitFor(() => expect(assignment).toBeVisible(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
const disabledItem = page.getByRole('menuitem', { name: 'Archive assignee' });
expect(disabledItem).toBeDisabled();
await userEvent.click(disabledItem);
@@ -43,8 +46,47 @@ export const dropdownTest: TwentyUiGalleryPlayFunction = async ({
await userEvent.click(
await page.findByRole('menuitem', { name: /^Assign person/ }),
);
+ const search = await page.findByRole('searchbox', { name: 'Search people' });
+ await waitFor(() => expect(search).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ const ada = page.getByRole('button', { name: /^Ada Lovelace/ });
+ const grace = page.getByRole('button', { name: /^Grace Hopper/ });
+ const createPerson = page.getByRole('button', { name: 'Create person' });
+ await waitFor(() => expect(ada).toHaveAttribute('tabindex', '0'));
+ expect(grace).toHaveAttribute('tabindex', '-1');
+ expect(createPerson).toHaveAttribute('tabindex', '-1');
+ await userEvent.tab();
+ await waitFor(() => expect(ada).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ await userEvent.keyboard('{ArrowDown}');
+ await waitFor(() => expect(grace).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ await userEvent.tab({ shift: true });
+ await waitFor(() => expect(search).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ await waitFor(() => expect(grace).toHaveAttribute('tabindex', '0'));
+ await userEvent.tab();
+ await waitFor(() => expect(grace).toHaveFocus(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ 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(grace).toHaveAttribute('data-highlighted'), {
+ timeout: INTERACTION_TIMEOUT,
+ });
+ expect(search).toHaveAttribute('aria-activedescendant', grace.id);
+ expect(ada).not.toHaveAttribute('data-highlighted');
const option = await page.findByText('Ada Lovelace');
- await waitFor(() => expect(option).toBeVisible());
+ await waitFor(() => expect(option).toBeVisible(), {
+ timeout: INTERACTION_TIMEOUT,
+ });
await userEvent.click(option);
await waitFor(() =>
expect(canvas.getByLabelText('Assignee')).toHaveTextContent(
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.dismissal.stories.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.dismissal.stories.tsx
index 9114e29d1c8..05122a9a6fc 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.dismissal.stories.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.dismissal.stories.tsx
@@ -259,6 +259,49 @@ export const TabAway: Story = {
},
};
+export const ShiftTabAway: Story = {
+ play: async ({ canvasElement, args }) => {
+ const body = within(canvasElement.ownerDocument.body);
+ const trigger = await openRecordActions(canvasElement);
+
+ await waitFor(() =>
+ expect(body.getByRole('menuitem', { name: 'Duplicate' })).toHaveFocus(),
+ );
+ await userEvent.tab({ shift: true });
+
+ await waitFor(() =>
+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ await waitFor(() => expect(trigger).toHaveFocus());
+ expect(args.onInteractOutside).toHaveBeenCalledOnce();
+ expect(args.onInteractOutside).toHaveBeenCalledWith(
+ expect.objectContaining({ target: null, type: 'keydown' }),
+ );
+ },
+};
+
+export const ShiftTabAwayPrevented: Story = {
+ args: { onInteractOutside: fn(preventDismiss) },
+ play: async ({ canvasElement, args }) => {
+ const body = within(canvasElement.ownerDocument.body);
+ const trigger = await openRecordActions(canvasElement);
+ const duplicate = body.getByRole('menuitem', { name: 'Duplicate' });
+
+ await waitFor(() => expect(duplicate).toHaveFocus());
+ await userEvent.tab({ shift: true });
+
+ expect(args.onInteractOutside).toHaveBeenCalledOnce();
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
+ expect(duplicate).toHaveFocus();
+
+ await userEvent.keyboard('{Escape}');
+
+ await waitFor(() =>
+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ },
+};
+
export const ShiftTabAwayKeepsNextClick: Story = {
render: (args) => <RecordDetailsPanel {...args} />,
play: async ({ canvasElement, args }) => {
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.pages.stories.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.pages.stories.tsx
index e2efa8ec2a7..b696b8c627b 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.pages.stories.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.pages.stories.tsx
@@ -11,7 +11,7 @@ import { type DropdownType } from '../types/DropdownType';
import { createStoryState } from './createStoryState';
import { DROPDOWN_STORY_A11Y_PARAMETERS } from './dropdownStoryA11yParameters';
-type FilterAction = { label: string; page?: string };
+type FilterAction = { label: string; page?: string; id?: string };
const DEFAULT_FILTER_ACTIONS: FilterAction[] = [
{ label: 'People', page: 'people' },
@@ -34,8 +34,8 @@ const FilterPages = ({ keepMounted }: { keepMounted?: boolean }) => {
<Dropdown.Trigger>Filters</Dropdown.Trigger>
<Dropdown.Content aria-label="Filters" keepMounted={keepMounted}>
<Dropdown.Page id="root">
- {filterActions.useValue().map(({ label, page }) => (
- <Dropdown.ActionItem key={label} page={page}>
+ {filterActions.useValue().map(({ label, page, id }) => (
+ <Dropdown.ActionItem key={label} id={id} page={page}>
{label}
</Dropdown.ActionItem>
))}
@@ -50,6 +50,9 @@ const FilterPages = ({ keepMounted }: { keepMounted?: boolean }) => {
<Dropdown.OptionItem selected={false}>
Ada Lovelace
</Dropdown.OptionItem>
+ <Dropdown.OptionItem selected={false}>
+ Grace Hopper
+ </Dropdown.OptionItem>
</Dropdown.Page>
</Dropdown.Content>
</Dropdown.Root>
@@ -244,6 +247,40 @@ export const SelectionReturnsToPreviousPage: Story = {
},
};
+export const BackKeepsItsTabStopBesideSearch: Story = {
+ render: () => <FilterPages />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await openFilters(canvasElement);
+ await userEvent.click(
+ await body.findByRole('menuitem', { name: 'People' }),
+ );
+ const search = await body.findByRole('searchbox', {
+ name: 'Search people',
+ });
+
+ const ada = body.getByRole('button', { name: 'Ada Lovelace' });
+ const grace = body.getByRole('button', { name: 'Grace Hopper' });
+
+ await waitFor(() => expect(search).toHaveFocus());
+ await userEvent.tab();
+ expect(ada).toHaveFocus();
+ await userEvent.keyboard('{ArrowDown}');
+ expect(grace).toHaveFocus();
+ await userEvent.tab({ shift: true });
+ expect(search).toHaveFocus();
+ await userEvent.tab({ shift: true });
+ expect(body.getByRole('button', { name: 'Back to filters' })).toHaveFocus();
+ await userEvent.tab();
+ expect(search).toHaveFocus();
+ await userEvent.tab();
+ expect(grace).toHaveFocus();
+ await userEvent.keyboard('{ArrowUp}{ArrowUp}');
+ expect(search).toHaveFocus();
+ },
+};
+
export const PageWithoutSearchFocusesFirstOption: Story = {
render: () => (
<Dropdown.Root type="picker">
@@ -638,3 +675,37 @@ export const MovedAndRenamedDestination: Story = {
);
},
};
+
+export const ConsumerIdRestoresTrigger: Story = {
+ render: () => <FilterPages />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ filterActions.set([
+ { label: 'People', page: 'people', id: 'people-filter' },
+ { label: 'Clear filters' },
+ ]);
+ await openFilters(canvasElement);
+ await userEvent.click(
+ await body.findByRole('menuitem', { name: 'People' }),
+ );
+ await body.findByRole('searchbox', { name: 'Search people' });
+
+ filterActions.set([
+ { label: 'Clear filters' },
+ { label: 'Recent people', page: 'people' },
+ { label: 'Everyone', page: 'people', id: 'people-filter' },
+ ]);
+ await userEvent.click(
+ body.getByRole('button', { name: 'Back to filters' }),
+ );
+
+ await waitFor(() =>
+ expect(body.getByRole('menuitem', { name: 'Everyone' })).toHaveFocus(),
+ );
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ },
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.picker.stories.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.picker.stories.tsx
index 32d64e094f0..2bd97c4c1d4 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.picker.stories.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.picker.stories.tsx
@@ -4,13 +4,16 @@ import { useState } from 'react';
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
import { Button } from '@ui/primitives/input/Button/Button';
+import { isDefined } from '@ui/utilities/utils/isDefined';
import { ComponentDecorator } from '@ui/testing';
import { Dropdown } from '../Dropdown';
+import { createStoryState } from './createStoryState';
import { DROPDOWN_STORY_A11Y_PARAMETERS } from './dropdownStoryA11yParameters';
const PEOPLE = ['Ada Lovelace', 'Grace Hopper', 'Margaret Hamilton'];
+const WORKSPACES = ['Acme', 'Globex', 'Initech'];
const onCreatePerson = fn();
const onEditItem = fn();
@@ -21,6 +24,10 @@ const onSelectDisabledOption = fn();
const onOpenChange = fn();
const onSearchChange = fn();
+const reviewerIdRevision = createStoryState(0);
+const disabledReviewerIndex = createStoryState<number | undefined>(undefined);
+const rankedPeople = createStoryState(PEOPLE);
+
const SearchablePicker = ({
multiple = false,
initialSearch = '',
@@ -72,39 +79,141 @@ const SearchablePicker = ({
);
};
-const openAssignees = async (canvasElement: HTMLElement) => {
- await userEvent.click(
- within(canvasElement).getByRole('button', { name: 'Assignees' }),
+const OwnerPicker = () => {
+ const [search, setSearch] = useState('');
+ const results = PEOPLE.filter((person) =>
+ person.toLowerCase().includes(search.toLowerCase()),
);
- const search = await within(canvasElement.ownerDocument.body).findByRole(
- 'searchbox',
- { name: 'Search people' },
+
+ return (
+ <Dropdown.Root type="picker">
+ <Dropdown.Trigger>Owner</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Choose owner">
+ <Dropdown.Search
+ aria-label="Search people"
+ value={search}
+ onValueChange={setSearch}
+ />
+ <Dropdown.Section label="Actions">
+ <Dropdown.ActionItem onClick={onCreatePerson}>
+ Create person
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ <Dropdown.Section label="People">
+ {results.map((person) => (
+ <Dropdown.OptionItem
+ key={person}
+ selected={false}
+ onSelect={() => onSelectPerson(person)}
+ >
+ {person}
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.Section>
+ <Button>Manage people</Button>
+ </Dropdown.Content>
+ </Dropdown.Root>
);
+};
- await waitFor(() => expect(search).toHaveFocus());
- await waitFor(() =>
- expect(
- within(canvasElement.ownerDocument.body).getByRole('dialog'),
- ).toBeVisible(),
+const ReviewerPicker = () => {
+ const revision = reviewerIdRevision.useValue();
+ const disabledIndex = disabledReviewerIndex.useValue();
+
+ return (
+ <Dropdown.Root type="picker">
+ <Dropdown.Trigger>Reviewers</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Choose reviewers">
+ {PEOPLE.map((person, index) => (
+ <Dropdown.OptionItem
+ key={person}
+ id={`reviewer-${index}-${revision}`}
+ selected={false}
+ disabled={index === disabledIndex}
+ >
+ {person}
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.Content>
+ </Dropdown.Root>
);
+};
- return search;
+const RankedPicker = () => {
+ const [search, setSearch] = useState('');
+ const results = rankedPeople
+ .useValue()
+ .filter((person) => person.toLowerCase().includes(search.toLowerCase()));
+
+ return (
+ <Dropdown.Root type="picker">
+ <Dropdown.Trigger>Ranked people</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Choose a ranked person">
+ <Dropdown.Search
+ aria-label="Search people"
+ value={search}
+ onValueChange={setSearch}
+ />
+ {results.map((person) => (
+ <Dropdown.OptionItem key={person} selected={false}>
+ {person}
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.Content>
+ </Dropdown.Root>
+ );
};
-const openFields = async (canvasElement: HTMLElement) => {
- await userEvent.click(
- within(canvasElement).getByRole('button', { name: 'Fields' }),
+const WorkspaceLinkPicker = () => {
+ const [search, setSearch] = useState('');
+ const results = WORKSPACES.filter((workspace) =>
+ workspace.toLowerCase().includes(search.toLowerCase()),
+ );
+
+ return (
+ <Dropdown.Root type="picker">
+ <Dropdown.Trigger>Workspaces</Dropdown.Trigger>
+ <Dropdown.Content aria-label="Switch workspace">
+ <Dropdown.Search
+ aria-label="Search workspaces"
+ value={search}
+ onValueChange={setSearch}
+ />
+ {results.map((workspace) => (
+ <Dropdown.OptionItem
+ key={workspace}
+ render={
+ <a
+ id={`workspace-${workspace.toLowerCase()}`}
+ href={`mailto:${workspace.toLowerCase()}@example.com`}
+ aria-label={workspace}
+ />
+ }
+ >
+ {workspace}
+ </Dropdown.OptionItem>
+ ))}
+ </Dropdown.Content>
+ </Dropdown.Root>
);
- const search = await within(canvasElement.ownerDocument.body).findByRole(
- 'searchbox',
+};
+
+const openPicker = async ({
+ canvasElement,
+ triggerName,
+}: {
+ canvasElement: HTMLElement;
+ triggerName: string;
+}) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: triggerName }),
);
+ const search = await body.findByRole('searchbox');
await waitFor(() => expect(search).toHaveFocus());
- await waitFor(() =>
- expect(
- within(canvasElement.ownerDocument.body).getByRole('dialog'),
- ).toBeVisible(),
- );
+ await waitFor(() => expect(body.getByRole('dialog')).toBeVisible());
return search;
};
@@ -128,6 +237,10 @@ const meta: Meta = {
]) {
spy.mockClear();
}
+
+ reviewerIdRevision.set(0);
+ disabledReviewerIndex.set(undefined);
+ rankedPeople.set(PEOPLE);
},
};
@@ -137,7 +250,7 @@ type Story = StoryObj;
export const EnterWithEmptySearch: Story = {
render: () => <SearchablePicker />,
play: async ({ canvasElement }) => {
- await openAssignees(canvasElement);
+ await openPicker({ canvasElement, triggerName: 'Assignees' });
await userEvent.keyboard('{Enter}');
expect(onCreatePerson).not.toHaveBeenCalled();
@@ -148,7 +261,10 @@ export const EnterWithEmptySearch: Story = {
export const EnterWithMatchingSearch: Story = {
render: () => <SearchablePicker />,
play: async ({ canvasElement }) => {
- const search = await openAssignees(canvasElement);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Assignees',
+ });
await userEvent.type(search, 'grace');
await userEvent.keyboard('{Enter}');
@@ -163,7 +279,10 @@ export const HighlightFollowsSearch: Story = {
render: () => <SearchablePicker />,
play: async ({ canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
- const search = await openAssignees(canvasElement);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Assignees',
+ });
expect(search).not.toHaveAttribute('aria-activedescendant');
@@ -198,7 +317,10 @@ export const TypingRightAfterOpening: Story = {
play: async ({ canvasElement }) => {
const { userEvent: trustedUserEvent } = await import('vitest/browser');
const body = within(canvasElement.ownerDocument.body);
- const search = await openAssignees(canvasElement);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Assignees',
+ });
await trustedUserEvent.keyboard('gra');
@@ -223,7 +345,10 @@ export const BackspaceClearingSearch: Story = {
play: async ({ canvasElement }) => {
const { userEvent: trustedUserEvent } = await import('vitest/browser');
const body = within(canvasElement.ownerDocument.body);
- const search = await openAssignees(canvasElement);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Assignees',
+ });
const margaret = body.getByRole('button', { name: 'Margaret Hamilton' });
await waitFor(() => expect(margaret).toHaveAttribute('data-highlighted'));
@@ -245,7 +370,10 @@ export const HighlightFollowsTypedSearch: Story = {
play: async ({ canvasElement }) => {
const { userEvent: trustedUserEvent } = await import('vitest/browser');
const body = within(canvasElement.ownerDocument.body);
- const search = await openAssignees(canvasElement);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Assignees',
+ });
const ada = body.getByRole('button', { name: 'Ada Lovelace' });
await trustedUserEvent.keyboard('a');
@@ -293,7 +421,7 @@ export const FirstEnabledResult: Story = {
),
play: async ({ canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
- const search = await openFields(canvasElement);
+ const search = await openPicker({ canvasElement, triggerName: 'Fields' });
await userEvent.type(search, 'n');
await userEvent.keyboard('{Enter}');
@@ -316,7 +444,7 @@ export const EmptyResultsStayOpen: Story = {
),
play: async ({ canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
- const search = await openFields(canvasElement);
+ const search = await openPicker({ canvasElement, triggerName: 'Fields' });
await userEvent.type(search, 'x');
await userEvent.keyboard('{Enter}');
@@ -393,7 +521,7 @@ export const MultipleSelectionStaysOpen: Story = {
play: async ({ canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
- await openAssignees(canvasElement);
+ await openPicker({ canvasElement, triggerName: 'Assignees' });
const ada = body.getByRole('button', { name: 'Ada Lovelace' });
const grace = body.getByRole('button', { name: 'Grace Hopper' });
@@ -412,7 +540,7 @@ export const InlineActionClosesMultiplePicker: Story = {
play: async ({ canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
- await openAssignees(canvasElement);
+ await openPicker({ canvasElement, triggerName: 'Assignees' });
await userEvent.click(body.getByRole('button', { name: 'Create person' }));
expect(onCreatePerson).toHaveBeenCalledOnce();
await waitFor(() =>
@@ -425,7 +553,10 @@ export const EmptyResultsAnnounced: Story = {
render: () => <SearchablePicker />,
play: async ({ canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
- const search = await openAssignees(canvasElement);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Assignees',
+ });
await userEvent.type(search, 'unknown');
expect(body.getByRole('status')).toHaveTextContent('No people found');
@@ -491,7 +622,7 @@ export const OptionsWithoutSelectionState: Story = {
play: async ({ canvasElement }) => {
const body = within(canvasElement.ownerDocument.body);
- await openFields(canvasElement);
+ await openPicker({ canvasElement, triggerName: 'Fields' });
expect(body.getByRole('button', { name: 'Stage' })).not.toHaveAttribute(
'aria-pressed',
);
@@ -748,8 +879,12 @@ export const DisabledOptionsLeaveTabOrder: Story = {
'tabindex',
'-1',
);
- await userEvent.tab();
- expect(body.getByRole('button', { name: 'Notes' })).toHaveFocus();
+ await userEvent.keyboard('{ArrowDown}');
+ const notes = body.getByRole('button', { name: 'Notes' });
+
+ expect(notes).toHaveFocus();
+ expect(notes).toHaveAttribute('tabindex', '0');
+ expect(overview).toHaveAttribute('tabindex', '-1');
},
};
@@ -803,5 +938,258 @@ export const CommandWithTrailingAction: Story = {
await waitFor(() =>
expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Views' }),
+ );
+ const reopenedItem = await body.findByRole('button', {
+ name: 'Open overview',
+ });
+ await waitFor(() => expect(body.getByRole('dialog')).toBeVisible());
+ const row = reopenedItem.parentElement;
+
+ expect(row).toHaveAttribute('role', 'none');
+
+ if (!isDefined(row)) {
+ return;
+ }
+
+ await userEvent.click(row);
+ expect(onSelectOption).toHaveBeenCalledTimes(2);
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const RowsShareOneTabStop: Story = {
+ render: () => <OwnerPicker />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+ const search = await openPicker({ canvasElement, triggerName: 'Owner' });
+ const create = body.getByRole('button', { name: 'Create person' });
+ const ada = body.getByRole('button', { name: 'Ada Lovelace' });
+ const grace = body.getByRole('button', { name: 'Grace Hopper' });
+ const manage = body.getByRole('button', { name: 'Manage people' });
+
+ await waitFor(() => expect(create).toHaveAttribute('tabindex', '0'));
+ expect(ada).toHaveAttribute('tabindex', '-1');
+ expect(grace).toHaveAttribute('tabindex', '-1');
+
+ await userEvent.tab();
+ expect(create).toHaveFocus();
+ await userEvent.tab();
+ expect(manage).toHaveFocus();
+ await userEvent.tab({ shift: true });
+ expect(create).toHaveFocus();
+
+ await userEvent.keyboard('{ArrowDown}{ArrowDown}');
+ expect(grace).toHaveFocus();
+ expect(onSelectPerson).not.toHaveBeenCalled();
+ expect(onCreatePerson).not.toHaveBeenCalled();
+
+ await userEvent.tab({ shift: true });
+ expect(search).toHaveFocus();
+ await waitFor(() => expect(grace).toHaveAttribute('tabindex', '0'));
+ expect(create).toHaveAttribute('tabindex', '-1');
+ await userEvent.tab();
+ expect(grace).toHaveFocus();
+ expect(body.getByRole('dialog', { name: 'Choose owner' })).toBeVisible();
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const TabStopReturnsToFirstRow: Story = {
+ render: () => <OwnerPicker />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+ const search = await openPicker({ canvasElement, triggerName: 'Owner' });
+
+ await userEvent.keyboard('{ArrowDown}{ArrowDown}{ArrowDown}{ArrowDown}');
+ expect(
+ body.getByRole('button', { name: 'Margaret Hamilton' }),
+ ).toHaveFocus();
+ await userEvent.tab({ shift: true });
+ expect(search).toHaveFocus();
+ await userEvent.type(search, 'gr');
+ const grace = body.getByRole('button', { name: 'Grace Hopper' });
+
+ await waitFor(() => expect(grace).toHaveAttribute('data-highlighted'));
+ await userEvent.tab();
+ expect(body.getByRole('button', { name: 'Create person' })).toHaveFocus();
+ expect(onSelectPerson).not.toHaveBeenCalled();
+ expect(onCreatePerson).not.toHaveBeenCalled();
+ expect(body.getByRole('dialog', { name: 'Choose owner' })).toBeVisible();
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const TabLeavesPicker: Story = {
+ render: () => (
+ <>
+ <SearchablePicker />
+ <Button>Next control</Button>
+ </>
+ ),
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await openPicker({ canvasElement, triggerName: 'Assignees' });
+ await userEvent.tab();
+ expect(body.getByRole('button', { name: 'Create person' })).toHaveFocus();
+ await userEvent.tab();
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ await waitFor(() =>
+ expect(
+ within(canvasElement).getByRole('button', { name: 'Next control' }),
+ ).toHaveFocus(),
+ );
+ expect(onSelectPerson).not.toHaveBeenCalled();
+ expect(onCreatePerson).not.toHaveBeenCalled();
+ },
+};
+
+export const RowIdChangeKeepsOneTabStop: Story = {
+ render: () => <ReviewerPicker />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Reviewers' }),
+ );
+ const dialog = await body.findByRole('dialog', {
+ name: 'Choose reviewers',
+ });
+ const ada = within(dialog).getByRole('button', { name: 'Ada Lovelace' });
+ const grace = within(dialog).getByRole('button', { name: 'Grace Hopper' });
+ const getTabStops = () =>
+ within(dialog)
+ .getAllByRole('button')
+ .filter((row) => row.getAttribute('tabindex') === '0');
+
+ await waitFor(() => expect(ada).toHaveFocus());
+ await waitFor(() => expect(getTabStops()).toEqual([ada]));
+
+ reviewerIdRevision.set(1);
+
+ await waitFor(() => expect(grace).toHaveAttribute('id', 'reviewer-1-1'));
+ await waitFor(() => expect(getTabStops()).toEqual([ada]));
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const RenderElementIdsKeepOneTabStop: Story = {
+ render: () => <WorkspaceLinkPicker />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Workspaces',
+ });
+ const dialog = body.getByRole('dialog', { name: 'Switch workspace' });
+ const acme = within(dialog).getByRole('link', { name: 'Acme' });
+ const getTabStops = () =>
+ within(dialog)
+ .getAllByRole('link')
+ .filter((link) => link.getAttribute('tabindex') === '0');
+
+ expect(acme).toHaveAttribute('id', 'workspace-acme');
+ await waitFor(() => expect(getTabStops()).toEqual([acme]));
+
+ await userEvent.type(search, 'glo');
+ const globex = within(dialog).getByRole('link', { name: 'Globex' });
+
+ await waitFor(() => expect(globex).toHaveAttribute('data-highlighted'));
+ expect(search).toHaveAttribute('aria-activedescendant', 'workspace-globex');
+ expect(getTabStops()).toEqual([globex]);
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const HighlightAndTabStopFollowReorder: Story = {
+ render: () => <RankedPicker />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+ const search = await openPicker({
+ canvasElement,
+ triggerName: 'Ranked people',
+ });
+
+ await userEvent.type(search, 'a');
+ const ada = body.getByRole('button', { name: 'Ada Lovelace' });
+ const margaret = body.getByRole('button', { name: 'Margaret Hamilton' });
+
+ await waitFor(() => expect(ada).toHaveAttribute('data-highlighted'));
+ expect(ada).toHaveAttribute('tabindex', '0');
+
+ rankedPeople.set(['Margaret Hamilton', 'Ada Lovelace', 'Grace Hopper']);
+
+ await waitFor(() => expect(margaret).toHaveAttribute('data-highlighted'));
+ expect(body.getByRole('button', { name: 'Margaret Hamilton' })).toBe(
+ margaret,
+ );
+ expect(search).toHaveAttribute('aria-activedescendant', margaret.id);
+ expect(margaret).toHaveAttribute('tabindex', '0');
+ expect(ada).toHaveAttribute('tabindex', '-1');
+ await userEvent.keyboard('{ArrowDown}');
+ expect(margaret).toHaveFocus();
+ await userEvent.keyboard('{ArrowDown}');
+ expect(ada).toHaveFocus();
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
+ },
+};
+
+export const DisabledRowLeavesNavigationWhileOpen: Story = {
+ render: () => <ReviewerPicker />,
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ within(canvasElement).getByRole('button', { name: 'Reviewers' }),
+ );
+ const dialog = await body.findByRole('dialog', {
+ name: 'Choose reviewers',
+ });
+ const ada = within(dialog).getByRole('button', { name: 'Ada Lovelace' });
+ const grace = within(dialog).getByRole('button', { name: 'Grace Hopper' });
+ const margaret = within(dialog).getByRole('button', {
+ name: 'Margaret Hamilton',
+ });
+
+ await waitFor(() => expect(ada).toHaveFocus());
+
+ disabledReviewerIndex.set(1);
+
+ await waitFor(() => expect(grace).toBeDisabled());
+ expect(grace).toHaveAttribute('tabindex', '-1');
+ await userEvent.keyboard('{ArrowDown}');
+ expect(margaret).toHaveFocus();
+
+ disabledReviewerIndex.set(undefined);
+
+ await waitFor(() => expect(grace).toBeEnabled());
+ await userEvent.keyboard('{ArrowUp}');
+ expect(grace).toHaveFocus();
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() =>
+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),
+ );
},
};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.submenu.stories.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.submenu.stories.tsx
index 021a17a5a8b..f00f03aeeed 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.submenu.stories.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__stories__/Dropdown.submenu.stories.tsx
@@ -25,16 +25,31 @@ const ExportSubmenu = ({ direction }: { direction: 'ltr' | 'rtl' }) => (
</DirectionProvider>
);
+const ExportSubmenuWithNextControl = () => (
+ <>
+ <ExportSubmenu direction="ltr" />
+ <Button>Next control</Button>
+ </>
+);
+
+const focusExportTrigger = async (canvasElement: HTMLElement) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.tab();
+ await userEvent.keyboard('{ArrowDown}');
+ const trigger = await body.findByRole('menuitem', { name: 'Export' });
+
+ await waitFor(() => expect(trigger).toHaveFocus());
+
+ return trigger;
+};
+
const playHoverThenKeyboard =
({ forwardKey, dismissKey }: { forwardKey: string; dismissKey: string }) =>
async ({ canvasElement }: { canvasElement: HTMLElement }) => {
const body = within(canvasElement.ownerDocument.body);
+ const trigger = await focusExportTrigger(canvasElement);
- await userEvent.tab();
- await userEvent.keyboard('{ArrowDown}');
- const trigger = await body.findByRole('menuitem', { name: 'Export' });
-
- await waitFor(() => expect(trigger).toHaveFocus());
await userEvent.hover(trigger);
await body.findByRole('menu', { name: 'Export formats' });
expect(trigger).toHaveFocus();
@@ -173,3 +188,39 @@ export const DisabledSubmenuOwners: Story = {
);
},
};
+
+const playTabClosesMenuChain =
+ ({ shift }: { shift: boolean }) =>
+ async ({ canvasElement }: { canvasElement: HTMLElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const trigger = canvas.getByRole('button', { name: 'Record actions' });
+
+ await focusExportTrigger(canvasElement);
+ await userEvent.keyboard('{ArrowRight}');
+ const formats = await body.findByRole('menu', { name: 'Export formats' });
+
+ await waitFor(() => expect(formats).toBeVisible());
+ await waitFor(() =>
+ expect(body.getByRole('menuitem', { name: 'CSV' })).toHaveFocus(),
+ );
+ await userEvent.tab({ shift });
+ await waitFor(() =>
+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),
+ );
+ await waitFor(() =>
+ expect(
+ shift ? trigger : canvas.getByRole('button', { name: 'Next control' }),
+ ).toHaveFocus(),
+ );
+ };
+
+export const TabClosesMenuChain: Story = {
+ render: () => <ExportSubmenuWithNextControl />,
+ play: playTabClosesMenuChain({ shift: false }),
+};
+
+export const ShiftTabClosesMenuChain: Story = {
+ render: () => <ExportSubmenuWithNextControl />,
+ play: playTabClosesMenuChain({ shift: true }),
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownActionItem.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownActionItem.tsx
index 3393128f687..ebcc387137b 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownActionItem.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownActionItem.tsx
@@ -11,6 +11,7 @@ import { DropdownItemOwner } from './DropdownItemOwner';
import { getNativeDisabled } from './getNativeDisabled';
import { DropdownItemWithActions } from './DropdownItemWithActions';
import { type DropdownActionItemProps } from '../types/DropdownActionItemProps';
+import { getDropdownItemExplicitId } from './getDropdownItemExplicitId';
import { getDropdownItemLabel } from './getDropdownItemLabel';
import { getDropdownItems } from './getDropdownItems';
import { useDropdownContext } from './useDropdownContext';
@@ -33,14 +34,14 @@ export const DropdownActionItem = ({
nativeButton = !isDefined(render),
closeOnClick = true,
onClick,
- onFocus,
page,
id,
...props
}: DropdownActionItemProps) => {
const { type, closeTree, goToPage } = useDropdownContext();
const generatedId = useId();
- const itemId = id ?? generatedId;
+ const explicitId = getDropdownItemExplicitId({ id, render });
+ const itemId = explicitId ?? generatedId;
const itemFocus = useDropdownItemFocus({ id: itemId, disabled });
const hasActions = isRenderableSlot(actions);
@@ -54,10 +55,6 @@ export const DropdownActionItem = ({
nativeButton={nativeButton}
role={props.role ?? (type === 'menu' ? 'menuitem' : undefined)}
tabIndex={itemFocus.tabIndex}
- onFocus={(event) => {
- itemFocus.activate();
- onFocus?.(event);
- }}
data-dropdown-item=""
data-dropdown-page={page}
onClick={(event) => {
@@ -81,7 +78,7 @@ export const DropdownActionItem = ({
goToPage({
id: page,
trigger: {
- id,
+ id: explicitId,
index,
page,
label: getDropdownItemLabel(event.currentTarget),
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 5ae72d1d65d..c28760ab2d4 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContent.tsx
@@ -9,9 +9,10 @@ import { isDefined } from '@ui/utilities/utils/isDefined';
import styles from '../Dropdown.module.scss';
import { type DropdownContentProps } from '../types/DropdownContentProps';
import { DropdownPageFocusEffect } from './DropdownPageFocusEffect';
-import { DropdownSearchTargetEffect } from './DropdownSearchTargetEffect';
+import { DropdownRowsEffect } from './DropdownRowsEffect';
import { getDropdownFocusTarget } from './getDropdownFocusTarget';
import { getDropdownSearchTarget } from './getDropdownSearchTarget';
+import { isDropdownRow } from './isDropdownRow';
import { isUnhandledModifierShortcut } from './isUnhandledModifierShortcut';
import { useDropdownContext } from './useDropdownContext';
import { useDropdownKeyboardNavigation } from './useDropdownKeyboardNavigation';
@@ -31,6 +32,7 @@ export const DropdownContent = ({
children,
initialFocus,
onKeyDown,
+ onFocus,
onInput,
onClick,
onMouseDown,
@@ -43,7 +45,7 @@ export const DropdownContent = ({
const {
type,
isSubmenu,
- setOpen,
+ rowFocus,
initialFocusEdge,
focusOnOpen,
triggerId,
@@ -53,11 +55,7 @@ export const DropdownContent = ({
const contentRef = useRef<HTMLDivElement>(null);
const [content, setContent] = useState<HTMLDivElement | null>(null);
const mergedRef = useMergedRefs(contentRef, ref, setContent);
- const handleNavigation = useDropdownKeyboardNavigation({
- type,
- isSubmenu,
- setOpen,
- });
+ const handleNavigation = useDropdownKeyboardNavigation();
const defaultAriaLabelledBy = isDefined(ariaLabel)
? undefined
: (titleId ?? triggerId);
@@ -112,6 +110,18 @@ export const DropdownContent = ({
event.stopPropagation();
}
}}
+ onFocus={(event) => {
+ onFocus?.(event);
+
+ const { target } = event;
+
+ if (
+ target instanceof HTMLElement &&
+ isDropdownRow({ content: event.currentTarget, item: target })
+ ) {
+ rowFocus.focusRow(target.id);
+ }
+ }}
onInput={(event) => {
onInput?.(event);
setSearchTargetId(
@@ -136,7 +146,7 @@ export const DropdownContent = ({
</Popover.Positioner>
</Popover.Portal>
<DropdownPageFocusEffect contentRef={contentRef} />
- <DropdownSearchTargetEffect content={content} />
+ <DropdownRowsEffect content={content} />
</>
);
};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContextValue.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContextValue.ts
index 2f6a3d48d70..81140c972ef 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContextValue.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownContextValue.ts
@@ -1,6 +1,9 @@
+import { type Dispatch, type SetStateAction } from 'react';
+
import { type DropdownType } from '../types/DropdownType';
import { type DropdownFocusTarget } from './DropdownFocusTarget';
import { type DropdownPageFocusRequest } from './DropdownPageFocusRequest';
+import { type DropdownRowFocus } from './DropdownRowFocus';
export type DropdownContextValue = {
type: DropdownType;
@@ -9,10 +12,9 @@ export type DropdownContextValue = {
multiple: boolean;
isSubmenu: boolean;
parentType?: DropdownType;
- activeItemId?: string;
- parentActiveItemId?: string;
- setActiveItemId: (id: string) => void;
- setParentActiveItemId?: (id: string) => void;
+ rowFocus: DropdownRowFocus;
+ parentRowFocus?: DropdownRowFocus;
+ setRowIds: Dispatch<SetStateAction<string[] | undefined>>;
pageId?: string;
pageFocusRequest?: DropdownPageFocusRequest;
setPageFocusRequest: (request: DropdownPageFocusRequest | undefined) => void;
@@ -22,7 +24,7 @@ export type DropdownContextValue = {
focusOnOpen: boolean;
setFocusOnOpen: (focusOnOpen: boolean) => void;
setOpen: (open: boolean) => void;
- closeTree: () => void;
+ closeTree: (tabOutEvent?: Event) => void;
goToPage: (page: { id: string; trigger?: DropdownFocusTarget }) => void;
goBack: () => void;
registerPage: (page: { id: string; type?: DropdownType }) => void;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownOptionItem.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownOptionItem.tsx
index 77ce8434384..f4a159495d8 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownOptionItem.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownOptionItem.tsx
@@ -11,6 +11,7 @@ import { DropdownItemOwner } from './DropdownItemOwner';
import { getNativeDisabled } from './getNativeDisabled';
import { DropdownItemWithActions } from './DropdownItemWithActions';
import { type DropdownOptionItemProps } from '../types/DropdownOptionItemProps';
+import { getDropdownItemExplicitId } from './getDropdownItemExplicitId';
import { useDropdownContext } from './useDropdownContext';
import { useDropdownItemFocus } from './useDropdownItemFocus';
@@ -34,7 +35,6 @@ export const DropdownOptionItem = ({
disabled = false,
nativeButton = !isDefined(render),
onClick,
- onFocus,
id,
...props
}: DropdownOptionItemProps) => {
@@ -53,7 +53,7 @@ export const DropdownOptionItem = ({
: 'menuitem';
const selectionIndicator = multiple ? 'checkbox' : 'check';
const generatedId = useId();
- const itemId = id ?? generatedId;
+ const itemId = getDropdownItemExplicitId({ id, render }) ?? generatedId;
const itemFocus = useDropdownItemFocus({ id: itemId, disabled });
const hasActions = isRenderableSlot(actions);
@@ -76,10 +76,6 @@ export const DropdownOptionItem = ({
}
aria-current={isCurrentOption ? 'true' : undefined}
tabIndex={itemFocus.tabIndex}
- onFocus={(event) => {
- itemFocus.activate();
- onFocus?.(event);
- }}
data-dropdown-item=""
data-dropdown-option-item=""
onClick={(event) => {
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx
index b064f92a37a..6bbb5a6f3f5 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx
@@ -10,6 +10,7 @@ import { DropdownContext } from './DropdownContext';
import { type DropdownFocusTarget } from './DropdownFocusTarget';
import { type DropdownPageFocusRequest } from './DropdownPageFocusRequest';
import { DropdownNestedRootEffect } from './DropdownNestedRootEffect';
+import { getDropdownTabStopRowId } from './getDropdownTabStopRowId';
import { isDropdownDismissPrevented } from './isDropdownDismissPrevented';
import { useRegisteredElementId } from './useRegisteredElementId';
@@ -46,7 +47,8 @@ export const DropdownRoot = ({
id: string;
type: DropdownType;
}>();
- const [activeItemId, setActiveItemId] = useState<string>();
+ const [rowIds, setRowIds] = useState<string[]>();
+ const [focusedRowId, setFocusedRowId] = useState<string>();
const pageId = pageHistory[pageHistory.length - 1]?.id;
const [pageFocusRequest, setPageFocusRequest] =
useState<DropdownPageFocusRequest>();
@@ -69,6 +71,7 @@ export const DropdownRoot = ({
setPageHistory([{ id: defaultPage }]);
setActivePage(undefined);
setPageFocusRequest(undefined);
+ setFocusedRowId(undefined);
}
if (isClosing) {
@@ -85,11 +88,22 @@ export const DropdownRoot = ({
onOpenChange?.(nextOpen);
};
- const closeTree = () => {
+ const closeTree = (tabOutEvent?: Event) => {
+ if (
+ isDefined(tabOutEvent) &&
+ isDropdownDismissPrevented({
+ onDismiss: onInteractOutside,
+ event: tabOutEvent,
+ target: null,
+ })
+ ) {
+ return;
+ }
+
setOpen(false);
if (isSubmenu) {
- parent?.closeTree();
+ parent?.closeTree(tabOutEvent);
}
};
@@ -187,10 +201,13 @@ export const DropdownRoot = ({
multiple,
isSubmenu,
parentType: parent?.type,
- activeItemId,
- parentActiveItemId: parent?.activeItemId,
- setActiveItemId,
- setParentActiveItemId: parent?.setActiveItemId,
+ rowFocus: {
+ rowIds,
+ tabStopRowId: getDropdownTabStopRowId({ rowIds, focusedRowId }),
+ focusRow: setFocusedRowId,
+ },
+ parentRowFocus: parent?.rowFocus,
+ setRowIds,
pageId,
pageFocusRequest,
setPageFocusRequest,
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRowFocus.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRowFocus.ts
new file mode 100644
index 00000000000..35656ae88af
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRowFocus.ts
@@ -0,0 +1,5 @@
+export type DropdownRowFocus = {
+ rowIds?: string[];
+ tabStopRowId?: string;
+ focusRow: (id: string) => void;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRowsEffect.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRowsEffect.tsx
new file mode 100644
index 00000000000..dcb455cc111
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRowsEffect.tsx
@@ -0,0 +1,52 @@
+import { areArraysEqual } from '@base-ui/utils/areArraysEqual';
+import { useLayoutEffect } from 'react';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { getDropdownRows } from './getDropdownRows';
+import { getDropdownSearchTarget } from './getDropdownSearchTarget';
+import { useDropdownContext } from './useDropdownContext';
+
+type DropdownRowsEffectProps = {
+ content: HTMLDivElement | null;
+};
+
+export const DropdownRowsEffect = ({ content }: DropdownRowsEffectProps) => {
+ const { setRowIds, setSearchTargetId } = useDropdownContext();
+
+ useLayoutEffect(() => {
+ if (!isDefined(content)) {
+ return;
+ }
+
+ const updateRows = () => {
+ const rowIds = getDropdownRows(content).map((row) => row.id);
+
+ setRowIds((currentRowIds) =>
+ isDefined(currentRowIds) && areArraysEqual(currentRowIds, rowIds)
+ ? currentRowIds
+ : rowIds,
+ );
+ setSearchTargetId(getDropdownSearchTarget(content)?.id);
+ };
+
+ updateRows();
+
+ const observer = new MutationObserver(updateRows);
+
+ observer.observe(content, {
+ childList: true,
+ subtree: true,
+ attributes: true,
+ attributeFilter: ['disabled', 'aria-disabled', 'id'],
+ });
+
+ return () => {
+ observer.disconnect();
+ setRowIds(undefined);
+ setSearchTargetId(undefined);
+ };
+ }, [content, setRowIds, setSearchTargetId]);
+
+ return null;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearchTargetEffect.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearchTargetEffect.tsx
deleted file mode 100644
index 3f098179468..00000000000
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSearchTargetEffect.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import { useLayoutEffect } from 'react';
-
-import { isDefined } from '@ui/utilities/utils/isDefined';
-
-import { getDropdownSearchTarget } from './getDropdownSearchTarget';
-import { useDropdownContext } from './useDropdownContext';
-
-type DropdownSearchTargetEffectProps = {
- content: HTMLDivElement | null;
-};
-
-export const DropdownSearchTargetEffect = ({
- content,
-}: DropdownSearchTargetEffectProps) => {
- const { setSearchTargetId } = useDropdownContext();
-
- useLayoutEffect(() => {
- if (!isDefined(content)) {
- return;
- }
-
- const updateSearchTarget = () =>
- setSearchTargetId(getDropdownSearchTarget(content)?.id);
-
- updateSearchTarget();
-
- const observer = new MutationObserver(updateSearchTarget);
-
- observer.observe(content, {
- childList: true,
- subtree: true,
- attributes: true,
- attributeFilter: ['disabled', 'aria-disabled'],
- });
-
- return () => {
- observer.disconnect();
- setSearchTargetId(undefined);
- };
- }, [content, setSearchTargetId]);
-
- return null;
-};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenuTrigger.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenuTrigger.tsx
index 483b0fe0031..00507a21fbf 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenuTrigger.tsx
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownSubmenuTrigger.tsx
@@ -9,6 +9,7 @@ import { isDefined } from '@ui/utilities/utils/isDefined';
import { type DropdownSubmenuTriggerProps } from '../types/DropdownSubmenuTriggerProps';
import { DropdownItemOwner } from './DropdownItemOwner';
import { getNativeDisabled } from './getNativeDisabled';
+import { getDropdownItemExplicitId } from './getDropdownItemExplicitId';
import { getDropdownFocusTarget } from './getDropdownFocusTarget';
import { useDropdownContext } from './useDropdownContext';
import { useDropdownItemFocus } from './useDropdownItemFocus';
@@ -29,7 +30,6 @@ export const DropdownSubmenuTrigger = ({
nativeButton = !isDefined(render),
openOnHover = true,
onKeyDown,
- onFocus,
id,
ref,
...props
@@ -46,7 +46,7 @@ export const DropdownSubmenuTrigger = ({
} = useDropdownContext();
const triggerType = open ? type : rootType;
const generatedId = useId();
- const itemId = id ?? generatedId;
+ const itemId = getDropdownItemExplicitId({ id, render }) ?? generatedId;
const itemFocus = useDropdownItemFocus({
id: itemId,
disabled,
@@ -67,10 +67,6 @@ export const DropdownSubmenuTrigger = ({
role={parentType === 'menu' ? 'menuitem' : undefined}
aria-haspopup={triggerType === 'menu' ? 'menu' : 'dialog'}
tabIndex={itemFocus.tabIndex}
- onFocus={(event) => {
- itemFocus.activate();
- onFocus?.(event);
- }}
data-dropdown-item=""
onKeyDown={(event) => {
onKeyDown?.(event);
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts
index 803c75aec37..65fad318629 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts
@@ -6,6 +6,7 @@ import { type DropdownType } from '../types/DropdownType';
import { type DropdownFocusTarget } from './DropdownFocusTarget';
import { getDropdownItemLabel } from './getDropdownItemLabel';
import { getDropdownItems } from './getDropdownItems';
+import { getDropdownSearch } from './getDropdownSearch';
export const getDropdownFocusTarget = ({
content,
@@ -72,9 +73,7 @@ export const getDropdownFocusTarget = ({
return firstFormControl ?? content;
}
- const search = content.querySelector<HTMLInputElement>(
- '[data-dropdown-search]:not(:disabled)',
- );
+ const search = getDropdownSearch(content);
if (isDefined(search)) {
return search;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItemExplicitId.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItemExplicitId.ts
new file mode 100644
index 00000000000..123e562b523
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItemExplicitId.ts
@@ -0,0 +1,15 @@
+import { isValidElement, type ReactElement } from 'react';
+
+export const getDropdownItemExplicitId = ({
+ id,
+ render,
+}: {
+ id?: string;
+ render?: ReactElement;
+}) => {
+ if (!isValidElement<{ id?: string }>(render)) {
+ return id;
+ }
+
+ return render.props.id ?? id;
+};
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItems.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItems.ts
index 11e4d867746..0a92fc0c939 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItems.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownItems.ts
@@ -1,9 +1,6 @@
+import { isEnabledDropdownItem } from './isEnabledDropdownItem';
+
export const getDropdownItems = (content: HTMLElement) =>
Array.from(
content.querySelectorAll<HTMLElement>('[data-dropdown-item]'),
- ).filter(
- (item) =>
- item.getAttribute('aria-disabled') !== 'true' &&
- !item.hasAttribute('disabled') &&
- item.closest('[data-dropdown-content]') === content,
- );
+ ).filter((item) => isEnabledDropdownItem({ content, item }));
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownRows.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownRows.ts
new file mode 100644
index 00000000000..4351c259564
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownRows.ts
@@ -0,0 +1,6 @@
+import { isDropdownRow } from './isDropdownRow';
+
+export const getDropdownRows = (content: HTMLElement) =>
+ Array.from(
+ content.querySelectorAll<HTMLElement>('[data-dropdown-item]'),
+ ).filter((item) => isDropdownRow({ content, item }));
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearch.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearch.ts
new file mode 100644
index 00000000000..d6b6c3ac23d
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearch.ts
@@ -0,0 +1,4 @@
+export const getDropdownSearch = (content: HTMLElement) =>
+ content.querySelector<HTMLInputElement>(
+ '[data-dropdown-search]:not(:disabled)',
+ );
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 e6b99c4740e..a3aa30ad8aa 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearchTarget.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownSearchTarget.ts
@@ -3,15 +3,14 @@ import { isNonEmptyString } from '@sniptt/guards';
import { isDefined } from '@ui/utilities/utils/isDefined';
import { getDropdownItems } from './getDropdownItems';
+import { getDropdownSearch } from './getDropdownSearch';
export const getDropdownSearchTarget = (content: HTMLElement) => {
if (content.dataset.type === 'panel') {
return undefined;
}
- const search = content.querySelector<HTMLInputElement>(
- '[data-dropdown-search]:not(:disabled)',
- );
+ const search = getDropdownSearch(content);
if (!isDefined(search) || !isNonEmptyString(search.value.trim())) {
return undefined;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownTabStopRowId.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownTabStopRowId.ts
new file mode 100644
index 00000000000..068ed169b6e
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownTabStopRowId.ts
@@ -0,0 +1,12 @@
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+export const getDropdownTabStopRowId = ({
+ rowIds = [],
+ focusedRowId,
+}: {
+ rowIds?: string[];
+ focusedRowId?: string;
+}) =>
+ isDefined(focusedRowId) && rowIds.includes(focusedRowId)
+ ? focusedRowId
+ : rowIds[0];
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/isDropdownDismissPrevented.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/isDropdownDismissPrevented.ts
index 7677a18bfba..9c08a8c1ffc 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/isDropdownDismissPrevented.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/isDropdownDismissPrevented.ts
@@ -6,9 +6,11 @@ import { getDropdownDismissTarget } from './getDropdownDismissTarget';
export const isDropdownDismissPrevented = ({
onDismiss,
event,
+ target = getDropdownDismissTarget(event),
}: {
onDismiss: ((dismissEvent: DropdownDismissEvent) => void) | undefined;
event: Event;
+ target?: Element | null;
}) => {
if (!isDefined(onDismiss)) {
return false;
@@ -17,7 +19,7 @@ export const isDropdownDismissPrevented = ({
let isPrevented = false;
onDismiss({
- target: getDropdownDismissTarget(event),
+ target,
type: event.type,
preventDefault: () => {
isPrevented = true;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/isDropdownRow.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/isDropdownRow.ts
new file mode 100644
index 00000000000..c858f1245a1
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/isDropdownRow.ts
@@ -0,0 +1,16 @@
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { getDropdownSearch } from './getDropdownSearch';
+import { isEnabledDropdownItem } from './isEnabledDropdownItem';
+
+export const isDropdownRow = ({
+ content,
+ item,
+}: {
+ content: HTMLElement;
+ item: HTMLElement;
+}) =>
+ item.hasAttribute('data-dropdown-item') &&
+ isEnabledDropdownItem({ content, item }) &&
+ (!item.hasAttribute('data-dropdown-back') ||
+ !isDefined(getDropdownSearch(content)));
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/isEnabledDropdownItem.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/isEnabledDropdownItem.ts
new file mode 100644
index 00000000000..3697909338e
--- /dev/null
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/isEnabledDropdownItem.ts
@@ -0,0 +1,10 @@
+export const isEnabledDropdownItem = ({
+ content,
+ item,
+}: {
+ content: HTMLElement;
+ item: HTMLElement;
+}) =>
+ item.getAttribute('aria-disabled') !== 'true' &&
+ !item.hasAttribute('disabled') &&
+ item.closest('[data-dropdown-content]') === content;
diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownItemFocus.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownItemFocus.ts
index 7860edb681f..cace439ee94 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownItemFocus.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownItemFocus.ts
@@ -11,16 +11,11 @@ export const useDropdownItemFocus = ({
}) => {
const context = useDropdownContext();
const type = isSubmenuTrigger ? context.parentType : context.type;
- const activeItemId = isSubmenuTrigger
- ? context.parentActiveItemId
- : context.activeItemId;
- const setActiveItemId = isSubmenuTrigger
- ? context.setParentActiveItemId
- : context.setActiveItemId;
- const isOutsideMenuRovingFocus = type === 'menu' && activeItemId !== id;
+ const rowFocus = isSubmenuTrigger ? context.parentRowFocus : context.rowFocus;
+ const isRovingRow =
+ type !== 'panel' && (rowFocus?.rowIds?.includes(id) ?? true);
+ const isOutsideTabOrder =
+ disabled || (isRovingRow && rowFocus?.tabStopRowId !== id);
- return {
- tabIndex: disabled || isOutsideMenuRovingFocus ? -1 : 0,
- activate: () => setActiveItemId?.(id),
- };
+ return { tabIndex: isOutsideTabOrder ? -1 : 0 };
};
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 c61d5b2077e..3e53fbb6906 100644
--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts
+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/useDropdownKeyboardNavigation.ts
@@ -3,25 +3,20 @@ import { useState, type KeyboardEvent } from 'react';
import { isDefined } from '@ui/utilities/utils/isDefined';
-import { type DropdownType } from '../types/DropdownType';
import { getDropdownItemLabel } from './getDropdownItemLabel';
import { getDropdownItems } from './getDropdownItems';
+import { getDropdownRows } from './getDropdownRows';
+import { getDropdownSearch } from './getDropdownSearch';
import { getDropdownSearchTarget } from './getDropdownSearchTarget';
import { getDropdownTrigger } from './getDropdownTrigger';
import { getNextDropdownGridItem } from './getNextDropdownGridItem';
import { getNextDropdownItem } from './getNextDropdownItem';
+import { useDropdownContext } from './useDropdownContext';
const TYPEAHEAD_RESET_DELAY = 500;
-export const useDropdownKeyboardNavigation = ({
- type,
- isSubmenu,
- setOpen,
-}: {
- type: DropdownType;
- isSubmenu: boolean;
- setOpen: (open: boolean) => void;
-}) => {
+export const useDropdownKeyboardNavigation = () => {
+ const { type, isSubmenu, setOpen, closeTree } = useDropdownContext();
const direction = useDirection();
const [typeahead, setTypeahead] = useState({ text: '', timestamp: 0 });
@@ -77,17 +72,19 @@ export const useDropdownKeyboardNavigation = ({
return;
}
- const search = content.querySelector<HTMLInputElement>(
- '[data-dropdown-search]:not(:disabled)',
- );
+ if (type === 'menu' && event.key === 'Tab' && event.shiftKey) {
+ event.preventDefault();
+ closeTree(event.nativeEvent);
+ return;
+ }
+
+ const search = getDropdownSearch(content);
const isSearch = target === search;
if (isEditable && !isSearch) {
return;
}
- const items = getDropdownItems(content).filter(
- (item) => !isDefined(search) || !item.hasAttribute('data-dropdown-back'),
- );
+ const items = getDropdownRows(content);
const searchTarget =
isSearch && event.key === 'Enter' && !event.nativeEvent.isComposing
? getDropdownSearchTarget(content)