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

🪟 fix: Layer Tooltips Above the Popups They Open Inside (#16791)

Marco Beretta3f094468b0fd
diff --git a/client/src/components/Chat/Input/TokenUsage/CompactAction.tsx b/client/src/components/Chat/Input/TokenUsage/CompactAction.tsx
index 47a7be2a62..d9123a1a21 100644
--- a/client/src/components/Chat/Input/TokenUsage/CompactAction.tsx
+++ b/client/src/components/Chat/Input/TokenUsage/CompactAction.tsx
@@ -3,6 +3,9 @@ import { ScrollText } from 'lucide-react';
import { Button, Spinner, TooltipAnchor } from '@librechat/client';
import { useLocalize } from '~/hooks';
+/** The usage popover sits at z-200, above the tooltip default (150). */
+const TOOLTIP_Z_INDEX = 250;
+
interface CompactActionProps {
compact: () => void;
canCompact: boolean;
@@ -23,6 +26,7 @@ function CompactAction({ compact, canCompact, isCompacting }: CompactActionProps
<div>
<TooltipAnchor
side="bottom"
+ zIndex={TOOLTIP_Z_INDEX}
description={description}
render={
<Button
diff --git a/client/src/components/Chat/Messages/Content/DialogImage.tsx b/client/src/components/Chat/Messages/Content/DialogImage.tsx
index 7d735ffd6f..06186638d1 100644
--- a/client/src/components/Chat/Messages/Content/DialogImage.tsx
+++ b/client/src/components/Chat/Messages/Content/DialogImage.tsx
@@ -5,6 +5,9 @@ import { X, ArrowDownToLine, RotateCcw } from 'lucide-react';
import { Button, MorphIcon, TooltipAnchor, useMediaQuery, useRemScale } from '@librechat/client';
import { useLocalize } from '~/hooks';
+/** The lightbox is z-250 and not an OGDialog, so its tooltips would keep the default 150 and sit behind it. */
+const TOOLTIP_Z_INDEX = 300;
+
const imageSizeCache = new Map<string, string>();
const getQualityStyles = (quality: string): string => {
@@ -282,6 +285,7 @@ export default function DialogImage({
{/* Close button - top left */}
<div className="absolute top-4 left-4 z-20">
<TooltipAnchor
+ zIndex={TOOLTIP_Z_INDEX}
description={localize('com_ui_close')}
render={
<Button
@@ -303,6 +307,7 @@ export default function DialogImage({
>
{zoom > 1 && (
<TooltipAnchor
+ zIndex={TOOLTIP_Z_INDEX}
description={localize('com_ui_reset_zoom')}
render={
<Button
@@ -317,6 +322,7 @@ export default function DialogImage({
/>
)}
<TooltipAnchor
+ zIndex={TOOLTIP_Z_INDEX}
description={localize('com_ui_download')}
render={
<Button
@@ -331,6 +337,7 @@ export default function DialogImage({
/>
{showDetails && (
<TooltipAnchor
+ zIndex={TOOLTIP_Z_INDEX}
description={imageDetailsLabel}
render={
<Button
diff --git a/client/src/components/Chat/Messages/Content/__tests__/DialogImage.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/DialogImage.test.tsx
new file mode 100644
index 0000000000..f870192e9c
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/__tests__/DialogImage.test.tsx
@@ -0,0 +1,48 @@
+import React from 'react';
+import { render, screen, fireEvent } from '@testing-library/react';
+import DialogImage from '../DialogImage';
+
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+}));
+
+jest.mock('@librechat/client', () => {
+ const actual = jest.requireActual<typeof import('@librechat/client')>('@librechat/client');
+ return {
+ ...actual,
+ useRemScale: () => 1,
+ useMediaQuery: () => false,
+ };
+});
+
+/** The lightbox is a raw Radix dialog at z-250, not an OGDialog, so a tooltip left on the
+ * stylesheet default (150) would paint behind its overlay. */
+const LIGHTBOX_Z_INDEX = 250;
+
+describe('DialogImage tooltips', () => {
+ it('layers the close tooltip above the lightbox', async () => {
+ render(
+ <DialogImage isOpen onOpenChange={jest.fn()} src="/media.png" downloadImage={jest.fn()} />,
+ );
+
+ const close = screen.getByRole('button', { name: 'com_ui_close' });
+ fireEvent.mouseEnter(close);
+ fireEvent.mouseMove(close);
+
+ const tooltip = await screen.findByRole('tooltip', undefined, { timeout: 3000 });
+ expect(Number(tooltip.style.zIndex)).toBeGreaterThan(LIGHTBOX_Z_INDEX);
+ });
+
+ it('layers the download tooltip above the lightbox', async () => {
+ render(
+ <DialogImage isOpen onOpenChange={jest.fn()} src="/media.png" downloadImage={jest.fn()} />,
+ );
+
+ const download = screen.getByRole('button', { name: 'com_ui_download' });
+ fireEvent.mouseEnter(download);
+ fireEvent.mouseMove(download);
+
+ const tooltip = await screen.findByRole('tooltip', undefined, { timeout: 3000 });
+ expect(Number(tooltip.style.zIndex)).toBeGreaterThan(LIGHTBOX_Z_INDEX);
+ });
+});
diff --git a/packages/client/src/components/Tooltip.spec.tsx b/packages/client/src/components/Tooltip.spec.tsx
index f393706132..2df97af83e 100644
--- a/packages/client/src/components/Tooltip.spec.tsx
+++ b/packages/client/src/components/Tooltip.spec.tsx
@@ -4,6 +4,24 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { TooltipAnchor } from './Tooltip';
describe('TooltipAnchor', () => {
+ describe('zIndex', () => {
+ /** Lets a tooltip clear a host layer above the stylesheet's default (150). */
+ test('applies the zIndex prop to the tooltip popup', async () => {
+ render(
+ <TooltipAnchor description="Layered" zIndex={250} aria-label="Layered" tabIndex={0}>
+ <span>icon</span>
+ </TooltipAnchor>,
+ );
+
+ const anchor = screen.getByLabelText('Layered');
+ fireEvent.mouseEnter(anchor);
+ fireEvent.mouseMove(anchor);
+
+ const tooltip = await screen.findByRole('tooltip', undefined, { timeout: 3000 });
+ expect(tooltip).toHaveStyle({ zIndex: '250' });
+ });
+ });
+
describe('role="button" keyboard activation', () => {
/** Renders a non-native element, so Enter and Space must both be handled (WCAG 2.1.1). */
const renderButtonAnchor = (onClick: jest.Mock) => {
diff --git a/packages/client/src/components/Tooltip.tsx b/packages/client/src/components/Tooltip.tsx
index 8118137ff3..13367c9945 100644
--- a/packages/client/src/components/Tooltip.tsx
+++ b/packages/client/src/components/Tooltip.tsx
@@ -22,6 +22,8 @@ interface TooltipAnchorProps extends Ariakit.TooltipAnchorProps {
description: string;
enableHTML?: boolean;
portalElement?: Ariakit.TooltipProps['portalElement'];
+ /** Overrides the popup's z-index, for anchors inside a host layer above the default. */
+ zIndex?: number;
side?: 'top' | 'bottom' | 'left' | 'right';
}
@@ -34,11 +36,13 @@ const TooltipPopup = memo(function TooltipPopup({
description,
enableHTML,
portalElement,
+ zIndex,
}: {
store: Ariakit.TooltipStore;
description: string;
enableHTML: boolean;
portalElement?: Ariakit.TooltipProps['portalElement'];
+ zIndex?: number;
}) {
const mounted = Ariakit.useStoreState(store, (state) => state.mounted);
const placement = Ariakit.useStoreState(store, (state) => state.placement);
@@ -47,6 +51,7 @@ const TooltipPopup = memo(function TooltipPopup({
* the stylesheet default so tooltips never outrank freshly opened dialogs. */
const dialogDepth = useDialogDepth();
const popoverZIndex = usePopoverZIndex();
+ const resolvedZIndex = zIndex ?? (dialogDepth > 0 ? popoverZIndex : undefined);
const sanitizer = useMemo(() => {
const instance = DOMPurify();
@@ -102,7 +107,7 @@ const TooltipPopup = memo(function TooltipPopup({
className="tooltip"
render={
<motion.div
- style={dialogDepth > 0 ? { zIndex: popoverZIndex } : undefined}
+ style={resolvedZIndex != null ? { zIndex: resolvedZIndex } : undefined}
initial={{ opacity: 0, x, y }}
animate={{ opacity: 1, x: 0, y: 0 }}
exit={{ opacity: 0, x, y }}
@@ -136,6 +141,7 @@ export const TooltipAnchor: ForwardRefExoticComponent<
role,
enableHTML = false,
portalElement,
+ zIndex,
onKeyDown,
tabIndex,
...props
@@ -188,6 +194,7 @@ export const TooltipAnchor: ForwardRefExoticComponent<
description={description}
enableHTML={enableHTML}
portalElement={portalElement}
+ zIndex={zIndex}
/>
</Ariakit.TooltipProvider>
);