Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🎛️ refactor: Move the Code Tool Selects onto Dropdown and Remove Select (#17432)

Marco Beretta69b3a7cac617
diff --git a/client/src/components/SidePanel/Agents/Code/Settings.tsx b/client/src/components/SidePanel/Agents/Code/Settings.tsx
index 3fff7e75c1..f657fe1b36 100644
--- a/client/src/components/SidePanel/Agents/Code/Settings.tsx
+++ b/client/src/components/SidePanel/Agents/Code/Settings.tsx
@@ -1,12 +1,8 @@
-import { useCallback, useEffect } from 'react';
+import { useCallback, useEffect, useId } from 'react';
import { useFormContext } from 'react-hook-form';
import {
Switch,
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
+ Dropdown,
HoverCard,
HoverCardPortal,
HoverCardContent,
@@ -43,6 +39,7 @@ const WORKSPACE_STATUS_LABELS = {
} as const;
export default function CodeSettings() {
+ const labelId = useId();
const localize = useLocalize();
const { user } = useAuthContext();
const { agentsConfig } = useGetAgentsConfig();
@@ -205,15 +202,18 @@ export default function CodeSettings() {
<div className="space-y-2 ps-1">
{executionEnvironments.length > 0 && (
<>
- <label
+ <span
+ id={`${labelId}-code-environment`}
className="text-text-secondary text-xs font-medium"
- htmlFor="code-environment-id"
>
{localize('com_ui_code_environment')}
- </label>
- <Select
+ </span>
+ <Dropdown
+ variant="field"
+ testId="code-environment-id"
+ aria-labelledby={`${labelId}-code-environment`}
value={codeEnvironmentId ?? DEPLOYMENT_DEFAULT_ENVIRONMENT}
- onValueChange={(value) => {
+ onChange={(value) => {
setValue('code_workspace_id', '', { shouldDirty: true });
setValue(
'code_environment_id',
@@ -221,24 +221,20 @@ export default function CodeSettings() {
{ shouldDirty: true },
);
}}
- >
- <SelectTrigger id="code-environment-id" data-testid="code-environment-id">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value={DEPLOYMENT_DEFAULT_ENVIRONMENT}>
- {localize('com_ui_code_environment_deployment_default')}
- </SelectItem>
- {executionEnvironments.map((candidate) => (
- <SelectItem key={candidate.id} value={candidate.id}>
- {candidate.name}
- {candidate.type === 'attached'
- ? ` (${localize('com_ui_code_environment_attached')})`
- : ''}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ options={[
+ {
+ value: DEPLOYMENT_DEFAULT_ENVIRONMENT,
+ label: localize('com_ui_code_environment_deployment_default'),
+ },
+ ...executionEnvironments.map((candidate) => ({
+ value: candidate.id,
+ label:
+ candidate.type === 'attached'
+ ? `${candidate.name} (${localize('com_ui_code_environment_attached')})`
+ : candidate.name,
+ })),
+ ]}
+ />
<p className="text-text-tertiary text-xs">
{localize('com_nav_info_code_environment')}
</p>
@@ -293,52 +289,48 @@ export default function CodeSettings() {
)}
</>
)}
- <label
+ <span
+ id={`${labelId}-stateful-code-environment`}
className="text-text-secondary text-xs font-medium"
- htmlFor="stateful-code-environment"
>
{localize('com_ui_stateful_code_environment')}
- </label>
- <Select
+ </span>
+ <Dropdown
+ variant="field"
+ testId="stateful-code-environment"
+ aria-labelledby={`${labelId}-stateful-code-environment`}
value={environment}
- onValueChange={(value) => {
+ onChange={(value) => {
const nextEnvironment = value as StatefulCodeEnvironment;
if (allowedEnvironments.includes(nextEnvironment)) {
setValue('stateful_code_environment', nextEnvironment, { shouldDirty: true });
}
}}
- >
- <SelectTrigger id="stateful-code-environment" data-testid="stateful-code-environment">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {STATEFUL_CODE_ENVIRONMENTS.filter(
- (candidate) => allowedEnvironments.includes(candidate) || candidate === environment,
- ).map((candidate) => (
- <SelectItem
- key={candidate}
- value={candidate}
- disabled={!allowedEnvironments.includes(candidate)}
- >
- {localize(ENVIRONMENT_LABELS[candidate])}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ options={STATEFUL_CODE_ENVIRONMENTS.filter(
+ (candidate) => allowedEnvironments.includes(candidate) || candidate === environment,
+ ).map((candidate) => ({
+ value: candidate,
+ label: localize(ENVIRONMENT_LABELS[candidate]),
+ disabled: !allowedEnvironments.includes(candidate),
+ }))}
+ />
<p className="text-text-tertiary text-xs">
{localize('com_nav_info_stateful_code_environment')}
</p>
{showGitIdentity && (
<div className="space-y-2">
- <label
- htmlFor="code-workspace-default"
+ <span
+ id={`${labelId}-code-workspace-default`}
className="text-text-secondary text-xs font-medium"
>
{localize('com_ui_code_workspace_default')}
- </label>
- <Select
+ </span>
+ <Dropdown
+ variant="field"
+ testId="code-workspace-default"
+ aria-labelledby={`${labelId}-code-workspace-default`}
value={workspaceId || '__automatic__'}
- onValueChange={(value) => {
+ onChange={(value) => {
if (value !== '__automatic__' && !workspaces.some(({ id }) => id === value))
return;
setValue('code_workspace_id', value === '__automatic__' ? '' : value, {
@@ -350,33 +342,26 @@ export default function CodeSettings() {
});
}
}}
- >
- <SelectTrigger id="code-workspace-default">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="__automatic__">
- {localize('com_ui_code_workspace_last_used')}
- </SelectItem>
- {workspaceId &&
- (workspaceDiscoveryState !== 'ready' ||
- !workspaces.some(({ id }) => id === workspaceId)) && (
- <SelectItem value={workspaceId} disabled>
- {workspaceId} —{' '}
- {localize(
- workspaceDiscoveryState === 'ready'
- ? 'com_ui_code_workspace_missing'
- : WORKSPACE_STATUS_LABELS[workspaceDiscoveryState],
- )}
- </SelectItem>
- )}
- {workspaces.map(({ id, name }) => (
- <SelectItem key={id} value={id}>
- {name ?? id}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ options={[
+ { value: '__automatic__', label: localize('com_ui_code_workspace_last_used') },
+ ...(workspaceId &&
+ (workspaceDiscoveryState !== 'ready' ||
+ !workspaces.some(({ id }) => id === workspaceId))
+ ? [
+ {
+ value: workspaceId,
+ label: `${workspaceId} (${localize(
+ workspaceDiscoveryState === 'ready'
+ ? 'com_ui_code_workspace_missing'
+ : WORKSPACE_STATUS_LABELS[workspaceDiscoveryState],
+ )})`,
+ disabled: true,
+ },
+ ]
+ : []),
+ ...workspaces.map(({ id, name }) => ({ value: id, label: name ?? id })),
+ ]}
+ />
{workspaceDiscoveryState !== 'ready' && (
<p className="text-text-tertiary text-xs" role="status">
{localize(WORKSPACE_STATUS_LABELS[workspaceDiscoveryState])}
@@ -389,34 +374,27 @@ export default function CodeSettings() {
)}
{showGitIdentity && (
<div className="border-border-light space-y-2 border-t pt-3">
- <label
- htmlFor="repository-instructions"
+ <span
+ id={`${labelId}-repository-instructions`}
className="text-text-secondary text-xs font-medium"
>
{localize('com_ui_repository_instructions')}
- </label>
- <Select
+ </span>
+ <Dropdown
+ variant="field"
+ testId="repository-instructions"
+ aria-labelledby={`${labelId}-repository-instructions`}
value={watch('repositoryInstructions') ?? 'prefer'}
- onValueChange={(value) => {
+ onChange={(value) => {
if (value === 'prefer' || value === 'defer' || value === 'off')
setValue('repositoryInstructions', value, { shouldDirty: true });
}}
- >
- <SelectTrigger id="repository-instructions">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="prefer">
- {localize('com_ui_repository_instructions_prefer')}
- </SelectItem>
- <SelectItem value="defer">
- {localize('com_ui_repository_instructions_defer')}
- </SelectItem>
- <SelectItem value="off">
- {localize('com_ui_repository_instructions_off')}
- </SelectItem>
- </SelectContent>
- </Select>
+ options={[
+ { value: 'prefer', label: localize('com_ui_repository_instructions_prefer') },
+ { value: 'defer', label: localize('com_ui_repository_instructions_defer') },
+ { value: 'off', label: localize('com_ui_repository_instructions_off') },
+ ]}
+ />
<p className="text-text-tertiary text-xs">
{localize('com_ui_repository_instructions_description')}
</p>
diff --git a/client/src/components/SidePanel/Agents/__tests__/CodeSettings.spec.tsx b/client/src/components/SidePanel/Agents/__tests__/CodeSettings.spec.tsx
index bac5a94595..e4b4d45a7c 100644
--- a/client/src/components/SidePanel/Agents/__tests__/CodeSettings.spec.tsx
+++ b/client/src/components/SidePanel/Agents/__tests__/CodeSettings.spec.tsx
@@ -133,9 +133,9 @@ test('repository instruction mode defaults to prefer and retains an explicit off
HTMLElement.prototype.scrollIntoView = jest.fn();
render(<IdentityForm />);
expect(
- screen.getByRole('combobox', { name: 'com_ui_repository_instructions' }),
+ screen.getByRole('combobox', { name: /^com_ui_repository_instructions / }),
).toHaveTextContent('com_ui_repository_instructions_prefer');
- fireEvent.click(screen.getByRole('combobox', { name: 'com_ui_repository_instructions' }));
+ fireEvent.click(screen.getByRole('combobox', { name: /^com_ui_repository_instructions / }));
fireEvent.click(
await screen.findByRole('option', { name: 'com_ui_repository_instructions_off' }),
);
@@ -143,18 +143,18 @@ test('repository instruction mode defaults to prefer and retains an explicit off
fireEvent.click(screen.getByText('Toggle Dialog'));
fireEvent.click(screen.getByText('Toggle Dialog'));
expect(
- screen.getByRole('combobox', { name: 'com_ui_repository_instructions' }),
+ screen.getByRole('combobox', { name: /^com_ui_repository_instructions / }),
).toHaveTextContent('com_ui_repository_instructions_off');
});
test('saves a workspace default bound to the selected machine and permits clearing it', async () => {
HTMLElement.prototype.scrollIntoView = jest.fn();
render(<IdentityForm />);
- fireEvent.click(screen.getByRole('combobox', { name: 'com_ui_code_workspace_default' }));
+ fireEvent.click(screen.getByRole('combobox', { name: /^com_ui_code_workspace_default / }));
fireEvent.click(await screen.findByRole('option', { name: 'Project A' }));
expect(screen.getByTestId('workspace-default')).toHaveTextContent('project-a');
expect(screen.getByTestId('machine-default')).toHaveTextContent('byom');
- fireEvent.click(screen.getByRole('combobox', { name: 'com_ui_code_workspace_default' }));
+ fireEvent.click(screen.getByRole('combobox', { name: /^com_ui_code_workspace_default / }));
fireEvent.click(await screen.findByRole('option', { name: 'com_ui_code_workspace_last_used' }));
expect(screen.getByTestId('workspace-default')).toBeEmptyDOMElement();
});
@@ -184,7 +184,7 @@ test('permits clearing a saved workspace while discovery is unavailable', async
mockWorkspaceStatusQueries.mockReturnValue([{ isLoading: false, isError: true }]);
render(<IdentityForm savedWorkspace="project-a" />);
- fireEvent.click(screen.getByRole('combobox', { name: 'com_ui_code_workspace_default' }));
+ fireEvent.click(screen.getByRole('combobox', { name: /^com_ui_code_workspace_default / }));
fireEvent.click(await screen.findByRole('option', { name: 'com_ui_code_workspace_last_used' }));
expect(screen.getByTestId('workspace-default')).toBeEmptyDOMElement();
diff --git a/e2e/specs/mock/scenarios/nested-popovers.spec.ts b/e2e/specs/mock/scenarios/nested-popovers.spec.ts
index a9c63018db..0831db2f31 100644
--- a/e2e/specs/mock/scenarios/nested-popovers.spec.ts
+++ b/e2e/specs/mock/scenarios/nested-popovers.spec.ts
@@ -9,9 +9,9 @@ import { openSidebar } from './sidebar';
* A modal OGDialog parks `pointer-events: none` on the body, so a menu portaled out of it inherits
* `none` unless it turns pointer events back on for itself. DropdownPopup does that with a class,
* not an inline style, and its menu must still take a real mouse pick while the dialog is open.
- * The Select's check indicator draws its box at the icon size role, so a theme that resizes icons
- * resizes the box with the glyph inside it. The Select under test is the agent code tool's execution
- * environment picker, which renders inside the tool's modal dialog.
+ * A field Dropdown's check glyph draws at the icon size role, so a theme that resizes icons resizes
+ * the check. The Dropdown under test is the agent code tool's execution environment picker, which
+ * renders inside the tool's modal dialog.
*/
/** Names an icon size apart from the default, so a box still drawn at a fixed size shows. */
@@ -125,10 +125,12 @@ async function openEnvironmentSelect(page: Page) {
await trigger.click();
const listbox = page.getByRole('listbox');
await expect(listbox).toBeVisible();
- /** The list zooms in, so a box read before the animation settles is scaled. */
- await listbox.evaluate((element) =>
- Promise.all(element.getAnimations({ subtree: true }).map((animation) => animation.finished)),
- );
+ /** The list zooms in from 0.95, so a box read before the transition settles is scaled. The
+ * transition only starts once Ariakit marks the list entered, so wait for that first. */
+ await expect(listbox).toHaveAttribute('data-enter');
+ await expect
+ .poll(() => listbox.evaluate((element) => getComputedStyle(element).scale))
+ .toMatch(/^(1|none)$/);
}
test.afterEach(async ({ page }) => {
@@ -136,20 +138,15 @@ test.afterEach(async ({ page }) => {
agentId = undefined;
});
-/** The checked option's indicator box is `expected` square and its glyph fills it exactly. */
+/** The checked option's check glyph is `expected` square, so it follows the icon size role. */
async function expectIndicator(page: Page, expected: string) {
const checked = page.getByRole('option', { selected: true });
- const box = checked.locator('> span').first();
const glyph = checked.locator('svg');
await expect(glyph).toBeVisible();
- const [boxRect, glyphRect] = await Promise.all([box.boundingBox(), glyph.boundingBox()]);
- expect(boxRect).not.toBeNull();
+ const glyphRect = await glyph.boundingBox();
expect(glyphRect).not.toBeNull();
- expect(`${boxRect?.width}px`).toBe(expected);
- expect(`${boxRect?.height}px`).toBe(expected);
- /** The glyph sits inside its box rather than spilling past it. */
- expect(glyphRect?.width).toBe(boxRect?.width);
- expect(glyphRect?.x).toBe(boxRect?.x);
+ expect(`${glyphRect?.width}px`).toBe(expected);
+ expect(`${glyphRect?.height}px`).toBe(expected);
}
test.describe('popovers inside a modal dialog', () => {
@@ -202,6 +199,31 @@ test.describe('popovers inside a modal dialog', () => {
await expectIndicator(page, '20px');
});
+ /** The dialog traps focus in its own DOM, so a list portaled out of it could not take the
+ * keyboard. The list renders inside the dialog and the arrow keys and Enter pick from it. */
+ test('the execution environment Dropdown takes a keyboard pick inside the tool dialog @scenario:code-environment-keyboard-pick', async ({
+ page,
+ }) => {
+ await offerStatefulSessions(page);
+ await useTheme(page);
+ await openEnvironmentSelect(page);
+
+ const dialog = page.getByRole('dialog');
+ const listbox = page.getByRole('listbox');
+ await expect(dialog).toContainText('E2E managed runtime');
+ expect(await listbox.evaluate((element) => element.closest('[role="dialog"]') != null)).toBe(
+ true,
+ );
+ await expect(listbox).toBeFocused();
+ await page.keyboard.press('ArrowDown');
+ await page.keyboard.press('Enter');
+ await expect(listbox).toBeHidden();
+ const trigger = dialog.getByTestId('code-environment-id');
+ await expect(trigger).toHaveText('E2E managed runtime');
+ await expect(trigger).toBeFocused();
+ await expect(dialog).toBeVisible();
+ });
+
/** The Settings dialog is a Headless UI panel, not an OGDialog; before it declared a dialog
* level its popover lists painted behind it (berry-13/LibreChat#249). Hit testing alone cannot
* show that: the open list sets `pointer-events: none` on the body, so the panel is skipped and
@@ -237,7 +259,9 @@ test.describe('popovers inside a modal dialog', () => {
await expect(page.getByTestId('default-stateful-workspace')).toHaveText(
'Conversation workspace',
);
- await expect(page.getByRole('dialog').getByRole('heading', { name: 'Settings' })).toBeVisible();
+ /** Mobile shows the open section's title in place of "Settings", so the control staying on
+ * screen is what shows the dialog stayed open. */
+ await expect(page.getByTestId('default-stateful-workspace')).toBeVisible();
});
});
@@ -251,22 +275,40 @@ const REFERENCE_LIST_THEME = {
},
} as const;
-/** The open list's width floor and scroll cap, as the browser computed them, with the room the
- * popper leaves between its trigger and the viewport's edge, and the list's drawn box. */
+/** The open list's width floor and scroll cap, as the browser computed them, with the trigger's
+ * width and the room the popover leaves between its trigger and its boundary, and the list's
+ * drawn box. Inside a dialog that boundary is the dialog, since the list renders in it. */
async function listBounds(page: Page) {
return page.getByRole('listbox').evaluate((element) => {
const style = getComputedStyle(element);
- const { top, bottom } = element.getBoundingClientRect();
+ const { top, bottom, width } = element.getBoundingClientRect();
return {
+ width,
minWidth: style.minWidth,
maxHeight: style.maxHeight,
- available: parseFloat(style.getPropertyValue('--radix-select-content-available-height')),
+ anchor: parseFloat(style.getPropertyValue('--popover-anchor-width')),
+ available: parseFloat(style.getPropertyValue('--popover-available-height')),
top,
bottom,
};
});
}
+/** The list takes the `roleMinWidth` floor and is at least its trigger wide, and caps at `roleMaxHeight` or the
+ * room it has, whichever is smaller. A `none` role leaves only the room. */
+function expectListRoles(
+ bounds: Awaited<ReturnType<typeof listBounds>>,
+ roleMinWidth: number,
+ roleMaxHeight: number | 'none',
+) {
+ expect(bounds.anchor).toBeGreaterThan(0);
+ expect(bounds.minWidth).toBe(`${roleMinWidth}px`);
+ expect(bounds.width).toBeGreaterThanOrEqual(Math.max(roleMinWidth, bounds.anchor) - 0.5);
+ const cap =
+ roleMaxHeight === 'none' ? bounds.available : Math.min(roleMaxHeight, bounds.available);
+ expect(bounds.maxHeight).toBe(`${cap}px`);
+}
+
/** Tall enough that the list's own cap, not the viewport, decides its height. */
async function useTallWindow(page: Page) {
const { width } = page.viewportSize() ?? { width: 1280 };
@@ -296,9 +338,7 @@ test.describe('Select list size roles', () => {
await useTheme(page);
await useTallWindow(page);
await openEnvironmentSelect(page);
- const bounds = await listBounds(page);
- expect(bounds.available).toBeGreaterThan(384);
- expect(bounds).toMatchObject({ minWidth: '128px', maxHeight: '384px' });
+ expectListRoles(await listBounds(page), 128, 384);
});
test('the ClickHouse theme sizes the list by its trigger and caps it at the available height @scenario:select-list-size-clickhouse', async ({
@@ -308,9 +348,7 @@ test.describe('Select list size roles', () => {
await useTheme(page, clickHouseTheme);
await useTallWindow(page);
await openEnvironmentSelect(page);
- const bounds = await listBounds(page);
- expect(bounds.available).toBeGreaterThan(384);
- expect(bounds).toMatchObject({ minWidth: '0px', maxHeight: `${bounds.available}px` });
+ expectListRoles(await listBounds(page), 0, 'none');
});
test('a theme that sets both list roles resizes the list @scenario:select-list-size-reference', async ({
@@ -320,7 +358,7 @@ test.describe('Select list size roles', () => {
await useTheme(page, REFERENCE_LIST_THEME);
await useTallWindow(page);
await openEnvironmentSelect(page);
- expect(await listBounds(page)).toMatchObject({ minWidth: '192px', maxHeight: '320px' });
+ expectListRoles(await listBounds(page), 192, 320);
});
test('the default list never grows past a short phone screen @scenario:select-list-fits-short-phone', async ({
diff --git a/eslint-suppressions.json b/eslint-suppressions.json
index 0e061eaf0f..b49d7a3796 100644
--- a/eslint-suppressions.json
+++ b/eslint-suppressions.json
@@ -1455,11 +1455,6 @@
"count": 1
}
},
- "packages/client/src/components/Combobox.tsx": {
- "shadcn/no-inline-styles": {
- "count": 1
- }
- },
"packages/client/src/components/DataTable.tsx": {
"shadcn/no-inline-styles": {
"count": 4
diff --git a/packages/client/src/components/Combobox.tsx b/packages/client/src/components/Combobox.tsx
deleted file mode 100644
index 1e43f19c74..0000000000
--- a/packages/client/src/components/Combobox.tsx
+++ /dev/null
@@ -1,178 +0,0 @@
-import { startTransition } from 'react';
-import { JSX } from 'react/jsx-runtime';
-import { Search as SearchIcon } from 'lucide-react';
-import * as RadixSelect from '@radix-ui/react-select';
-import { CheckIcon, ChevronDownIcon } from '@radix-ui/react-icons';
-import {
- Combobox,
- ComboboxItem,
- ComboboxList,
- ComboboxProvider,
- ComboboxCancel,
-} from '@ariakit/react';
-import type { OptionWithIcon } from '~/common';
-import { SelectTrigger, SelectValue, SelectScrollDownButton } from './Select';
-import { useNestedPopoverStyle } from './OriginalDialog';
-import { cn, disabledInkClasses } from '~/utils';
-import { useCombobox } from '~/hooks';
-
-export default function ComboboxComponent({
- selectedValue,
- displayValue,
- items,
- setValue,
- ariaLabel,
- searchPlaceholder,
- selectPlaceholder,
- isCollapsed,
- SelectIcon,
-}: {
- ariaLabel: string;
- displayValue?: string;
- selectedValue: string;
- searchPlaceholder?: string;
- selectPlaceholder?: string;
- items: OptionWithIcon[] | string[];
- setValue: (value: string) => void;
- isCollapsed: boolean;
- SelectIcon?: React.ReactNode;
-}): JSX.Element {
- const options: OptionWithIcon[] = (items ?? []).map((option: string | OptionWithIcon) => {
- if (typeof option === 'string') {
- return { label: option, value: option };
- }
- return option;
- });
-
- const { open, setOpen, setSearchValue, matches } = useCombobox({
- value: selectedValue,
- options,
- });
- const nestedStyle = useNestedPopoverStyle();
-
- return (
- <RadixSelect.Root
- value={selectedValue}
- onValueChange={setValue}
- open={open}
- /** Hacky fix for radix-ui Android issue: https://github.com/radix-ui/primitives/issues/1658 */
- onOpenChange={() => {
- if (open === true) {
- setOpen(false);
- return;
- }
- setTimeout(() => {
- setOpen(!open);
- }, 75);
- }}
- >
- <ComboboxProvider
- open={open}
- setOpen={setOpen}
- resetValueOnHide
- includesBaseElement={false}
- setValue={(value) => {
- startTransition(() => {
- setSearchValue(value);
- });
- }}
- >
- <SelectTrigger
- aria-label={ariaLabel}
- className={cn(
- '[&_svg]:size-theme-icon flex items-center gap-2 [&_svg]:shrink-0 [&>span]:line-clamp-1 [&>span]:flex [&>span]:w-full [&>span]:items-center [&>span]:gap-1 [&>span]:truncate',
- isCollapsed
- ? 'size-theme-control min-h-theme-target min-w-theme-target flex shrink-0 items-center justify-center p-0 [&>span]:w-auto [&>svg]:hidden'
- : '',
- 'bg-surface-secondary text-text-primary hover:bg-surface-hover focus-visible:ring-focus-control focus-visible:ring-2',
- )}
- >
- <SelectValue placeholder={selectPlaceholder}>
- <div className="assistant-item flex items-center justify-center overflow-hidden rounded-full">
- {SelectIcon ? SelectIcon : <ChevronDownIcon />}
- </div>
- <span className={cn('ms-2 select-none', isCollapsed ? 'hidden' : '')}>
- {selectedValue
- ? (displayValue ?? selectedValue)
- : selectPlaceholder && selectPlaceholder}
- </span>
- </SelectValue>
- </SelectTrigger>
- <RadixSelect.Portal>
- <RadixSelect.Content
- role="dialog"
- aria-label={ariaLabel + 's'}
- position="popper"
- style={nestedStyle}
- className={cn(
- 'border-border-light bg-surface-secondary text-text-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-40 max-h-[52vh] min-w-[8rem] overflow-hidden rounded-md border shadow-md',
- 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
- 'bg-surface-secondary',
- )}
- >
- <RadixSelect.Viewport className="mb-5 h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]">
- <div className="group bg-surface-secondary text-text-primary sticky inset-s-0 top-0 z-10 flex h-12 items-center gap-2 px-3 py-2 duration-300">
- <SearchIcon className="text-text-secondary group-focus-within:text-text-primary group-hover:text-text-primary h-4 w-4 transition-colors duration-300" />
- <Combobox
- autoSelect
- placeholder={searchPlaceholder}
- className="focus:ring-border-medium flex-1 rounded-md border-none bg-transparent px-2.5 py-2 text-sm focus:ring-1 focus:outline-hidden"
- // Ariakit's Combobox manually triggers a blur event on virtually
- // blurred items, making them work as if they had actual DOM
- // focus. These blur events might happen after the corresponding
- // focus events in the capture phase, leading Radix Select to
- // close the popover. This happens because Radix Select relies on
- // the order of these captured events to discern if the focus was
- // outside the element. Since we don't have access to the
- // onInteractOutside prop in the Radix SelectContent component to
- // stop this behavior, we can turn off Ariakit's behavior here.
- onBlurCapture={(event) => {
- event.preventDefault();
- event.stopPropagation();
- }}
- />
- <ComboboxCancel
- hideWhenEmpty={true}
- className="text-text-secondary group-focus-within:text-text-primary group-hover:text-text-primary relative flex h-5 w-5 items-center justify-end transition-colors duration-300"
- />
- </div>
- <ComboboxList className="overflow-y-auto p-1 py-2">
- {matches.map(({ label, value, icon }) => (
- <RadixSelect.Item key={value} value={`${value ?? ''}`} asChild>
- <ComboboxItem
- className={cn(
- 'focus:bg-surface-hover focus:text-text-primary relative flex w-full cursor-pointer items-center rounded-sm py-1.5 ps-2 pe-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
- disabledInkClasses,
- 'hover:bg-surface-hover rounded-lg',
- )}
- /** Hacky fix for radix-ui Android issue: https://github.com/radix-ui/primitives/issues/1658 */
- onTouchEnd={() => {
- setValue(`${value ?? ''}`);
- setOpen(false);
- }}
- >
- <span className="absolute inset-e-2 flex h-3.5 w-3.5 items-center justify-center">
- <RadixSelect.ItemIndicator>
- <CheckIcon className="size-theme-icon" />
- </RadixSelect.ItemIndicator>
- </span>
- <RadixSelect.ItemText>
- <div className="[&_svg]:text-text-primary [&_svg]:size-theme-icon flex items-center justify-center gap-3 [&_svg]:shrink-0">
- <div className="assistant-item overflow-hidden rounded-full">
- {icon && icon}
- </div>
- {label}
- </div>
- </RadixSelect.ItemText>
- </ComboboxItem>
- </RadixSelect.Item>
- ))}
- </ComboboxList>
- </RadixSelect.Viewport>
- <SelectScrollDownButton className="absolute right-0 bottom-0 left-0" />
- </RadixSelect.Content>
- </RadixSelect.Portal>
- </ComboboxProvider>
- </RadixSelect.Root>
- );
-}
diff --git a/packages/client/src/components/Dropdown.css b/packages/client/src/components/Dropdown.css
index b1c9707baa..f8cf5228b9 100644
--- a/packages/client/src/components/Dropdown.css
+++ b/packages/client/src/components/Dropdown.css
@@ -31,6 +31,20 @@
/* Elevation here is a black shadow, which carries no separation at all against
* a pure black surface. Lives with the primitive rather than in the app
* stylesheet, which the published package does not include. */
+/* A form-field list takes the theme's list roles: `listMinWidth` (0 sizes it by its
+ * trigger) and `listMaxHeight`, never past the room the popover leaves below or above it. */
+.popover-ui[data-variant='field'] {
+ min-width: var(--theme-list-min-width, 8rem);
+ max-height: min(var(--theme-list-max-height, 24rem), var(--popover-available-height, 100dvh));
+}
+
+/* ...and is never narrower than its trigger. The floor sits on Ariakit's wrapper, where the
+ * anchor width is set and which the list fills, because a role of `0` (unitless) cannot be
+ * combined with a length in `max()`. */
+.popover-field-wrapper {
+ min-width: var(--popover-anchor-width, 0px);
+}
+
html.high-contrast .popover-ui {
border: 1px solid rgb(var(--border-medium));
box-shadow: none;
diff --git a/packages/client/src/components/Dropdown.tsx b/packages/client/src/components/Dropdown.tsx
index b9fe26a702..32b96bccf0 100644
--- a/packages/client/src/components/Dropdown.tsx
+++ b/packages/client/src/components/Dropdown.tsx
@@ -4,6 +4,7 @@ import { matchSorter } from 'match-sorter';
import * as Select from '@ariakit/react/select';
import * as Combobox from '@ariakit/react/combobox';
import type { Option } from '~/common';
+import { useDialogDepth, usePopoverZIndex } from './OriginalDialog';
import { cn, disabledFillClasses } from '~/utils';
import { focusOutlineRole } from './Focus';
import { fieldControl } from './Field';
@@ -29,6 +30,8 @@ interface DropdownProps {
ariaLabel?: string;
'aria-labelledby'?: string;
'aria-describedby'?: string;
+ /** Portals the list out of the trigger's parent. Defaults to `true`, and to `false` inside a
+ * dialog, whose focus trap and `aria-hidden` pass would cut a portaled list off. */
portal?: boolean;
/** `field` matches Input; `compact` supplies the small toolbar-control recipe. */
variant?: 'default' | 'field' | 'compact';
@@ -77,7 +80,7 @@ const Dropdown: React.FC<DropdownProps> = ({
ariaLabel,
'aria-labelledby': ariaLabelledBy,
'aria-describedby': ariaDescribedBy,
- portal = true,
+ portal,
variant = 'default',
shape = 'theme',
portalElement,
@@ -87,6 +90,8 @@ const Dropdown: React.FC<DropdownProps> = ({
searchEmptyText,
}) => {
const valueId = `${useId()}value`;
+ const inDialog = useDialogDepth() > 0;
+ const popoverZIndex = usePopoverZIndex();
const [searchValue, setSearchValue] = useState('');
const handleChange = (value: string) => {
@@ -141,14 +146,18 @@ const Dropdown: React.FC<DropdownProps> = ({
{option.icon != null && <span>{option.icon as React.ReactNode}</span>}
<span className="block truncate">{option.label}</span>
{selectedValue === option.value && (
- <span className="ms-auto ps-2">
+ <span className="ms-auto shrink-0 ps-2">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
- className="icon-md block group-hover:hidden"
+ /* A field list's check follows the theme's icon size role, as the form select did. */
+ className={cn(
+ 'block group-hover:hidden',
+ variant === 'field' ? 'size-theme-icon' : 'icon-md',
+ )}
aria-hidden="true"
>
<path
@@ -216,9 +225,18 @@ const Dropdown: React.FC<DropdownProps> = ({
{!iconOnly && <Select.SelectArrow className="shrink-0" />}
</Select.Select>
<Select.SelectPopover
- portal={portal}
+ /* A modal dialog traps focus inside its own DOM and hides every other body
+ child from assistive technology, so a list portaled out of it can be
+ neither reached by keyboard nor read. Inside a dialog the list renders in
+ place, as Ariakit menus already do, unless the caller asks otherwise. */
+ portal={portal ?? (portalElement != null || !inDialog)}
portalElement={portalElement}
store={selectProps}
+ /* Inside a dialog the list layers over it; elsewhere `z-40` applies. Pointer
+ events are already re-enabled by the class below. */
+ style={{ zIndex: inDialog ? popoverZIndex : undefined }}
+ data-variant={variant}
+ wrapperProps={variant === 'field' ? { className: 'popover-field-wrapper' } : undefined}
className={cn(
// `className` sizes the TRIGGER only (applied above on Select.Select).
// Forwarding it here too meant a caller's trigger height (a fixed height utility)
diff --git a/packages/client/src/components/Select.spec.tsx b/packages/client/src/components/Select.spec.tsx
deleted file mode 100644
index 230360d313..0000000000
--- a/packages/client/src/components/Select.spec.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import '@testing-library/jest-dom';
-import { render, screen } from '@testing-library/react';
-import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './Select';
-
-describe('SelectTrigger', () => {
- /** The trigger hid the outline on every focus and drew nothing in its place, so a keyboard
- * user could not see which control held focus. */
- it('draws keyboard focus in the control focus role', () => {
- render(
- <Select>
- <SelectTrigger aria-label="Model">
- <SelectValue placeholder="Pick one" />
- </SelectTrigger>
- </Select>,
- );
-
- const trigger = screen.getByRole('combobox', { name: 'Model' });
- expect(trigger).toHaveClass(
- 'focus-visible:outline-hidden',
- 'focus-visible:ring-2',
- 'focus-visible:ring-focus-control',
- );
- expect(trigger).not.toHaveClass('focus:outline-hidden');
- });
-});
-
-describe('SelectContent', () => {
- /** The list's width floor and scroll cap are theme roles, so a theme can retune both. */
- it('bounds the list with the list size roles', () => {
- render(
- <Select open value="one">
- <SelectTrigger aria-label="Model">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="one">One</SelectItem>
- </SelectContent>
- </Select>,
- );
-
- expect(screen.getByRole('listbox')).toHaveClass('min-w-theme-list', 'max-h-theme-list');
- });
-});
diff --git a/packages/client/src/components/Select.tsx b/packages/client/src/components/Select.tsx
deleted file mode 100644
index 8baf238c1a..0000000000
--- a/packages/client/src/components/Select.tsx
+++ /dev/null
@@ -1,192 +0,0 @@
-import * as React from 'react';
-import * as SelectPrimitive from '@radix-ui/react-select';
-import { CaretSortIcon, CheckIcon, ChevronDownIcon, ChevronUpIcon } from '@radix-ui/react-icons';
-import { cn, disabledFillClasses, disabledInkClasses } from '~/utils';
-import { useDialogDepth, usePopoverZIndex } from './OriginalDialog';
-
-// @ts-ignore - Radix UI type conflicts with React types
-const Select: React.FC<SelectPrimitive.SelectProps> = SelectPrimitive.Root;
-
-// @ts-ignore - Radix UI type conflicts with React types
-const SelectGroup: React.ForwardRefExoticComponent<
- SelectPrimitive.SelectGroupProps & React.RefAttributes<HTMLDivElement>
-> = SelectPrimitive.Group;
-
-const SelectValue: React.ForwardRefExoticComponent<
- SelectPrimitive.SelectValueProps & React.RefAttributes<HTMLSpanElement>
-> = SelectPrimitive.Value;
-
-// @ts-ignore - Radix UI type conflicts with React types
-const SelectTrigger: React.ForwardRefExoticComponent<
- Omit<SelectPrimitive.SelectTriggerProps & React.RefAttributes<HTMLButtonElement>, 'ref'> &
- React.RefAttributes<HTMLButtonElement>
-> = React.forwardRef<
- React.ElementRef<typeof SelectPrimitive.Trigger>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
->(({ className = '', children, ...props }, ref) => (
- <SelectPrimitive.Trigger
- ref={ref}
- className={cn(
- 'border-border-control ring-offset-surface-primary placeholder:text-text-secondary focus-visible:ring-focus-control h-theme-control flex w-full items-center justify-between rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs focus-visible:ring-2 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
- disabledFillClasses,
- 'hover:bg-surface-hover rounded-lg',
- className,
- )}
- {...props}
- >
- {children}
- <SelectPrimitive.Icon asChild>
- <CaretSortIcon className="size-theme-icon opacity-50" />
- </SelectPrimitive.Icon>
- </SelectPrimitive.Trigger>
-));
-SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
-
-const SelectScrollUpButton: React.ForwardRefExoticComponent<
- Omit<SelectPrimitive.SelectScrollUpButtonProps & React.RefAttributes<HTMLDivElement>, 'ref'> &
- React.RefAttributes<HTMLDivElement>
-> = React.forwardRef<
- React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
->(({ className = '', ...props }, ref) => (
- <SelectPrimitive.ScrollUpButton
- ref={ref}
- className={cn('flex cursor-default items-center justify-center py-1', className)}
- {...props}
- >
- <ChevronUpIcon />
- </SelectPrimitive.ScrollUpButton>
-));
-SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
-
-const SelectScrollDownButton: React.ForwardRefExoticComponent<
- Omit<SelectPrimitive.SelectScrollDownButtonProps & React.RefAttributes<HTMLDivElement>, 'ref'> &
- React.RefAttributes<HTMLDivElement>
-> = React.forwardRef<
- React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
->(({ className = '', ...props }, ref) => (
- <SelectPrimitive.ScrollDownButton
- ref={ref}
- className={cn('flex cursor-default items-center justify-center py-1', className)}
- {...props}
- >
- <ChevronDownIcon />
- </SelectPrimitive.ScrollDownButton>
-));
-SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
-
-const SelectContent: React.ForwardRefExoticComponent<
- Omit<SelectPrimitive.SelectContentProps & React.RefAttributes<HTMLDivElement>, 'ref'> &
- React.RefAttributes<HTMLDivElement>
-> = React.forwardRef<
- React.ElementRef<typeof SelectPrimitive.Content>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
->(({ className = '', children, position = 'popper', style, ...props }, ref) => {
- const nested = useDialogDepth() > 0;
- const zIndex = usePopoverZIndex();
- return (
- <SelectPrimitive.Portal>
- <SelectPrimitive.Content
- ref={ref}
- /* Inside a dialog the list must layer over it and accept pointer events
- (see `useNestedPopoverStyle`); elsewhere `z-40` applies. */
- style={{ zIndex: nested ? zIndex : undefined, ...style }}
- className={cn(
- 'border-border-light bg-surface-secondary text-text-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 max-h-theme-list min-w-theme-list relative z-40 overflow-hidden rounded-md border shadow-md',
- position === 'popper'
- ? 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1'
- : '',
- nested && 'pointer-events-auto',
- className,
- )}
- position={position}
- {...props}
- >
- <SelectScrollUpButton />
- <SelectPrimitive.Viewport
- className={cn(
- 'p-1',
- position === 'popper'
- ? 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
- : '',
- )}
- >
- {children}
- </SelectPrimitive.Viewport>
- <SelectScrollDownButton />
- </SelectPrimitive.Content>
- </SelectPrimitive.Portal>
- );
-});
-SelectContent.displayName = SelectPrimitive.Content.displayName;
-
-const SelectLabel: React.ForwardRefExoticComponent<
- Omit<SelectPrimitive.SelectLabelProps & React.RefAttributes<HTMLDivElement>, 'ref'> &
- React.RefAttributes<HTMLDivElement>
-> = React.forwardRef<
- React.ElementRef<typeof SelectPrimitive.Label>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
->(({ className = '', ...props }, ref) => (
- <SelectPrimitive.Label
- ref={ref}
- className={cn('px-2 py-1.5 text-sm font-semibold', className)}
- {...props}
- />
-));
-SelectLabel.displayName = SelectPrimitive.Label.displayName;
-
-const SelectItem: React.ForwardRefExoticComponent<
- Omit<SelectPrimitive.SelectItemProps & React.RefAttributes<HTMLDivElement>, 'ref'> &
- React.RefAttributes<HTMLDivElement>
-> = React.forwardRef<
- React.ElementRef<typeof SelectPrimitive.Item>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
->(({ className = '', children, ...props }, ref) => (
- <SelectPrimitive.Item
- ref={ref}
- className={cn(
- 'focus:bg-surface-hover focus:text-text-primary relative flex w-full cursor-pointer items-center rounded-sm py-1.5 ps-2 pe-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
- disabledInkClasses,
- 'hover:bg-surface-hover rounded-lg',
- className,
- )}
- {...props}
- >
- <span className="size-theme-icon absolute inset-e-2 flex items-center justify-center">
- <SelectPrimitive.ItemIndicator>
- <CheckIcon className="size-theme-icon" />
- </SelectPrimitive.ItemIndicator>
- </span>
- <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
- </SelectPrimitive.Item>
-));
-SelectItem.displayName = SelectPrimitive.Item.displayName;
-
-const SelectSeparator: React.ForwardRefExoticComponent<
- Omit<SelectPrimitive.SelectSeparatorProps & React.RefAttributes<HTMLDivElement>, 'ref'> &
- React.RefAttributes<HTMLDivElement>
-> = React.forwardRef<
- React.ElementRef<typeof SelectPrimitive.Separator>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
->(({ className = '', ...props }, ref) => (
- <SelectPrimitive.Separator
- ref={ref}
- className={cn('bg-surface-tertiary -mx-1 my-1 h-px', className)}
- {...props}
- />
-));
-SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
-
-export {
- Select,
- SelectGroup,
- SelectValue,
- SelectTrigger,
- SelectContent,
- SelectLabel,
- SelectItem,
- SelectSeparator,
- SelectScrollUpButton,
- SelectScrollDownButton,
-};
diff --git a/packages/client/src/components/__tests__/dialogPopoverFocus.spec.tsx b/packages/client/src/components/__tests__/dialogPopoverFocus.spec.tsx
index bb9fee2153..487f505670 100644
--- a/packages/client/src/components/__tests__/dialogPopoverFocus.spec.tsx
+++ b/packages/client/src/components/__tests__/dialogPopoverFocus.spec.tsx
@@ -1,36 +1,49 @@
import '@testing-library/jest-dom';
-import { render, screen } from '@testing-library/react';
-import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../Select';
+import { act, fireEvent, render, screen } from '@testing-library/react';
import { OGDialog, OGDialogContent } from '../OriginalDialog';
+import Dropdown from '../Dropdown';
/**
- * A dialog traps focus, and a popover opened inside it is expected to take that
- * trap over — Radix does this by pausing the outer scope when the inner one
- * mounts. Both scopes have to come from the same copy of
- * `@radix-ui/react-focus-scope` for that hand-off to happen; with duplicates,
- * the dialog never yields and the popover's options cannot be reached by
- * keyboard. `radixLayers.spec.ts` pins the packaging invariant; this asserts
- * the behaviour it exists for.
+ * A dialog traps focus inside its own DOM and hides every other body child from
+ * assistive technology. A select list portaled out of it could be neither reached
+ * by keyboard nor read, so inside a dialog `Dropdown` renders the list in place:
+ * the list is exposed, and the keyboard can move through it and pick an option.
*/
-it('lets a portaled select option hold focus inside a dialog', () => {
+it('lets the keyboard pick a select option inside a dialog', async () => {
+ const onChange = jest.fn();
render(
<OGDialog open>
<OGDialogContent>
- <Select open value="ask">
- <SelectTrigger aria-label="Execution environment">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="ask">Ask before changes</SelectItem>
- <SelectItem value="accept">Accept edits</SelectItem>
- </SelectContent>
- </Select>
+ <Dropdown
+ value="ask"
+ onChange={onChange}
+ ariaLabel="Execution environment"
+ options={[
+ { value: 'ask', label: 'Ask before changes' },
+ { value: 'accept', label: 'Accept edits' },
+ ]}
+ />
</OGDialogContent>
</OGDialog>,
);
- const option = screen.getByRole('option', { name: 'Accept edits' });
- option.focus();
+ const trigger = screen.getByRole('combobox', { name: 'Execution environment' });
+ await act(async () => {
+ trigger.focus();
+ fireEvent.click(trigger);
+ });
+ const listbox = await screen.findByRole('listbox');
+ expect(screen.getByRole('dialog')).toContainElement(listbox);
+ expect(document.activeElement).toBe(listbox);
- expect(document.activeElement).toBe(option);
+ await act(async () => {
+ fireEvent.keyDown(listbox, { key: 'ArrowDown' });
+ });
+ const active = listbox.getAttribute('aria-activedescendant');
+ expect(active).toBe(screen.getByRole('option', { name: 'Accept edits' }).id);
+
+ await act(async () => {
+ fireEvent.keyDown(listbox, { key: 'Enter' });
+ });
+ expect(onChange).toHaveBeenCalledWith('accept');
});
diff --git a/packages/client/src/components/__tests__/popoverLayering.spec.tsx b/packages/client/src/components/__tests__/popoverLayering.spec.tsx
index b5f291cd92..84752462a5 100644
--- a/packages/client/src/components/__tests__/popoverLayering.spec.tsx
+++ b/packages/client/src/components/__tests__/popoverLayering.spec.tsx
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
-import { render, screen } from '@testing-library/react';
+import { act, fireEvent, render, screen } from '@testing-library/react';
import { HoverCard, HoverCardContent, HoverCardPortal, HoverCardTrigger } from '../HoverCard';
-import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../Select';
import { DialogLayer, OGDialog, OGDialogContent } from '../OriginalDialog';
+import Dropdown from '../Dropdown';
/**
* A portaled popover lands beside the dialog in the DOM, not inside it, so its
@@ -24,17 +24,23 @@ function zIndexOf(element: HTMLElement): number {
function EnvironmentSelect() {
return (
- <Select open value="attached">
- <SelectTrigger aria-label="Execution environment">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="attached">Attached VM</SelectItem>
- </SelectContent>
- </Select>
+ <Dropdown
+ value="attached"
+ onChange={() => undefined}
+ ariaLabel="Execution environment"
+ options={[{ value: 'attached', label: 'Attached VM' }]}
+ />
);
}
+/** The Ariakit select opens from its trigger rather than a controlled `open` prop. */
+async function openSelect() {
+ await act(async () => {
+ fireEvent.click(screen.getByRole('combobox', { name: 'Execution environment' }));
+ });
+ return screen.findByRole('listbox');
+}
+
function HelpHoverCard() {
return (
<HoverCard open>
@@ -47,7 +53,7 @@ function HelpHoverCard() {
}
describe('portaled popovers inside a dialog', () => {
- it('opens a select above the dialog content it belongs to', () => {
+ it('opens a select above the dialog content it belongs to', async () => {
render(
<OGDialog open>
<OGDialogContent>
@@ -56,23 +62,23 @@ describe('portaled popovers inside a dialog', () => {
</OGDialog>,
);
- const listbox = screen.getByRole('listbox');
+ const listbox = await openSelect();
expect(zIndexOf(listbox)).toBeGreaterThan(DIALOG_CONTENT_Z_INDEX);
- expect(listbox).toHaveClass('pointer-events-auto');
+ expect(listbox).toHaveClass('[pointer-events:auto]');
});
/** The Settings dialog is a Headless UI panel at z-50, not an OGDialog, so it declares its own
* dialog level (berry-13/LibreChat#249). */
- it('opens a select above a non-OGDialog panel that declares a dialog layer', () => {
+ it('opens a select above a non-OGDialog panel that declares a dialog layer', async () => {
render(
<DialogLayer>
<EnvironmentSelect />
</DialogLayer>,
);
- const listbox = screen.getByRole('listbox');
+ const listbox = await openSelect();
expect(zIndexOf(listbox)).toBeGreaterThan(50);
- expect(listbox).toHaveClass('pointer-events-auto');
+ expect(listbox).toHaveClass('[pointer-events:auto]');
});
it('opens a hover card above the dialog content it belongs to', () => {
@@ -90,14 +96,11 @@ describe('portaled popovers inside a dialog', () => {
});
/** Outside a dialog the CSS layer still decides, so a consumer that raises it
- * by class — `z-[999]` to clear the legacy `Dialog` — keeps that override.
+ * by class keeps that override.
*
- * Only the absence of OUR inline z-index is asserted. `pointer-events` is
- * Radix's to set out here: a select disables outside pointer events for its
- * own layer stack, and whether a sibling popover then reads `auto` depends
- * on whether the two share a copy of `react-dismissable-layer` — which is a
- * packaging fact, not this hook's contract. */
- it('leaves the CSS layer alone outside any dialog', () => {
+ * Only the absence of OUR inline z-index is asserted; the list keeps its
+ * `z-40` class, which a consumer can still raise. */
+ it('leaves the CSS layer alone outside any dialog', async () => {
render(
<>
<EnvironmentSelect />
@@ -105,11 +108,10 @@ describe('portaled popovers inside a dialog', () => {
</>,
);
- const listbox = screen.getByRole('listbox');
+ const listbox = await openSelect();
const card = screen.getByText('What stateful sessions do');
expect(listbox.style.zIndex).toBe('');
expect(listbox).toHaveClass('z-40');
- expect(listbox).not.toHaveClass('pointer-events-auto');
expect(card.style.zIndex).toBe('');
expect(card).toHaveClass('z-50');
});
diff --git a/packages/client/src/components/index.ts b/packages/client/src/components/index.ts
index 37f6c2b3f5..b488f61c43 100644
--- a/packages/client/src/components/index.ts
+++ b/packages/client/src/components/index.ts
@@ -42,11 +42,9 @@ export * from './InputOTP';
export * from './IconButton';
export * from './MultiSearch';
export * from './Resizable';
-export * from './Select';
export { default as Radio } from './Radio';
export { default as Badge } from './Badge';
export { default as Avatar } from './Avatar';
-export { default as Combobox } from './Combobox';
export { default as Composer } from './Composer';
export { SendActions } from './SendActions';
export type { SendAction } from './SendActions';
diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.md
index 80d8308e3a..d6b0d40567 100644
--- a/packages/client/src/theme/README.md
+++ b/packages/client/src/theme/README.md
@@ -392,7 +392,7 @@ Each status family has a foreground, a `-subtle` background, a `-border`, and a
the dialog's close icon, `h-theme-field-lg` (`fieldHeightLg`) the large `title`
input, and `h-theme-target` the switch's hit area, and `min-w-theme-tab` (`tabMinWidth`, `0` to size a tab by its label) the tab
trigger. `min-w-theme-list` and `max-h-theme-list` (`listMinWidth`, `0` to size the list by
- its trigger, and `listMaxHeight`, 8 to 40rem or `none`) bound the Select's list, which never
+ its trigger, and `listMaxHeight`, 8 to 40rem or `none`) bound a field `Dropdown`'s list, which never
grows past the room the popper leaves between its trigger and the viewport's edge, so `none`
drops the fixed cap and keeps only that one. Every default is the size the primitive drew before. The icon and checkbox roles
are bounded to the room their layouts leave: `iconSize` 0.75 to 1.25rem, `iconSizeMd` (the
diff --git a/packages/client/src/theme/primitives.spec.ts b/packages/client/src/theme/primitives.spec.ts
index dcc2d7575a..96f7021ba2 100644
--- a/packages/client/src/theme/primitives.spec.ts
+++ b/packages/client/src/theme/primitives.spec.ts
@@ -17,7 +17,7 @@ const repoRoot = join(__dirname, '../../../..');
const primitives: Record<string, string[]> = {
Button: ['Button.tsx'],
Input: ['Input.tsx', 'Field.ts'],
- Select: ['Select.tsx', 'Dropdown.tsx', 'Dropdown.css'],
+ Select: ['Dropdown.tsx', 'Dropdown.css'],
Dialog: ['OriginalDialog.tsx', 'OGDialogTemplate.tsx', 'Dialog.tsx'],
Menu: ['DropdownPopup.tsx', 'Dropdown.css'],
Tabs: ['Tabs.tsx'],
diff --git a/packages/client/src/theme/tailwind.spec.js b/packages/client/src/theme/tailwind.spec.js
index c1bad6ac98..e5fb71a1ab 100644
--- a/packages/client/src/theme/tailwind.spec.js
+++ b/packages/client/src/theme/tailwind.spec.js
@@ -247,9 +247,7 @@ describe('LibreChat Tailwind preset', () => {
expect(css).toContain(`var(${property}, ${fallback})`);
});
- expect(rule(css, 'max-h-theme-list')).toContain(
- 'var(--radix-select-content-available-height, 100dvh)',
- );
+ expect(rule(css, 'max-h-theme-list')).toContain('var(--popover-available-height, 100dvh)');
/** The tap-target floor is the role's reason to exist, so the floor itself is asserted
* rather than only the control-height variable it is built from. */
diff --git a/packages/client/tailwind.preset.cjs b/packages/client/tailwind.preset.cjs
index 246857fc34..42759db93d 100644
--- a/packages/client/tailwind.preset.cjs
+++ b/packages/client/tailwind.preset.cjs
@@ -53,14 +53,14 @@ module.exports = {
'theme-target': '24px',
/** The narrowest a tab trigger draws. */
'theme-tab': 'var(--theme-tab-min-width, 100px)',
- /** The narrowest a Select's list draws. */
+ /** The narrowest a field Dropdown's list draws. */
'theme-list': 'var(--theme-list-min-width, 8rem)',
},
maxHeight: {
- /** The tallest a Select's list draws before it scrolls, never past the room the popper
- * leaves between its trigger and the viewport's edge. */
+ /** The tallest a field Dropdown's list draws before it scrolls, never past the room the
+ * popover leaves between its trigger and the viewport's edge. */
'theme-list':
- 'min(var(--theme-list-max-height, 24rem), var(--radix-select-content-available-height, 100dvh))',
+ 'min(var(--theme-list-max-height, 24rem), var(--popover-available-height, 100dvh))',
},
inset: {
/** Where a sign-in label rests in its field: centered 2px low, as on the stock 44px field,