fix: Layer Settings Dialog Popovers Above Its Panel (#16720)

The Settings dialog is a Headless UI panel at z-50, not an OGDialog, so it set no dialog depth and its Select lists kept their z-40 layer, opening invisibly behind the panel. A new DialogLayer counts it as one dialog level, so popovers inside it take the depth-aware z-index they get inside an OGDialog.
This commit is contained in:
Marco Beretta 2026-10-03 15:47:53 +02:00 • committed by GitHub
parent f156160c99
commit 2ea44e0d67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 106 additions and 36 deletions

View file

@ -2,7 +2,7 @@ import { useState } from 'react';
import * as Tabs from '@radix-ui/react-tabs';
import { X, ChevronLeft } from 'lucide-react';
import { SettingsTabValues } from 'librechat-data-provider';
import { Button, useMediaQuery, DIALOG_SCRIM_CLASS } from '@librechat/client';
import { Button, DialogLayer, useMediaQuery, DIALOG_SCRIM_CLASS } from '@librechat/client';
import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild } from '@headlessui/react';
import type { TDialogProps } from '~/common';
import type { SettingsTab } from './types';
@ -101,38 +101,42 @@ export default function SettingsDialog({ open, onOpenChange }: TDialogProps) {
<X className="h-5 w-5" aria-hidden="true" />
</Button>
</DialogTitle>
<Tabs.Root
value={effectiveTab}
onValueChange={(v) => setActiveTab(v as SettingsTab)}
orientation="vertical"
className="flex flex-1 flex-col gap-4 overflow-hidden p-5 md:flex-row md:gap-6"
>
{showSidebar && (
<Sidebar
ctx={ctx}
query={query}
onQueryChange={setQuery}
onSelectTab={selectTab}
showChevron={isSmallScreen}
hideTabs={hideTabs}
/>
)}
{showContent && (
<div className="flex-1 overflow-y-auto md:pr-1">
{searching ? (
<Content activeTab={effectiveTab} query={query} ctx={ctx} />
) : (
<Tabs.Content
value={effectiveTab}
tabIndex={-1}
className="focus:outline-hidden"
>
{/* A Headless UI panel, so it counts itself as a dialog level for the popovers its
settings open (Select lists, menus, tooltips) to layer above it. */}
<DialogLayer>
<Tabs.Root
value={effectiveTab}
onValueChange={(v) => setActiveTab(v as SettingsTab)}
orientation="vertical"
className="flex flex-1 flex-col gap-4 overflow-hidden p-5 md:flex-row md:gap-6"
>
{showSidebar && (
<Sidebar
ctx={ctx}
query={query}
onQueryChange={setQuery}
onSelectTab={selectTab}
showChevron={isSmallScreen}
hideTabs={hideTabs}
/>
)}
{showContent && (
<div className="flex-1 overflow-y-auto md:pr-1">
{searching ? (
<Content activeTab={effectiveTab} query={query} ctx={ctx} />
</Tabs.Content>
)}
</div>
)}
</Tabs.Root>
) : (
<Tabs.Content
value={effectiveTab}
tabIndex={-1}
className="focus:outline-hidden"
>
<Content activeTab={effectiveTab} query={query} ctx={ctx} />
</Tabs.Content>
)}
</div>
)}
</Tabs.Root>
</DialogLayer>
</DialogPanel>
</div>
</TransitionChild>

View file

@ -37,8 +37,15 @@ async function useTheme(page: Page, definition?: { name: string }) {
}, definition ?? null);
}
/** The stateful workspace Select only renders when the agents endpoint offers stateful sessions. */
/** The stateful workspace Select only renders when the agents endpoint offers stateful sessions;
* a pick's save is answered here so it stands without a configured code environment. */
async function offerStatefulSessions(page: Page) {
await page.route('**/api/user/preferences', async (route) => {
if (route.request().method() === 'GET') {
return route.continue();
}
await route.fulfill({ json: { preferences: route.request().postDataJSON() } });
});
await page.route('**/api/endpoints', async (route) => {
const response = await route.fetch();
const endpoints = await response.json();
@ -49,8 +56,7 @@ async function offerStatefulSessions(page: Page) {
});
}
/** Opens the Settings Select's list. Only its geometry is read, which does not depend on how the
* list layers against the Settings dialog. */
/** Opens the stateful workspace Select's list in the Settings dialog. */
async function openWorkspaceSelect(page: Page) {
await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
/** Mobile keeps the account menu in the drawer. */
@ -138,6 +144,43 @@ test.describe('popovers inside a modal dialog', () => {
await openWorkspaceSelect(page);
await expectIndicator(page, '20px');
});
/** The Settings dialog is a Headless UI panel, not an OGDialog; before it declared a dialog
* level its Select 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
* a click falls through to a list nobody can see. The probe turns pointer events back on
* everywhere so `elementFromPoint` reports what is painted on top. */
test('a Select in the Settings dialog opens on top of it and takes a pick @scenario:settings-select-opens-on-top', async ({
page,
}) => {
await offerStatefulSessions(page);
await useTheme(page);
await openWorkspaceSelect(page);
const option = page.getByRole('option', { name: 'Conversation workspace' });
const box = await option.boundingBox();
expect(box).not.toBeNull();
const x = (box?.x ?? 0) + (box?.width ?? 0) / 2;
const y = (box?.y ?? 0) + (box?.height ?? 0) / 2;
const painted = await page.evaluate(
([px, py]) => {
const probe = document.createElement('style');
probe.textContent = '* { pointer-events: auto !important; }';
document.head.append(probe);
const top = document.elementFromPoint(px, py);
probe.remove();
return top?.closest('[role="listbox"]') != null;
},
[x, y],
);
expect(painted).toBe(true);
await page.mouse.click(x, y);
await expect(page.getByRole('listbox')).toBeHidden();
await expect(page.getByTestId('default-stateful-workspace')).toHaveText(
'Conversation workspace',
);
});
});
/** Sets both list roles apart from their defaults, so a list still drawing a fixed size shows. */

