From d2b7a35954db033cb3512ce1843b0e32f0058046 Mon Sep 17 00:00:00 2001 From: Lee Calcote Date: Fri, 23 Oct 2026 18:29:53 -0500 Subject: [PATCH] fix(CustomTooltip): resolve tooltip content against the theme of its own surface The tooltip paints bgColor (default #141414) in both palette modes, but its content styled from the ambient theme, so mode-dependent tokens such as palette.divider were wrong on light pages. Wrap the title in a ThemeProvider whose mode follows the contrast of bgColor, only when it differs from the page mode so branded themes are preserved. Remove the CollaboratorAvatarGroup call-site workaround. Fixes #1783 Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: Lee Calcote --- src/__testing__/CustomTooltip.test.tsx | 41 +++++++++++++++++++ .../CollaboratorAvatarGroup.tsx | 24 +---------- src/custom/CustomTooltip/customTooltip.tsx | 32 ++++++++++++--- 3 files changed, 70 insertions(+), 27 deletions(-) create mode 100644 src/__testing__/CustomTooltip.test.tsx diff --git a/src/__testing__/CustomTooltip.test.tsx b/src/__testing__/CustomTooltip.test.tsx new file mode 100644 index 000000000..7c7a6e2e0 --- /dev/null +++ b/src/__testing__/CustomTooltip.test.tsx @@ -0,0 +1,41 @@ +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import CustomTooltip from '../custom/CustomTooltip/customTooltip'; +import { createCustomTheme, ThemeProvider, useTheme } from '../theme'; + +// CustomTooltip -> Markdown -> react-markdown (ESM-only) is excluded by jest's +// transformIgnorePatterns allowlist, so those leaf modules are stubbed. +jest.mock('react-markdown', () => ({ + __esModule: true, + default: ({ children }: { children: React.ReactNode }) =>
{children}
+})); +jest.mock('remark-gfm', () => ({ __esModule: true, default: () => {} })); +jest.mock('rehype-raw', () => ({ __esModule: true, default: () => {} })); + +const ModeProbe = () => {useTheme().palette.mode}; + +const renderTooltip = (pageMode: 'light' | 'dark', bgColor?: string) => + render( + + } open bgColor={bgColor}> + + + + ); + +describe('CustomTooltip theme context', () => { + it('resolves tooltip content against dark on the default dark surface of a light page', async () => { + renderTooltip('light'); + expect((await screen.findByTestId('mode')).textContent).toBe('dark'); + }); + + it('keeps the page theme when it already matches the surface', async () => { + renderTooltip('dark'); + expect((await screen.findByTestId('mode')).textContent).toBe('dark'); + }); + + it('follows a light bgColor rather than assuming dark', async () => { + renderTooltip('dark', '#ffffff'); + expect((await screen.findByTestId('mode')).textContent).toBe('light'); + }); +}); diff --git a/src/custom/CollaboratorAvatarGroup/CollaboratorAvatarGroup.tsx b/src/custom/CollaboratorAvatarGroup/CollaboratorAvatarGroup.tsx index 9c7143a48..9bfea9317 100644 --- a/src/custom/CollaboratorAvatarGroup/CollaboratorAvatarGroup.tsx +++ b/src/custom/CollaboratorAvatarGroup/CollaboratorAvatarGroup.tsx @@ -1,5 +1,4 @@ import { ExpandMore } from '@mui/icons-material'; -import { alpha } from '@mui/material'; import { MouseEvent, useState } from 'react'; import { Avatar, AvatarGroup, Button, Divider, Popover, Typography } from '../../base'; import { iconSmall } from '../../constants/iconsSizes'; @@ -161,24 +160,7 @@ const CollaboratorAvatarGroup = ({ > {user.name} - {/* - WORKAROUND for https://github.com/layer5io/sistent/issues/1783 - delete - the two `borderColor` overrides and the button `color` override once that - component-level fix lands, and do not copy this into other tooltips. - `CustomTooltip`'s surface is the literal `#141414` in both palette modes, - but `palette.divider`, the theme's outlined-button border and the button - label colour all resolve to mode-dependent tokens, so in light mode the - separator is invisible, the button outline is near black-on-black and the - label is black-on-black outright: `MuiButton`'s root override spreads - `typography.textB2SemiBold`, whose `color` is `common.black` in light mode - (src/theme/typography.ts), and that wins over MUI's own - `--variant-outlinedColor`. Measured on the hovered component, the label was - `rgb(0, 0, 0)` on `rgb(20, 20, 20)` - 1.06:1. These three are fixed to - white / white alphas, which are stable across modes because the surface - they sit on is; the label now matches the tooltip's own body text at - 18.4:1, clearing WCAG AA. - */} - +