🔅 fix: Quiet Form-Control Outlines in the Stock Palettes (#16400)

* fix: Quiet Form-Control Outlines in the Stock Palettes

The stock light and dark palettes gave border-control a 3:1 value, which
made every field, textarea and dropdown outline far louder than the cards
and separators around them. Both now use their border-light value, while
the high contrast and ClickHouse palettes keep their 3:1 outlines.

A legacy theme without border-control now keeps its own light border on
controls instead of being pushed to a contrast-ranked candidate, which
often landed on a text color. The contrast helper that ranking needed is
removed.

The empty tools and skills cards step up from border-light to
border-medium so their dashed edge reads against the panel.

* fix: Keep a Legacy Medium Border on Controls

A theme that predates border-control and painted only its medium border
drew that edge on selects and OTP slots, so it now falls back to the
medium border after the light one instead of the bundled role.

Adds scenarios for the stock outlines matching the card border, the
legacy medium-border theme, and the empty tools card edge.

* test: Spell Out the Stock Control Outline Scenario Tags

(cherry picked from commit df59d61f77)

Original-PR: https://github.com/LibreChat-AI/LibreChat/pull/16400
This commit is contained in:
Marco Beretta 2026-09-26 21:28:16 +02:00 • committed by Lia
parent c0ea79ad12
commit e232b1b398
13 changed files with 117 additions and 193 deletions

View file

@ -413,7 +413,7 @@ export default function SkillsSection({ items, onInfo, onRemove, onAdd }: Props)
<button
type="button"
onClick={onAdd}
className="border-border-light text-text-secondary hover:border-border-medium hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
className="border-border-medium text-text-secondary hover:border-border-heavy hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
>
<Plus className="h-4 w-4" aria-hidden="true" />
<span className="text-xs">{localize('com_ui_skills_add_row')}</span>

View file

@ -371,7 +371,7 @@ function SelectedSection({
<button
type="button"
onClick={onAdd}
className="border-border-light text-text-secondary hover:border-border-medium hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
className="border-border-medium text-text-secondary hover:border-border-heavy hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary flex w-full flex-col items-center gap-1 rounded-xl border border-dashed px-2 py-4 transition-colors focus:outline-hidden focus-visible:ring-2"
>
<Plus className="h-4 w-4" aria-hidden="true" />
<span className="text-xs">{emptyLabel}</span>

View file

@ -2,14 +2,16 @@ import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse';
import { darkTheme } from '../../../../packages/client/src/theme/themes/dark';
import { openAgentBuilder } from '../agents.helpers';
import { themeValue } from './style.helpers';
/**
* A form control's outline is the only edge it has, so it owes the WCAG 1.4.11
* 3:1 non-text floor against whatever the control is painted on. The separators
* are a different role and stay quiet. The probe is a real control, the week
* A form control's outline is the only edge it has. The stock light and dark
* palettes keep it at their quiet light border, and the high contrast and
* ClickHouse palettes hold it to the WCAG 1.4.11 3:1 non-text floor against
* whatever the control is painted on. The probe is a real control, the week
* start `Dropdown` in the settings dialog, measured against the first opaque
* surface behind it, in every palette the app ships.
* surface behind it.
*/
type Rgb = [number, number, number];
@ -84,16 +86,6 @@ const PALETTES: Array<{
appearance: Appearance;
definition?: unknown;
}> = [
{
name: 'default light',
tag: '@scenario:control-outline-clears-3-to-1-default-light',
appearance: 'light',
},
{
name: 'default dark',
tag: '@scenario:control-outline-clears-3-to-1-default-dark',
appearance: 'dark',
},
{
name: 'high contrast light',
tag: '@scenario:control-outline-clears-3-to-1-high-contrast-light',
@ -148,13 +140,82 @@ test.describe('form control outline', () => {
expect(await themeValue(page, '--border-control')).toBe(darkTheme['rgb-border-control']);
});
/** Each tag is written out whole: the runner finds a scenario by its literal tag. */
const STOCK: Array<{ appearance: Appearance; title: string }> = [
{
appearance: 'light',
title:
'a stock light dropdown outline matches the card border @scenario:stock-control-outline-matches-card-border-light',
},
{
appearance: 'dark',
title:
'a stock dark dropdown outline matches the card border @scenario:stock-control-outline-matches-card-border-dark',
},
];
for (const { appearance, title } of STOCK) {
test(title, async ({ page }) => {
await installAppearance(page, appearance);
await openSettings(page);
const light = await themeValue(page, '--border-light');
expect(await themeValue(page, '--border-control')).toBe(light);
expect((await outlineAgainstSurface(page)).border).toBe(
`rgb(${light.split(/\s+/).join(', ')})`,
);
});
}
test('a legacy theme that painted only its medium border keeps it on controls @scenario:legacy-medium-border-theme-keeps-its-control-outline', async ({
page,
}) => {
const definition = {
version: 1,
name: 'legacy-medium-outline',
modes: { light: { colors: { 'rgb-border-medium': '70 90 110' } } },
};
await installAppearance(page, 'light', definition);
await openSettings(page);
await expect(page.locator('html')).toHaveAttribute('data-theme', 'legacy-medium-outline');
expect(await themeValue(page, '--border-control')).toBe('70 90 110');
expect((await outlineAgainstSurface(page)).border).toBe('rgb(70, 90, 110)');
});
test('the empty tools card edge sits one step above the field outline @scenario:empty-tools-card-edge-steps-above-field-outline', async ({
page,
}) => {
await installAppearance(page, 'dark');
let form = await openAgentBuilder(page);
const createNew = form.getByRole('button', { name: 'Create New Agent' });
if (await createNew.isVisible().catch(() => false)) {
await createNew.click();
form = page.getByRole('form', { name: 'Agent configuration form' });
}
const emptyTools = form.getByRole('button', { name: /No tools yet/ });
await expect(emptyTools).toBeVisible();
const medium = await themeValue(page, '--border-medium');
const edge = await emptyTools.evaluate((node) => {
const style = getComputedStyle(node);
return { color: style.borderTopColor, style: style.borderTopStyle };
});
const field = await form
.getByRole('textbox', { name: 'Agent name' })
.evaluate((node) => getComputedStyle(node).borderTopColor);
expect(edge).toEqual({ color: `rgb(${medium.split(/\s+/).join(', ')})`, style: 'dashed' });
expect(field).not.toBe(edge.color);
});
test('a custom theme without the control role keeps the outline it drew @scenario:custom-theme-keeps-its-control-outline', async ({
page,
}) => {
const definition = {
version: 1,
name: 'legacy-outline',
modes: { light: { colors: { 'rgb-border-medium': '70 90 110' } } },
modes: { light: { colors: { 'rgb-border-light': '70 90 110' } } },
};
await installAppearance(page, 'light', definition);
await openSettings(page);

View file

@ -3,8 +3,8 @@
* treatment. Owned here so `Input`, `Textarea`, and the select/combobox triggers
* that have to sit beside them in a form cannot drift apart as the theme evolves.
* Callers compose a variant rather than restating these classes locally. The
* border is `border-control` because it is the only edge the control has, so it
* owes the 3:1 non-text floor that the separator roles deliberately do not.
* border is `border-control` because it is the only edge the control has, so a
* palette can raise it to the 3:1 non-text floor without touching separators.
*/
export const fieldBase: string =
'lc-field flex w-full rounded-lg border border-border-control px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-text-primary disabled:cursor-not-allowed disabled:opacity-50';

View file

@ -3,16 +3,16 @@
*
* Every other color role is declared by the app stylesheet, but this one ships
* with the package so a consumer rendering `Input`, `Select` or `InputOTP` gets
* an outline that clears the WCAG 1.4.11 3:1 floor without restating it.
* an outline without restating it. The stock values match `border-light`.
* `ThemeProvider` paints the registry value inline whenever a theme is active,
* which outranks these; they only cover the stock palette before and without a
* theme definition, and `semanticTokens.spec.ts` keeps them in step with
* `themes/default.ts` and `themes/dark.ts`.
*/
html {
--border-control: 133 133 133;
--border-control: 227 227 227;
}
.dark {
--border-control: 125 125 125;
--border-control: 33 33 33;
}

View file

@ -250,20 +250,7 @@ describe('theme registry', () => {
expect(resolved.colors['rgb-chart-widget-stroke']).toBe('50 51 52');
});
it('keeps the control outline a theme drew with its own medium border', () => {
const resolved = resolveTheme(
{
version: 1,
name: 'legacy-control-border-reference',
modes: { dark: { colors: { 'rgb-border-medium': '150 151 152' } } },
},
'dark',
);
expect(resolved.colors['rgb-border-control']).toBe('150 151 152');
});
it('keeps a legacy light border that clears 3:1, the role most controls drew', () => {
it('keeps the light border a legacy theme drew its controls with', () => {
const resolved = resolveTheme(
{
version: 1,
@ -278,64 +265,17 @@ describe('theme registry', () => {
expect(resolved.colors['rgb-border-control']).toBe('110 111 112');
});
it('passes over quiet legacy borders to the bundled outline where it clears 3:1', () => {
it('keeps the medium border a legacy theme drew its selects with', () => {
const resolved = resolveTheme(
{
version: 1,
name: 'quiet-border-reference',
modes: {
light: {
colors: { 'rgb-border-light': '245 245 245', 'rgb-border-medium': '240 240 240' },
},
},
name: 'medium-border-reference',
modes: { dark: { colors: { 'rgb-border-medium': '150 151 152' } } },
},
'light',
'dark',
);
expect(resolved.colors['rgb-border-control']).toBe(defaultTheme['rgb-border-control']);
});
it('falls to the candidate that comes closest when nothing clears 3:1', () => {
const resolved = resolveTheme(
{
version: 1,
name: 'illegible-reference',
modes: {
light: {
colors: {
'rgb-surface-primary': '140 140 140',
'rgb-border-medium': '150 150 150',
'rgb-text-secondary': '120 120 120',
'rgb-text-primary': '90 90 90',
},
},
},
},
'light',
);
expect(resolved.colors['rgb-border-control']).toBe('90 90 90');
});
it('outlines controls with secondary text when no border clears its canvases', () => {
const resolved = resolveTheme(
{
version: 1,
name: 'mid-gray-canvas-reference',
modes: {
light: {
colors: {
'rgb-surface-primary': '140 140 140',
'rgb-border-medium': '150 150 150',
'rgb-text-secondary': '20 21 22',
},
},
},
},
'light',
);
expect(resolved.colors['rgb-border-control']).toBe('20 21 22');
expect(resolved.colors['rgb-border-control']).toBe('150 151 152');
});
it('gives a theme that leaves every border alone the bundled control outline', () => {
@ -343,12 +283,12 @@ describe('theme registry', () => {
{
version: 1,
name: 'surface-only-reference',
modes: { light: { colors: { 'rgb-surface-primary': '250 250 250' } } },
modes: { dark: { colors: { 'rgb-surface-primary': '10 10 10' } } },
},
'light',
'dark',
);
expect(resolved.colors['rgb-border-control']).toBe(defaultTheme['rgb-border-control']);
expect(resolved.colors['rgb-border-control']).toBe(darkTheme['rgb-border-control']);
});
it('preserves an explicit control outline', () => {

View file

@ -9,7 +9,6 @@ import type {
ThemeMode,
} from './types';
import { highContrastDarkTheme, highContrastLightTheme } from './themes/highContrast';
import { contrastRatio } from './utils/contrast';
import { defaultTheme } from './themes/default';
import { darkTheme } from './themes/dark';
export const THEME_VERSION = 1 as const;
@ -47,68 +46,19 @@ export const MARK_NEIGHBOURHOOD: readonly (keyof IThemeRGB)[] = Object.freeze([
'rgb-surface-tertiary',
]);
const NON_TEXT_CONTRAST = 3;
/** The canvases a form control is painted on, which its outline is measured against. */
const CONTROL_CANVASES: readonly (keyof IThemeRGB)[] = Object.freeze([
'rgb-surface-primary',
'rgb-surface-secondary',
'rgb-surface-tertiary',
'rgb-surface-dialog',
'rgb-surface-chat',
]);
/** What a theme has to paint to have coordinated the outline its controls wore. */
const CONTROL_SURROUNDINGS: readonly (keyof IThemeRGB)[] = Object.freeze([
'rgb-border-light',
'rgb-border-medium',
...CONTROL_CANVASES,
]);
/** The outline's lowest contrast across the canvases a theme paints. */
const weakestContrast = (outline: string, palette: IThemeRGB): number =>
CONTROL_CANVASES.reduce((weakest, canvas) => {
const surface = palette[canvas];
const ratio = surface === undefined ? undefined : contrastRatio(outline, surface);
return ratio === undefined ? weakest : Math.min(weakest, ratio);
}, Number.POSITIVE_INFINITY);
/**
* The control outline for a stored or environment theme that predates
* `rgb-border-control`. Controls drew `border-light` (fields, dropdowns,
* comboboxes) or `border-medium` (select, OTP) before the role existed, so a
* theme that painted either, or the canvases they sit on, coordinated an
* outline this role now replaces. The first candidate that clears the 3:1
* non-text floor on the theme's own canvases wins: its light border, its
* medium border, the bundled role, then its secondary and primary text. When
* none clears, the one that comes closest does. A theme that names none of
* these keeps the bundled role, and one that names the role keeps it as written.
* `base` is the bundled palette for the mode, which the theme is painted over.
* `rgb-border-control`. Fields, dropdowns and comboboxes drew `border-light`
* and selects and OTP slots drew `border-medium` before the role existed, so a
* theme that painted either keeps that edge on its controls, the light border
* first. A theme that painted neither keeps the bundled role, and one that
* names the role keeps it as written.
*/
export function controlBorderFallback(colors: IThemeRGB, base: IThemeRGB = {}): string | undefined {
export function controlBorderFallback(colors: IThemeRGB): string | undefined {
if (colors['rgb-border-control'] !== undefined) {
return undefined;
}
const ownsControlSurroundings = CONTROL_SURROUNDINGS.some((token) => colors[token] !== undefined);
if (!ownsControlSurroundings) {
return undefined;
}
const palette: IThemeRGB = { ...base, ...colors };
const ranked = [
colors['rgb-border-light'],
colors['rgb-border-medium'],
base['rgb-border-control'],
palette['rgb-text-secondary'],
palette['rgb-text-primary'],
]
.filter((value): value is string => value !== undefined)
.map((outline) => ({ outline, contrast: weakestContrast(outline, palette) }));
const clearing = ranked.find(({ contrast }) => contrast >= NON_TEXT_CONTRAST);
const closest = ranked.reduce<(typeof ranked)[number] | undefined>(
(best, entry) => (best === undefined || entry.contrast > best.contrast ? entry : best),
undefined,
);
return (clearing ?? closest)?.outline;
return colors['rgb-border-light'] ?? colors['rgb-border-medium'];
}
export const themeAppearanceProperties: Readonly<
@ -646,7 +596,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
? { 'rgb-chart-widget-stroke': customColors['rgb-border-light'] }
: {};
const borderControlSource =
customColors != null ? controlBorderFallback(customColors, baseColors) : undefined;
customColors != null ? controlBorderFallback(customColors) : undefined;
const borderControlFallback =
borderControlSource !== undefined ? { 'rgb-border-control': borderControlSource } : {};
/**

View file

@ -613,14 +613,12 @@ describe('syntax highlighting palette', () => {
});
/** `border-control` is the only edge a form control has (`Field`, `Select`,
* `InputOTP`, the dropdown and combobox triggers), so it is a UI component
* boundary under WCAG 1.4.11 and owes 3:1 on every canvas a form can sit on.
* The separator roles are deliberately quieter and are not held to this. */
* `InputOTP`, the dropdown and combobox triggers). The stock light and dark
* palettes keep it at their quiet `border-light` value by design; the high
* contrast and ClickHouse palettes hold it to the WCAG 1.4.11 3:1 floor. */
const controlCanvases: Array<keyof IThemeRGB> = [...canvasSurfaces, 'rgb-surface-tertiary'];
describe.each([
['default', defaultTheme],
['dark', darkTheme],
['high contrast light', highContrastLightTheme],
['high contrast dark', highContrastDarkTheme],
['clickhouse light', clickHouseLightTheme],

View file

@ -69,7 +69,7 @@ export const darkTheme: IThemeRGB = {
'rgb-border-heavy': '89 89 89', // #595959 (gray-500)
'rgb-border-xheavy': '153 150 150', // #999696 (gray-400)
'rgb-border-destructive': '239 68 68', // #ef4444 (red-500)
'rgb-border-control': '125 125 125', // #7d7d7d, 3.25:1 on gray-700, the lightest canvas
'rgb-border-control': '33 33 33', // #212121 (gray-800), the stock field edge
// Status colors
'rgb-status-success': '110 231 183', // #6ee7b7 (green-300)

View file

@ -69,7 +69,7 @@ export const defaultTheme: IThemeRGB = {
'rgb-border-heavy': '153 150 150', // #999696 (gray-400)
'rgb-border-xheavy': '89 89 89', // #595959 (gray-500)
'rgb-border-destructive': '220 38 38', // #dc2626 (red-600)
'rgb-border-control': '133 133 133', // #858585, 3.12:1 on gray-100, the lightest canvas
'rgb-border-control': '227 227 227', // #e3e3e3 (gray-200), the stock field edge
// Status colors
'rgb-status-success': '4 120 87', // #047857 (green-700)

View file

@ -332,14 +332,6 @@ describe('applyTheme', () => {
expect(root.style.getPropertyValue('--chart-widget-stroke')).toBe('50 51 52');
});
it('carries a legacy medium border onto the control outline', () => {
const root = document.documentElement;
applyTheme({ 'rgb-border-medium': '60 61 62' }, root);
expect(root.style.getPropertyValue('--border-control')).toBe('60 61 62');
});
it('carries a legacy light border onto the control outline', () => {
const root = document.documentElement;
@ -348,14 +340,20 @@ describe('applyTheme', () => {
expect(root.style.getPropertyValue('--border-control')).toBe('110 111 112');
});
it('keeps the bundled outline when the legacy borders are too quiet', () => {
it('carries a legacy medium border onto the control outline', () => {
const root = document.documentElement;
applyTheme({ 'rgb-border-medium': '240 240 240' }, root, defaultTheme);
applyTheme({ 'rgb-border-medium': '60 61 62' }, root, defaultTheme);
expect(root.style.getPropertyValue('--border-control')).toBe(
defaultTheme['rgb-border-control'],
);
expect(root.style.getPropertyValue('--border-control')).toBe('60 61 62');
});
it('leaves the bundled outline when the theme paints no border', () => {
const root = document.documentElement;
applyTheme({ 'rgb-surface-primary': '250 250 250' }, root, defaultTheme);
expect(root.style.getPropertyValue('--border-control')).toBe('');
});
it('leaves an explicit control outline alone', () => {

View file

@ -71,7 +71,7 @@ function mapColors(colors: IThemeRGB, base?: IThemeRGB): Array<[string, string]>
variables.push(['--chart-widget-stroke', colors['rgb-border-light']]);
}
const legacyControlBorder = controlBorderFallback(colors, base);
const legacyControlBorder = controlBorderFallback(colors);
if (legacyControlBorder !== undefined) {
variables.push(['--border-control', legacyControlBorder]);
}

View file

@ -1,23 +0,0 @@
const channel = (value: number): number => {
const c = value / 255;
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
};
function luminance(triplet: string): number | undefined {
const parts = triplet.trim().split(/\s+/).map(Number);
if (parts.length !== 3 || parts.some(Number.isNaN)) {
return undefined;
}
const [r, g, b] = parts;
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
}
/** WCAG contrast ratio between two `R G B` triplets; `undefined` when either is malformed. */
export function contrastRatio(a: string, b: string): number | undefined {
const [first, second] = [luminance(a), luminance(b)];
if (first === undefined || second === undefined) {
return undefined;
}
const [lighter, darker] = first > second ? [first, second] : [second, first];
return (lighter + 0.05) / (darker + 0.05);
}