View file

@ -12,6 +12,15 @@ const DialogDepthContext = React.createContext(0);
/** Current OGDialog nesting depth (0 when rendered outside any dialog). */
export const useDialogDepth = (): number => React.useContext(DialogDepthContext);
/**
* Counts a dialog that is not an OGDialog, such as a Headless UI panel, as one dialog level, so
* the popovers portaled out of it layer above it the way they do inside an OGDialog.
*/
export const DialogLayer = ({ children }: { children: React.ReactNode }): React.JSX.Element => {
const depth = React.useContext(DialogDepthContext);
return <DialogDepthContext.Provider value={depth + 1}>{children}</DialogDepthContext.Provider>;
};
/**
* z-index for a portaled popover so it renders above the dialog it lives in.
* Outside any dialog (depth 0) it falls back to a low default (50).

View file

@ -2,7 +2,7 @@ import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { HoverCard, HoverCardContent, HoverCardPortal, HoverCardTrigger } from '../HoverCard';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../Select';
import { OGDialog, OGDialogContent } from '../OriginalDialog';
import { DialogLayer, OGDialog, OGDialogContent } from '../OriginalDialog';
/**
* A portaled popover lands beside the dialog in the DOM, not inside it, so its
@ -61,6 +61,20 @@ describe('portaled popovers inside a dialog', () => {
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', () => {
render(
<DialogLayer>
<EnvironmentSelect />
</DialogLayer>,
);
const listbox = screen.getByRole('listbox');
expect(zIndexOf(listbox)).toBeGreaterThan(50);
expect(listbox).toHaveClass('pointer-events-auto');
});
it('opens a hover card above the dialog content it belongs to', () => {
render(
<OGDialog open>