mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 05:20:55 +00:00
♿ a11y: Ring Content Rows in a Themeable Focus Role (#16740)
* feat: Add a Focus Role for Rows Inside Content * test: Cover the Subtle Focus Role in the Mock Harness * test: Probe the Subtle Focus Role Through Its Theme Variable * test: Focus the Probe to Read the Subtle Focus Utility * test: Read the Subtle Focus Ring From Its Utility Property * fix: Ring the Subagent Progress Disclosure in the Subtle Focus Role
This commit is contained in:
parent
cac13c42e7
commit
2b25f69ea0
36 changed files with 217 additions and 30 deletions
|
|
@ -502,7 +502,7 @@ export default function Artifacts() {
|
|||
aria-valuemin={10}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={Math.round(height)}
|
||||
className="bg-surface-primary-alt focus-visible:ring-border-heavy flex shrink-0 cursor-grab items-center justify-center pt-2.5 pb-1.5 focus-visible:ring-2 focus-visible:outline-hidden focus-visible:ring-inset active:cursor-grabbing"
|
||||
className="bg-surface-primary-alt focus-visible:ring-focus-subtle flex shrink-0 cursor-grab items-center justify-center pt-2.5 pb-1.5 focus-visible:ring-2 focus-visible:outline-hidden focus-visible:ring-inset active:cursor-grabbing"
|
||||
onPointerDown={handleDragStart}
|
||||
onPointerMove={handleDragMove}
|
||||
onPointerUp={handleDragEnd}
|
||||
|
|
|
|||
|
|
@ -500,7 +500,7 @@ function FailedPeek({
|
|||
type="button"
|
||||
className={cn(
|
||||
TOOL_ROW_CLASSES,
|
||||
'text-text-secondary hover:text-text-primary focus-visible:ring-border-heavy w-full pl-6 text-left focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset',
|
||||
'text-text-secondary hover:text-text-primary focus-visible:ring-focus-subtle w-full pl-6 text-left focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset',
|
||||
)}
|
||||
onClick={onReveal}
|
||||
data-testid="activity-phase-failed-peek"
|
||||
|
|
@ -846,7 +846,7 @@ export default function ActivityPhaseGroup({
|
|||
* supplies it today; stating it here keeps the requirement with
|
||||
* the element that depends on it. */
|
||||
className={cn(
|
||||
'text-text-secondary hover:text-text-primary focus-visible:ring-border-heavy flex h-auto min-h-7 min-w-0 flex-1 items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 text-left font-medium hover:bg-transparent focus-visible:ring-2 focus-visible:ring-offset-0 focus-visible:outline-none focus-visible:ring-inset',
|
||||
'text-text-secondary hover:text-text-primary focus-visible:ring-focus-subtle flex h-auto min-h-7 min-w-0 flex-1 items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 text-left font-medium hover:bg-transparent focus-visible:ring-2 focus-visible:ring-offset-0 focus-visible:outline-none focus-visible:ring-inset',
|
||||
/** The open card's title: the one semibold, primary-colour line
|
||||
* in the fold, so the rows under it read as its contents. */
|
||||
isExpanded && 'text-text-primary font-semibold',
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ export default function FilePreviewDialog({
|
|||
<button
|
||||
type="button"
|
||||
onClick={handleDownload}
|
||||
className="text-text-secondary hover:text-text-primary focus-visible:ring-border-heavy inline-flex shrink-0 items-center gap-1 text-xs transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
className="text-text-secondary hover:text-text-primary focus-visible:ring-focus-subtle inline-flex shrink-0 items-center gap-1 text-xs transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
aria-label={`${localize('com_ui_download')} ${fileName}`}
|
||||
>
|
||||
<Download className="size-3" aria-hidden="true" />
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ const FileAttachmentGroup = memo(({ attachments }: { attachments: TAttachment[]
|
|||
className={cn(
|
||||
'inline-flex w-full max-w-full items-center gap-2 rounded-lg py-1 pr-2 text-sm',
|
||||
'text-text-secondary hover:text-text-primary transition-colors',
|
||||
'focus-visible:ring-border-heavy focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
'focus-visible:ring-focus-subtle focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
)}
|
||||
>
|
||||
<FilesIcon className="size-4 shrink-0" aria-hidden="true" />
|
||||
|
|
@ -365,7 +365,7 @@ const TextAttachment = memo(
|
|||
onClick={handleDownload}
|
||||
aria-label={`${localize('com_ui_download')} ${visibleFilename}`}
|
||||
title={localize('com_ui_download')}
|
||||
className="text-text-secondary hover:bg-surface-hover hover:text-text-primary focus-visible:ring-border-heavy flex size-7 shrink-0 items-center justify-center rounded-md transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
className="text-text-secondary hover:bg-surface-hover hover:text-text-primary focus-visible:ring-focus-subtle flex size-7 shrink-0 items-center justify-center rounded-md transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
>
|
||||
<Download className="size-4" aria-hidden="true" />
|
||||
</button>
|
||||
|
|
@ -390,7 +390,7 @@ const TextAttachment = memo(
|
|||
onClick={() => setExpanded((prev) => !prev)}
|
||||
aria-expanded={expanded}
|
||||
aria-controls={preId}
|
||||
className="text-text-secondary hover:text-text-primary focus-visible:ring-border-heavy mt-2 text-xs transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
className="text-text-secondary hover:text-text-primary focus-visible:ring-focus-subtle mt-2 text-xs transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
>
|
||||
{expanded ? localize('com_ui_collapse') : localize('com_ui_show_all')}
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ export default function BackgroundTaskCall({
|
|||
<ul
|
||||
tabIndex={0}
|
||||
aria-label={localize('com_ui_background_tasks')}
|
||||
className="focus-visible:ring-border-heavy flex max-h-96 flex-col gap-2 overflow-y-auto pr-1 focus-visible:ring-2 focus-visible:outline-none"
|
||||
className="focus-visible:ring-focus-subtle flex max-h-96 flex-col gap-2 overflow-y-auto pr-1 focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
{display.tasks.map((task) => (
|
||||
<li key={task.taskId}>
|
||||
|
|
@ -218,7 +218,7 @@ export default function BackgroundTaskCall({
|
|||
className="border-border-light border-t px-3 py-2"
|
||||
onToggle={(event) => setShowRaw(event.currentTarget.open)}
|
||||
>
|
||||
<summary className="text-text-secondary hover:text-text-primary focus-visible:ring-border-heavy cursor-pointer rounded text-xs focus-visible:ring-2 focus-visible:outline-none">
|
||||
<summary className="text-text-secondary hover:text-text-primary focus-visible:ring-focus-subtle cursor-pointer rounded text-xs focus-visible:ring-2 focus-visible:outline-none">
|
||||
{localize('com_ui_background_tasks_raw_details')}
|
||||
</summary>
|
||||
{showRaw && (
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ const FloatingSummaryBar = memo(
|
|||
className={cn(
|
||||
'bg-surface-secondary text-text-secondary-alt flex items-center justify-center rounded-lg p-1.5 shadow-xs',
|
||||
'hover:bg-surface-hover hover:text-text-primary',
|
||||
'focus-visible:ring-border-heavy focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
'focus-visible:ring-focus-subtle focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
)}
|
||||
>
|
||||
<ChevronUp className="h-[1.125rem] w-[1.125rem]" aria-hidden="true" />
|
||||
|
|
@ -190,7 +190,7 @@ const FloatingSummaryBar = memo(
|
|||
className={cn(
|
||||
'bg-surface-secondary text-text-secondary-alt flex items-center justify-center rounded-lg p-1.5 shadow-xs',
|
||||
'hover:bg-surface-hover hover:text-text-primary',
|
||||
'focus-visible:ring-border-heavy focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
'focus-visible:ring-focus-subtle focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
)}
|
||||
>
|
||||
<MorphIcon icon={isCopied ? Check : Copy} className="h-[1.125rem] w-[1.125rem]" />
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ const ToolMermaidArtifact = memo(({ attachment, text }: ToolMermaidArtifactProps
|
|||
className={cn(
|
||||
'inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs',
|
||||
'text-text-secondary hover:bg-surface-hover hover:text-text-primary transition-colors',
|
||||
'focus-visible:ring-border-heavy focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
'focus-visible:ring-focus-subtle focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
)}
|
||||
>
|
||||
<Download className="size-3" aria-hidden="true" />
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ function FileHeader({
|
|||
<button
|
||||
type="button"
|
||||
onClick={onOpenPreview}
|
||||
className="text-text-primary decoration-border-medium hover:text-text-secondary focus-visible:ring-border-heavy min-w-0 truncate text-left text-xs font-medium underline underline-offset-2 transition-colors focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:outline-hidden"
|
||||
className="text-text-primary decoration-border-medium hover:text-text-secondary focus-visible:ring-focus-subtle min-w-0 truncate text-left text-xs font-medium underline underline-offset-2 transition-colors focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:outline-hidden"
|
||||
aria-label={`${localize('com_ui_preview')}: ${fileName}`}
|
||||
>
|
||||
{fileName}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ function DigestBranch({
|
|||
return (
|
||||
<li className="min-w-0">
|
||||
<details open={isOnPath(entry.node.path, active)} className="group">
|
||||
<summary className="focus-visible:ring-border-heavy flex min-w-0 cursor-pointer items-center rounded py-0.5 focus-visible:ring-2 focus-visible:outline-none">
|
||||
<summary className="focus-visible:ring-focus-subtle flex min-w-0 cursor-pointer items-center rounded py-0.5 focus-visible:ring-2 focus-visible:outline-none">
|
||||
<NodeRow node={entry.node} serverNames={serverNames} />
|
||||
</summary>
|
||||
<ul className="border-border-light ms-1.5 border-s ps-2">
|
||||
|
|
|
|||
|
|
@ -633,7 +633,7 @@ export default function ToolCallGroup({
|
|||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
'text-text-secondary hover:text-text-secondary focus-visible:ring-border-heavy inline-flex h-auto min-w-0 flex-1 items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 hover:bg-transparent focus-visible:ring-2 focus-visible:ring-offset-0 focus-visible:outline-none',
|
||||
'text-text-secondary hover:text-text-secondary focus-visible:ring-focus-subtle inline-flex h-auto min-w-0 flex-1 items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 hover:bg-transparent focus-visible:ring-2 focus-visible:ring-offset-0 focus-visible:outline-none',
|
||||
/** An open header is the title of the rows under it, so it is the
|
||||
* one line in the fold set in the primary colour. */
|
||||
isExpanded && 'text-text-primary hover:text-text-primary',
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ export default function ToolCallInfo({ input, output }: { input: string; output?
|
|||
type="button"
|
||||
className={cn(
|
||||
'text-text-secondary inline-flex items-center gap-1 text-xs',
|
||||
'focus-visible:ring-border-heavy focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
'focus-visible:ring-focus-subtle focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
)}
|
||||
onClick={() => setShowParams((prev) => !prev)}
|
||||
aria-expanded={showParams}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ function ImageStrip({ images, label }: { images: ImageResult[]; label: string })
|
|||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={image.title || image.domain || label}
|
||||
className="border-border-light focus-visible:ring-border-heavy block h-28 overflow-hidden rounded-xl border no-underline focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
className="border-border-light focus-visible:ring-focus-subtle block h-28 overflow-hidden rounded-xl border no-underline focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
style={{ aspectRatio: ratio }}
|
||||
>
|
||||
<img
|
||||
|
|
@ -157,7 +157,7 @@ function ShoppingStrip({ items, label }: { items: ShoppingResult[]; label: strin
|
|||
href={safeUrl(item.link)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="border-border-light hover:bg-surface-hover focus-visible:ring-border-heavy flex w-full flex-col rounded-xl border p-2 no-underline transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
className="border-border-light hover:bg-surface-hover focus-visible:ring-focus-subtle flex w-full flex-col rounded-xl border p-2 no-underline transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
>
|
||||
{safeUrl(item.imageUrl) && (
|
||||
<div className="bg-surface-tertiary mb-2 aspect-square w-full shrink-0 overflow-hidden rounded-lg">
|
||||
|
|
@ -209,7 +209,7 @@ function PlaceList({ places, label }: { places: PlaceResult[]; label: string })
|
|||
href={mapLink(place)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="hover:bg-surface-hover focus-visible:ring-border-heavy flex items-center gap-2.5 px-3 py-2 no-underline transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
className="hover:bg-surface-hover focus-visible:ring-focus-subtle flex items-center gap-2.5 px-3 py-2 no-underline transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
|
||||
>
|
||||
<MapPin className="text-text-secondary size-4 shrink-0" aria-hidden="true" />
|
||||
<span className="min-w-0 flex-1">
|
||||
|
|
|
|||
|
|
@ -69,4 +69,4 @@ export default function SystemEventHeader({
|
|||
}
|
||||
|
||||
export const systemEventHeaderClasses =
|
||||
'inline-flex h-auto w-full items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 text-sm text-text-secondary hover:bg-transparent hover:text-text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-border-heavy focus-visible:ring-offset-0';
|
||||
'inline-flex h-auto w-full items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 text-sm text-text-secondary hover:bg-transparent hover:text-text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus-subtle focus-visible:ring-offset-0';
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ const ActionButton = React.forwardRef<HTMLButtonElement, ActionButtonProps>(
|
|||
'text-text-secondary inline-flex items-center justify-center transition-all duration-200 ease-out select-none',
|
||||
'hover:bg-surface-hover hover:text-text-primary',
|
||||
'disabled:pointer-events-none disabled:opacity-50',
|
||||
'focus-visible:outline-border-heavy focus-visible:outline focus-visible:outline-2',
|
||||
'focus-visible:outline-focus-subtle focus-visible:outline focus-visible:outline-2',
|
||||
iconOnly ? 'rounded-lg p-1.5' : 'ml-auto gap-2 rounded-md px-2 py-1',
|
||||
className,
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ const MermaidExport = memo(function MermaidExport({
|
|||
aria-busy={isBusy || undefined}
|
||||
className={cn(
|
||||
'text-text-secondary flex items-center justify-center rounded-lg p-1.5 transition-colors motion-reduce:transition-none',
|
||||
'hover:bg-surface-hover hover:text-text-primary focus-visible:outline-border-heavy focus-visible:outline focus-visible:outline-2',
|
||||
'hover:bg-surface-hover hover:text-text-primary focus-visible:outline-focus-subtle focus-visible:outline focus-visible:outline-2',
|
||||
buttonClassName,
|
||||
)}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ interface MermaidHeaderProps {
|
|||
}
|
||||
|
||||
const iconBtnClass =
|
||||
'flex items-center justify-center rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-surface-hover hover:text-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-border-heavy';
|
||||
'flex items-center justify-center rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-surface-hover hover:text-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-focus-subtle';
|
||||
|
||||
const MermaidHeader: React.FC<MermaidHeaderProps> = memo(
|
||||
({
|
||||
|
|
@ -69,7 +69,7 @@ const MermaidHeader: React.FC<MermaidHeaderProps> = memo(
|
|||
|
||||
return (
|
||||
<div className={cn('flex items-center justify-between gap-1 px-2 py-1', className)}>
|
||||
<span className="rounded text-xs font-medium text-text-secondary">
|
||||
<span className="text-text-secondary rounded text-xs font-medium">
|
||||
{localize('com_ui_mermaid')}
|
||||
</span>
|
||||
<div className={cn('flex items-center gap-1', actionsClassName)}>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export default function ResultSwitcher({
|
|||
onClick={onPrevious}
|
||||
disabled={atFirst}
|
||||
aria-label={localize('com_ui_prev_result')}
|
||||
className="text-text-tertiary hover:bg-surface-hover hover:text-text-primary focus:outline-border-heavy rounded p-0.5 transition-colors focus:outline focus:outline-2 disabled:pointer-events-none disabled:opacity-30"
|
||||
className="text-text-tertiary hover:bg-surface-hover hover:text-text-primary focus:outline-focus-subtle rounded p-0.5 transition-colors focus:outline focus:outline-2 disabled:pointer-events-none disabled:opacity-30"
|
||||
>
|
||||
<ChevronLeft className="size-3.5" aria-hidden="true" />
|
||||
</button>
|
||||
|
|
@ -45,7 +45,7 @@ export default function ResultSwitcher({
|
|||
onClick={onNext}
|
||||
disabled={atLast}
|
||||
aria-label={localize('com_ui_next_result')}
|
||||
className="text-text-tertiary hover:bg-surface-hover hover:text-text-primary focus:outline-border-heavy rounded p-0.5 transition-colors focus:outline focus:outline-2 disabled:pointer-events-none disabled:opacity-30"
|
||||
className="text-text-tertiary hover:bg-surface-hover hover:text-text-primary focus:outline-focus-subtle rounded p-0.5 transition-colors focus:outline focus:outline-2 disabled:pointer-events-none disabled:opacity-30"
|
||||
>
|
||||
<ChevronRight className="size-3.5" aria-hidden="true" />
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ const RunCode: React.FC<CodeBarProps & { iconOnly?: boolean }> = React.memo(
|
|||
className={cn(
|
||||
'text-text-secondary inline-flex items-center justify-center transition-all duration-200 ease-out select-none',
|
||||
'hover:bg-surface-hover hover:text-text-primary',
|
||||
'focus-visible:outline-border-heavy focus-visible:outline focus-visible:outline-2',
|
||||
'focus-visible:outline-focus-subtle focus-visible:outline focus-visible:outline-2',
|
||||
'disabled:pointer-events-none disabled:opacity-50',
|
||||
isError && 'text-text-destructive hover:text-text-destructive',
|
||||
iconOnly
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ export default function MemoryUsageBadge({
|
|||
className={cn(
|
||||
'inline-flex shrink-0 items-center gap-1.5 rounded-full px-2.5 py-1',
|
||||
'text-xs font-medium hover:underline',
|
||||
'focus-visible:ring-border-heavy focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
'focus-visible:ring-focus-subtle focus-visible:ring-2 focus-visible:outline-hidden',
|
||||
getStatusColor(percentage),
|
||||
)}
|
||||
>
|
||||
|
|
|
|||
134
e2e/specs/mock/scenarios/focus-subtle.spec.ts
Normal file
134
e2e/specs/mock/scenarios/focus-subtle.spec.ts
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse';
|
||||
import { NEW_CHAT_PATH } from '../helpers';
|
||||
|
||||
/**
|
||||
* The subtle focus role. Rows and controls inside content (tool rows, attachments, summaries,
|
||||
* message navigation) ring their keyboard focus in `focus-subtle`, which follows `border-heavy`
|
||||
* unless a theme names it, so the bundled palettes keep the ring they had. ClickHouse takes Click
|
||||
* UI's outline color, and a theme that only repaints `border-heavy` keeps its rows on it.
|
||||
*/
|
||||
|
||||
type Mode = 'light' | 'dark';
|
||||
|
||||
const HEAVY_ONLY_THEME = {
|
||||
version: 1,
|
||||
name: 'e2e-focus-subtle-heavy',
|
||||
modes: {
|
||||
light: { colors: { 'rgb-border-heavy': '10 20 30' } },
|
||||
dark: { colors: { 'rgb-border-heavy': '10 20 30' } },
|
||||
},
|
||||
} as const;
|
||||
|
||||
const NAMED_THEME = {
|
||||
version: 1,
|
||||
name: 'e2e-focus-subtle-named',
|
||||
modes: {
|
||||
light: { colors: { 'rgb-border-heavy': '10 20 30', 'rgb-focus-subtle': '200 30 90' } },
|
||||
dark: { colors: { 'rgb-border-heavy': '10 20 30', 'rgb-focus-subtle': '200 30 90' } },
|
||||
},
|
||||
} as const;
|
||||
|
||||
async function openChat(page: Page, mode: Mode, definition?: { name: string }) {
|
||||
await page.addInitScript(
|
||||
([appearance, stored]) => {
|
||||
localStorage.setItem('color-theme', appearance as string);
|
||||
localStorage.removeItem('theme-colors');
|
||||
localStorage.removeItem('theme-name');
|
||||
if (stored) {
|
||||
localStorage.setItem('theme-definition', JSON.stringify(stored));
|
||||
localStorage.setItem('theme-source', 'definition');
|
||||
} else {
|
||||
localStorage.removeItem('theme-definition');
|
||||
localStorage.removeItem('theme-source');
|
||||
}
|
||||
},
|
||||
[mode, definition ?? null] as [string, unknown],
|
||||
);
|
||||
await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({
|
||||
timeout: 30000,
|
||||
});
|
||||
const root = page.locator('html');
|
||||
if (definition) {
|
||||
await expect(root).toHaveAttribute('data-theme', definition.name);
|
||||
} else {
|
||||
await expect(root).not.toHaveAttribute('data-theme');
|
||||
}
|
||||
await expect(root).toHaveClass(mode === 'dark' ? /\bdark\b/ : /\blight\b/);
|
||||
}
|
||||
|
||||
/**
|
||||
* The ring the utility paints on focus. The ring colour is read from the utility's own custom
|
||||
* property, because the dark stylesheet's `.dark :focus-visible` outline rule outranks any outline
|
||||
* utility and would hide the role.
|
||||
*/
|
||||
function subtleFocus(page: Page): Promise<string> {
|
||||
return page.evaluate(() => {
|
||||
const node = document.createElement('div');
|
||||
node.className = 'focus-visible:ring-focus-subtle';
|
||||
node.tabIndex = -1;
|
||||
document.body.append(node);
|
||||
node.focus();
|
||||
const ring = getComputedStyle(node).getPropertyValue('--tw-ring-color');
|
||||
node.remove();
|
||||
const channels = ring.match(/\d+/g) ?? [];
|
||||
return `rgb(${channels.slice(0, 3).join(', ')})`;
|
||||
});
|
||||
}
|
||||
|
||||
/** Each tag is written out whole: the runner finds a scenario by its literal tag. */
|
||||
const CASES: Array<{ title: string; mode: Mode; definition?: { name: string }; expected: string }> =
|
||||
[
|
||||
{
|
||||
title:
|
||||
'the default light theme keeps the heavy border as its subtle focus ring @scenario:focus-subtle-default-light-unchanged',
|
||||
mode: 'light',
|
||||
expected: 'rgb(153, 150, 150)',
|
||||
},
|
||||
{
|
||||
title:
|
||||
'the default dark theme keeps the heavy border as its subtle focus ring @scenario:focus-subtle-default-dark-unchanged',
|
||||
mode: 'dark',
|
||||
expected: 'rgb(89, 89, 89)',
|
||||
},
|
||||
{
|
||||
title:
|
||||
'the ClickHouse light theme rings subtle focus in the Click UI outline @scenario:focus-subtle-clickhouse-light',
|
||||
mode: 'light',
|
||||
definition: clickHouseTheme,
|
||||
expected: 'rgb(67, 126, 239)',
|
||||
},
|
||||
{
|
||||
title:
|
||||
'the ClickHouse dark theme rings subtle focus in the Click UI outline @scenario:focus-subtle-clickhouse-dark',
|
||||
mode: 'dark',
|
||||
definition: clickHouseTheme,
|
||||
expected: 'rgb(250, 255, 105)',
|
||||
},
|
||||
{
|
||||
title:
|
||||
'a theme that repaints only the heavy border keeps its subtle focus on it @scenario:focus-subtle-follows-heavy-border',
|
||||
mode: 'light',
|
||||
definition: HEAVY_ONLY_THEME,
|
||||
expected: 'rgb(10, 20, 30)',
|
||||
},
|
||||
{
|
||||
title:
|
||||
'a theme that names the subtle focus role rings in it whatever the heavy border is @scenario:focus-subtle-follow-reference-theme',
|
||||
mode: 'light',
|
||||
definition: NAMED_THEME,
|
||||
expected: 'rgb(200, 30, 90)',
|
||||
},
|
||||
];
|
||||
|
||||
test.describe('subtle focus role', () => {
|
||||
for (const { title, mode, definition, expected } of CASES) {
|
||||
test(title, async ({ page }) => {
|
||||
await openChat(page, mode, definition);
|
||||
|
||||
expect(await subtleFocus(page)).toBe(expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -157,7 +157,7 @@ const buttonVariantRecipe = cva(
|
|||
* is inset because the row sits flush against the panel it opens.
|
||||
*/
|
||||
disclosure:
|
||||
'w-full justify-start focus-visible:ring-border-heavy focus-visible:ring-offset-0 disabled:opacity-100',
|
||||
'w-full justify-start focus-visible:ring-focus-subtle focus-visible:ring-offset-0 disabled:opacity-100',
|
||||
/**
|
||||
* A full-width answer row in an option list, such as the choices of an
|
||||
* `ask_user_question`. The fill follows the pointer instantly rather than
|
||||
|
|
|
|||
|
|
@ -433,6 +433,10 @@ Each status family has a foreground, a `-subtle` background, a `-border`, and a
|
|||
and Dialog scrims: `surface-overlay` at the `scrimOpacity`,
|
||||
`alertScrimOpacity` and `modalScrimOpacity` appearance roles (80%, 90% and
|
||||
65% by default). A bundled scrim dims the page and never lifts it.
|
||||
- `ring-focus-subtle` / `outline-focus-subtle` - The keyboard ring of a row or
|
||||
control inside content (tool rows, attachments, summaries, message
|
||||
navigation). Defaults to `border-heavy`, so a theme that names neither keeps
|
||||
the ring it had.
|
||||
- `ring-focus-control` - The keyboard focus ring of the shared primitives
|
||||
(`Checkbox`, `Switch`, `Field`, `IconButton` and their siblings). Defaults to
|
||||
the primary text ink; a theme that names only `rgb-text-primary` rings its
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ html {
|
|||
--border-destructive: var(--red-600);
|
||||
--border-control: var(--gray-200);
|
||||
--border-field-focus: var(--focus-control);
|
||||
--focus-subtle: var(--border-heavy);
|
||||
--field-fill: var(--surface-primary);
|
||||
--field-text: var(--text-primary);
|
||||
--surface-tooltip: var(--surface-primary);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ describe.each([
|
|||
const tokens = Object.keys(theme) as Array<keyof IThemeRGB>;
|
||||
|
||||
it('covers every registry color', () => {
|
||||
expect(tokens).toHaveLength(147);
|
||||
expect(tokens).toHaveLength(148);
|
||||
});
|
||||
|
||||
it('resolves every registry color to the runtime theme value', () => {
|
||||
|
|
@ -103,6 +103,7 @@ const colorAliases: Array<[string, string]> = [
|
|||
['--dialog-title', '--text-primary'],
|
||||
['--badge-label', '--text-primary'],
|
||||
['--border-field-focus', '--focus-control'],
|
||||
['--focus-subtle', '--border-heavy'],
|
||||
['--field-fill', '--surface-primary'],
|
||||
['--field-text', '--text-primary'],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -304,6 +304,21 @@ describe('theme registry', () => {
|
|||
expect(resolved.colors['rgb-chart-widget-stroke']).toBe('50 51 52');
|
||||
});
|
||||
|
||||
it('rings subtle focus in the heavy border for a theme that predates the role', () => {
|
||||
const resolved = resolveTheme(
|
||||
{
|
||||
version: 1,
|
||||
name: 'heavy-border-reference',
|
||||
modes: { light: { colors: { 'rgb-border-heavy': '10 20 30' } } },
|
||||
},
|
||||
'light',
|
||||
);
|
||||
|
||||
expect(resolved.colors['rgb-focus-subtle']).toBe('10 20 30');
|
||||
expect(defaultTheme['rgb-focus-subtle']).toBe(defaultTheme['rgb-border-heavy']);
|
||||
expect(darkTheme['rgb-focus-subtle']).toBe(darkTheme['rgb-border-heavy']);
|
||||
});
|
||||
|
||||
it('accepts table lengths in px or rem, zero included, and rejects other units', () => {
|
||||
const withTable = (tableCellSpaceY: string, tableRowStroke: string) =>
|
||||
({
|
||||
|
|
|
|||
|
|
@ -715,6 +715,11 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
|
|||
customColors?.['rgb-border-light'] !== undefined
|
||||
? { 'rgb-chart-widget-stroke': customColors['rgb-border-light'] }
|
||||
: {};
|
||||
const focusSubtleFallback: IThemeRGB =
|
||||
customColors?.['rgb-focus-subtle'] === undefined &&
|
||||
customColors?.['rgb-border-heavy'] !== undefined
|
||||
? { 'rgb-focus-subtle': customColors['rgb-border-heavy'] }
|
||||
: {};
|
||||
const borderControlSource =
|
||||
customColors != null ? controlBorderFallback(customColors) : undefined;
|
||||
const borderControlFallback: IThemeRGB =
|
||||
|
|
@ -789,6 +794,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
|
|||
...drawerEdgeFallback,
|
||||
...chartWidgetSurfaceFallback,
|
||||
...chartWidgetStrokeFallback,
|
||||
...focusSubtleFallback,
|
||||
...switchThumbFallback,
|
||||
...fieldFillFallback,
|
||||
...overlayFallback,
|
||||
|
|
|
|||
|
|
@ -403,6 +403,12 @@ describe('clickhouse theme definition', () => {
|
|||
).toEqual([]);
|
||||
});
|
||||
|
||||
/** Click UI's keyboard outline is the focus ring, on rows inside content as on controls. */
|
||||
it.each<ThemeMode>(['light', 'dark'])('rings subtle focus in the outline in %s', (mode) => {
|
||||
const { colors } = resolveTheme(clickHouseTheme, mode);
|
||||
expect(colors['rgb-focus-subtle']).toBe(colors['rgb-focus-outline']);
|
||||
});
|
||||
|
||||
/** Click UI's control height, button padding and gap, `transition.default`, and the two steps of
|
||||
* its `spaces` scale the shared spacing takes. */
|
||||
it('sizes theme controls and the shared spacing from Click UI', () => {
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ export const clickHouseLightTheme: IThemeRGB = {
|
|||
'rgb-border-destructive': '193 0 0', // #c10000 (palette.danger.600)
|
||||
'rgb-border-control': '128 134 145', // #808691 (palette.slate.500, 3.42:1 on background.muted)
|
||||
'rgb-border-field-focus': '22 21 23', // #161517 (field.color.stroke.active)
|
||||
'rgb-focus-subtle': '67 126 239', // #437eef (outline.default, 3.84:1 on white)
|
||||
'rgb-field-fill': '251 252 255', // #fbfcff (field.color.background.default)
|
||||
'rgb-field-text': '48 46 50', // #302e32 (field.color.text.default)
|
||||
'rgb-surface-tooltip': '29 29 29', // #1d1d1d (tooltip.color.background.default, lch(10.767 0 0 / 0.85) taken opaque)
|
||||
|
|
@ -289,6 +290,7 @@ export const clickHouseDarkTheme: IThemeRGB = {
|
|||
'rgb-border-destructive': '255 117 117', // #ff7575 (palette.danger.300)
|
||||
'rgb-border-control': '128 128 128', // #808080 (palette.neutral.500, 3.73:1 on background.muted)
|
||||
'rgb-border-field-focus': '250 255 105', // #faff69 (field.color.stroke.active)
|
||||
'rgb-focus-subtle': '250 255 105', // #faff69 (outline.default)
|
||||
'rgb-field-fill': '45 45 45', // rgb(17.794% 17.794% 17.794%) (field.color.background.default)
|
||||
'rgb-field-text': '230 231 233', // #e6e7e9 (field.color.text.default)
|
||||
'rgb-surface-tooltip': '50 50 50', // #323232 (palette.neutral.712; tooltip.color.background.default #282828 would vanish on the #282828 canvas)
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ const colorSources: Record<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
|
|||
'rgb-ring-primary': 'global.color.outline.default',
|
||||
'rgb-focus-outline': 'global.color.outline.default',
|
||||
'rgb-focus-control': 'global.color.outline.default',
|
||||
'rgb-focus-subtle': 'global.color.outline.default',
|
||||
'rgb-header-primary': 'global.color.background.default',
|
||||
'rgb-header-hover': 'global.color.background.muted',
|
||||
'rgb-header-button-hover': 'global.color.background.muted',
|
||||
|
|
@ -218,6 +219,7 @@ const colorSources: Record<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
|
|||
'rgb-ring-primary': 'global.color.outline.default',
|
||||
'rgb-focus-outline': 'global.color.outline.default',
|
||||
'rgb-focus-control': 'global.color.outline.default',
|
||||
'rgb-focus-subtle': 'global.color.outline.default',
|
||||
'rgb-header-primary': 'global.color.background.default',
|
||||
'rgb-header-hover': 'global.color.background.muted',
|
||||
'rgb-header-button-hover': 'global.color.background.muted',
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ export const darkTheme: IThemeRGB = {
|
|||
'rgb-border-destructive': '239 68 68', // #ef4444 (red-500)
|
||||
'rgb-border-control': '33 33 33', // #212121 (gray-800), the stock field edge
|
||||
'rgb-border-field-focus': '236 236 236', // #ececec (gray-100, matching focus-control)
|
||||
'rgb-focus-subtle': '89 89 89', // #595959 (gray-500, matching border-heavy)
|
||||
'rgb-field-fill': '13 13 13', // #0d0d0d (gray-900, matching surface-primary)
|
||||
'rgb-field-text': '236 236 236', // #ececec (gray-100, matching text-primary)
|
||||
'rgb-surface-tooltip': '13 13 13', // matching surface-primary
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ export const defaultTheme: IThemeRGB = {
|
|||
'rgb-border-destructive': '220 38 38', // #dc2626 (red-600)
|
||||
'rgb-border-control': '227 227 227', // #e3e3e3 (gray-200), the stock field edge
|
||||
'rgb-border-field-focus': '33 33 33', // #212121 (gray-800, matching focus-control)
|
||||
'rgb-focus-subtle': '153 150 150', // #999696 (gray-400, matching border-heavy)
|
||||
'rgb-field-fill': '255 255 255', // #fff (white, matching surface-primary)
|
||||
'rgb-field-text': '33 33 33', // #212121 (gray-800, matching text-primary)
|
||||
'rgb-surface-tooltip': '255 255 255', // matching surface-primary
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ export const highContrastLightTheme: IThemeRGB = {
|
|||
'rgb-border-destructive': '161 0 0', // #a10000
|
||||
'rgb-border-control': '0 0 0', // #000000
|
||||
'rgb-border-field-focus': '0 0 0', // #000000 (matching focus-control)
|
||||
'rgb-focus-subtle': '0 0 0', // #000000 (matching border-heavy)
|
||||
'rgb-field-fill': '255 255 255', // #ffffff (matching surface-primary)
|
||||
'rgb-field-text': '0 0 0', // #000000 (matching text-primary)
|
||||
'rgb-surface-tooltip': '255 255 255', // matching surface-primary
|
||||
|
|
@ -316,6 +317,7 @@ export const highContrastDarkTheme: IThemeRGB = {
|
|||
'rgb-border-destructive': '255 143 143', // #ff8f8f
|
||||
'rgb-border-control': '255 255 255', // #ffffff
|
||||
'rgb-border-field-focus': '255 255 255', // #ffffff (matching focus-control)
|
||||
'rgb-focus-subtle': '255 255 255', // #ffffff (matching border-heavy)
|
||||
'rgb-field-fill': '0 0 0', // #000000 (matching surface-primary)
|
||||
'rgb-field-text': '255 255 255', // #ffffff (matching text-primary)
|
||||
'rgb-surface-tooltip': '0 0 0', // matching surface-primary
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@
|
|||
--color-ring-primary: rgb(var(--ring-primary));
|
||||
--color-focus-outline: rgb(var(--focus-outline));
|
||||
--color-focus-control: rgb(var(--focus-control));
|
||||
/* Follows the heavy border it replaced, for a stylesheet that predates it. */
|
||||
--color-focus-subtle: rgb(var(--focus-subtle, var(--border-heavy)));
|
||||
--color-header-primary: rgb(var(--header-primary));
|
||||
--color-header-hover: rgb(var(--header-hover));
|
||||
--color-header-button-hover: rgb(var(--header-button-hover));
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ export interface IThemeRGB {
|
|||
'rgb-ring-primary'?: string;
|
||||
'rgb-focus-outline'?: string;
|
||||
'rgb-focus-control'?: string;
|
||||
/** The keyboard ring of a row or control inside content (tool rows, attachments, summaries,
|
||||
* message navigation); `rgb-border-heavy` when a theme omits it. */
|
||||
'rgb-focus-subtle'?: string;
|
||||
|
||||
// Header colors
|
||||
'rgb-header-primary'?: string;
|
||||
|
|
@ -265,6 +268,7 @@ export interface IThemeVariables {
|
|||
'--ring-primary': string;
|
||||
'--focus-outline': string;
|
||||
'--focus-control': string;
|
||||
'--focus-subtle': string;
|
||||
'--header-primary': string;
|
||||
'--header-hover': string;
|
||||
'--header-button-hover': string;
|
||||
|
|
@ -424,6 +428,7 @@ export interface IThemeColors {
|
|||
'ring-primary'?: string;
|
||||
'focus-outline'?: string;
|
||||
'focus-control'?: string;
|
||||
'focus-subtle'?: string;
|
||||
'header-primary'?: string;
|
||||
'header-hover'?: string;
|
||||
'header-button-hover'?: string;
|
||||
|
|
|
|||
|
|
@ -99,6 +99,10 @@ function mapColors(colors: IThemeRGB, base?: IThemeRGB): Array<[string, string]>
|
|||
variables.push(['--chart-widget-stroke', colors['rgb-border-light']]);
|
||||
}
|
||||
|
||||
if (colors['rgb-focus-subtle'] === undefined && colors['rgb-border-heavy'] !== undefined) {
|
||||
variables.push(['--focus-subtle', colors['rgb-border-heavy']]);
|
||||
}
|
||||
|
||||
const legacyControlBorder = controlBorderFallback(colors);
|
||||
if (legacyControlBorder !== undefined) {
|
||||
variables.push(['--border-control', legacyControlBorder]);
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ export const themeColorTokens = Object.freeze([
|
|||
'rgb-border-destructive',
|
||||
'rgb-border-control',
|
||||
'rgb-border-field-focus',
|
||||
'rgb-focus-subtle',
|
||||
'rgb-field-fill',
|
||||
'rgb-field-text',
|
||||
'rgb-surface-tooltip',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue