fix(webui): gate focus indicators on keyboard navigation modality (#6734)
This commit is contained in:
1 parent
cb95277098
commit
c6fd1b3ecb
24 files changed
+355
-86
No files matched your search
@@ -4,9 +4,12 @@ import { ContextInspector } from "@/components/thread/ContextInspector";
|
||||
import { ComposerUsagePopover } from "@/components/thread/ComposerUsagePopover";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { initializeI18n } from "@/i18n";
|
||||
import { installFocusModality } from "@/lib/focus-modality";
|
||||
import type { ContextSnapshot } from "@/lib/types";
|
||||
import "../src/globals.css";
|
||||
|
||||
installFocusModality();
|
||||
|
||||
const snapshots: ContextSnapshot[] = [
|
||||
{ id: "first", contextWindowTokens: 10000, usage: { prompt_tokens: 1000 }, graph: {
|
||||
nodes: [{ path: "/a.md", name: "a.md", state: "loaded", tokens: 100 }], edges: [],
|
||||
|
||||
@@ -260,3 +260,20 @@ for (const [file, renderedIndex, sourceLine, reverse] of [["long.ts", 58, 59, fa
|
||||
await expect(line).toHaveCount(0);
|
||||
});
|
||||
}
|
||||
|
||||
test("diff toggle stays quiet on Shift+click and Escape, then shows ring on keyboard Tab", async ({ page }) => {
|
||||
await page.goto("/browser/fixture.html?case=file-diff");
|
||||
const toggle = page.getByRole("region", { name: "long.ts", exact: true }).getByTestId("file-edit-diff-toggle");
|
||||
await page.keyboard.down("Shift");
|
||||
await toggle.click();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.up("Shift");
|
||||
await expect(toggle).toBeFocused();
|
||||
await expect(toggle).toHaveCSS("outline-style", "none");
|
||||
await expect(toggle).toHaveCSS("box-shadow", "none");
|
||||
|
||||
await page.keyboard.press("Tab");
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
await expect(toggle).toBeFocused();
|
||||
expect(await toggle.evaluate((node) => getComputedStyle(node).boxShadow)).not.toBe("none");
|
||||
});
|
||||
@@ -4,8 +4,11 @@ import { createRoot } from "react-dom/client";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { initializeI18n, setAppLanguage } from "@/i18n";
|
||||
import { LOCALE_STORAGE_KEY, normalizeLocale } from "@/i18n/config";
|
||||
import { installFocusModality } from "@/lib/focus-modality";
|
||||
import "../src/globals.css";
|
||||
|
||||
installFocusModality();
|
||||
|
||||
const parameters = new URLSearchParams(location.search);
|
||||
const fixtureCase = parameters.get("case");
|
||||
const historyPreview = parameters.get("preview");
|
||||
|
||||
@@ -12,8 +12,11 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigge
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { initializeI18n } from "@/i18n";
|
||||
import { installFocusModality } from "@/lib/focus-modality";
|
||||
import "../src/globals.css";
|
||||
|
||||
installFocusModality();
|
||||
|
||||
function OverlayFocusFixture() {
|
||||
const composer = useRef<HTMLTextAreaElement>(null);
|
||||
const [preset, setPreset] = useState("First model");
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { surfaceFocusProps } from "@/lib/surface-focus";
|
||||
import { useContext, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { SidebarPanelActionsContext } from "@/components/ui/sidebar-panel";
|
||||
@@ -51,8 +50,7 @@ export function FilePreviewPanelView({ path, state, imageOpen, onImageOpenChange
|
||||
<section aria-label={t("filePreview.aria")} data-testid="file-preview-panel" className="flex min-h-0 flex-1 flex-col">
|
||||
{markdown && (actionsHost ? createPortal(modeControl, actionsHost) : <div className="flex shrink-0 justify-end px-4 py-2">{modeControl}</div>)}
|
||||
<div key={mode} data-file-preview-scroll tabIndex={0}
|
||||
{...surfaceFocusProps}
|
||||
className="min-h-0 flex-1 overflow-auto outline-none data-[keyboard-focus]:ring-2 data-[keyboard-focus]:ring-inset data-[keyboard-focus]:ring-ring/60">
|
||||
className="min-h-0 flex-1 overflow-auto outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/60">
|
||||
{state.status === "loading" ? (
|
||||
<div role="status" aria-label={t("filePreview.loading", { defaultValue: "Loading preview..." })}
|
||||
className="h-full" aria-busy="true">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { currentLocale, setAppLanguage } from "@/i18n";
|
||||
@@ -8,24 +7,15 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
|
||||
export function LanguageSwitcher({ className }: { className?: string }) {
|
||||
const { t } = useTranslation();
|
||||
const [pointerFocus, setPointerFocus] = useState(false);
|
||||
return (
|
||||
<Select value={currentLocale()} onValueChange={(value) => { void setAppLanguage(value as SupportedLocale); }}>
|
||||
<SelectTrigger
|
||||
className={cn("min-w-40 rounded-full", pointerFocus && "focus-visible:ring-0", className)}
|
||||
className={cn("min-w-40 rounded-full", className)}
|
||||
aria-label={t("sidebar.language.ariaLabel")}
|
||||
onPointerDown={() => setPointerFocus(true)}
|
||||
onKeyDown={() => setPointerFocus(false)}
|
||||
onBlur={() => setPointerFocus(false)}
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent
|
||||
onPointerUpCapture={() => setPointerFocus(true)}
|
||||
onPointerDownOutside={() => setPointerFocus(true)}
|
||||
onKeyDownCapture={() => setPointerFocus(false)}
|
||||
onEscapeKeyDown={() => setPointerFocus(false)}
|
||||
>
|
||||
<SelectContent>
|
||||
{supportedLocales.map((option) => (
|
||||
<SelectItem
|
||||
key={option.code}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { surfaceFocusProps } from "@/lib/surface-focus";
|
||||
import {
|
||||
Children,
|
||||
isValidElement,
|
||||
@@ -689,7 +688,7 @@ export default function MarkdownTextRenderer({
|
||||
void _node;
|
||||
return (
|
||||
<div
|
||||
data-testid="markdown-data-table" {...surfaceFocusProps}
|
||||
data-testid="markdown-data-table"
|
||||
data-table-kind="data"
|
||||
role="region"
|
||||
tabIndex={0}
|
||||
@@ -697,7 +696,7 @@ export default function MarkdownTextRenderer({
|
||||
className={cn(
|
||||
"not-prose mb-5 mt-3 w-full max-w-full overflow-x-auto rounded-lg",
|
||||
"border border-border/65 bg-muted/20",
|
||||
"overscroll-x-contain outline-none data-[keyboard-focus]:ring-2 data-[keyboard-focus]:ring-ring",
|
||||
"overscroll-x-contain outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
<table
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { surfaceFocusProps } from "@/lib/surface-focus";
|
||||
import { useEffect, useId, useRef, type PointerEvent, type ReactNode, type Ref } from "react";
|
||||
import { SidebarPanel } from "@/components/ui/sidebar-panel";
|
||||
import { PanelRightClose, X } from "lucide-react";
|
||||
@@ -99,8 +98,8 @@ export function PreviewPane({ tabs, activeId, width, isClosing, onSelect, onClos
|
||||
className="file-preview-resize group absolute inset-y-0 left-0 z-20 hidden w-2 cursor-col-resize touch-none justify-start focus-visible:outline-none">
|
||||
<span aria-hidden className="h-full w-px bg-foreground/25 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100" />
|
||||
</button>
|
||||
<div role="tabpanel" {...surfaceFocusProps} id={`${id}-panel`} aria-labelledby={`${id}-tab-${tabs.findIndex((tab) => tab.id === activeId)}`} tabIndex={0}
|
||||
className="flex min-h-0 flex-1 flex-col outline-none data-[keyboard-focus]:ring-2 data-[keyboard-focus]:ring-inset data-[keyboard-focus]:ring-ring">
|
||||
<div role="tabpanel" id={`${id}-panel`} aria-labelledby={`${id}-tab-${tabs.findIndex((tab) => tab.id === activeId)}`} tabIndex={0}
|
||||
className="flex min-h-0 flex-1 flex-col outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring">
|
||||
{children}
|
||||
</div>
|
||||
</SidebarPanel>;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { modelAPIConfigurable, preferredModelAPI, REQUEST_API_LABELS } from "@/components/settings/models/modelAPI";
|
||||
@@ -6,7 +5,6 @@ import { ToggleButton } from "@/components/ui/toggle-button";
|
||||
import { SettingsRow } from "@/components/settings/shared/SettingsControls";
|
||||
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { ModelAPIConfig, ProviderRequestAPI, SettingsPayload } from "@/lib/types";
|
||||
|
||||
export function ModelAPIControl({
|
||||
@@ -26,7 +24,6 @@ export function ModelAPIControl({
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const controlTitle = title ?? t("settings.models.requestAPI");
|
||||
const [pointerFocus, setPointerFocus] = useState(false);
|
||||
const requestAPIs = Array.isArray(provider?.request_apis) ? provider.request_apis : undefined;
|
||||
const configurable = modelAPIConfigurable(provider);
|
||||
const fixedAPI = requestAPIs?.length === 1 ? requestAPIs[0] : undefined;
|
||||
@@ -69,19 +66,11 @@ export function ModelAPIControl({
|
||||
}}>
|
||||
<SelectTrigger
|
||||
aria-label={controlTitle}
|
||||
className={cn("w-full rounded-full", pointerFocus && "focus-visible:ring-0")}
|
||||
onPointerDown={() => setPointerFocus(true)}
|
||||
onKeyDown={() => setPointerFocus(false)}
|
||||
onBlur={() => setPointerFocus(false)}
|
||||
className="w-full rounded-full"
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent
|
||||
onPointerUpCapture={() => setPointerFocus(true)}
|
||||
onPointerDownOutside={() => setPointerFocus(true)}
|
||||
onKeyDownCapture={() => setPointerFocus(false)}
|
||||
onEscapeKeyDown={() => setPointerFocus(false)}
|
||||
>
|
||||
<SelectContent>
|
||||
{options.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>{option.label}</SelectItem>
|
||||
))}
|
||||
|
||||
@@ -275,7 +275,6 @@ export function ModelsSettings({
|
||||
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
|
||||
t(key, { defaultValue: fallback, ...(values ?? {}) });
|
||||
const [editorOpen, setEditorOpen] = useState(false);
|
||||
const [hideEditorReturnFocus, setHideEditorReturnFocus] = useState(false);
|
||||
const [advancedOpen, setAdvancedOpen] = useState(false);
|
||||
const resolvedAutomaticAPI = useAutomaticModelAPI({
|
||||
token,
|
||||
@@ -437,7 +436,6 @@ export function ModelsSettings({
|
||||
preset: SettingsPayload["model_presets"][number],
|
||||
rowKey: string,
|
||||
) => {
|
||||
setHideEditorReturnFocus(false);
|
||||
editorTriggerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
if (edits.needsCompletion() && !(await edits.commit())) return;
|
||||
if (!creating && selectedPreset?.name === preset.name && activeEditorRowKey === rowKey) {
|
||||
@@ -848,11 +846,9 @@ export function ModelsSettings({
|
||||
aria-label={ordered ? `${name}. ${t("settings.models.dragToReorder")}` : name}
|
||||
data-testid={`model-call-order-row-${name}`}
|
||||
onPointerDown={(event) => {
|
||||
setHideEditorReturnFocus(false);
|
||||
presetDrag.start(event, key);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Escape") setHideEditorReturnFocus(false);
|
||||
if (event.currentTarget !== event.target) return;
|
||||
if (ordered && event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
@@ -871,7 +867,7 @@ export function ModelsSettings({
|
||||
ordered && (callOrderBusy ? "cursor-wait" : "cursor-grab active:cursor-grabbing"),
|
||||
!isDragging && "settings-hover",
|
||||
isSelected && "bg-muted/45",
|
||||
!hideEditorReturnFocus && "focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
|
||||
"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
<div className="contents">
|
||||
@@ -881,8 +877,7 @@ export function ModelsSettings({
|
||||
aria-haspopup="dialog"
|
||||
disabled={!preset}
|
||||
onClick={() => preset && selectPreset(preset, key)}
|
||||
className={cn("col-span-2 grid min-w-0 grid-cols-subgrid items-center rounded-control text-left outline-none",
|
||||
!hideEditorReturnFocus && "focus-visible:ring-2 focus-visible:ring-ring")}
|
||||
className="col-span-2 grid min-w-0 grid-cols-subgrid items-center rounded-control text-left outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
{presetConfigured ? (
|
||||
<span className={cn("relative aspect-square min-w-8", primary ? "w-[calc(var(--preset-title-size)*1.375+1.5rem)]" : "h-8")}>
|
||||
@@ -978,13 +973,10 @@ export function ModelsSettings({
|
||||
type="button"
|
||||
variant="link"
|
||||
size="sm"
|
||||
className={cn("mr-auto h-11 gap-2 text-[13px] font-normal text-muted-foreground hover:font-semibold hover:text-orange-700 hover:no-underline dark:hover:text-orange-400 sm:h-9",
|
||||
hideEditorReturnFocus && "focus-visible:ring-0 focus-visible:ring-offset-0")}
|
||||
onKeyDown={(event) => { if (event.key !== "Escape") setHideEditorReturnFocus(false); }}
|
||||
className="mr-auto h-11 gap-2 text-[13px] font-normal text-muted-foreground hover:font-semibold hover:text-orange-700 hover:no-underline dark:hover:text-orange-400 sm:h-9"
|
||||
disabled={callOrderBusy}
|
||||
onClick={(event) => {
|
||||
editorTriggerRef.current = event.currentTarget;
|
||||
setHideEditorReturnFocus(false);
|
||||
setEditorRowKey(null);
|
||||
setEditorOpen(true);
|
||||
onBeginCreate();
|
||||
@@ -1011,7 +1003,6 @@ export function ModelsSettings({
|
||||
<DialogContent aria-describedby={undefined}
|
||||
onChangeCapture={edits.onChangeCapture} onFocusCapture={edits.onFocusCapture}
|
||||
onBlurCapture={edits.onBlurCapture}
|
||||
onEscapeKeyDown={() => setHideEditorReturnFocus(true)}
|
||||
className="relative max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none gap-0 overflow-y-auto p-0"
|
||||
onOpenAutoFocus={(event) => {
|
||||
if (!focusImageInput.current || !imageInputRef.current) return;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
.appearance-theme-option { position: relative; min-width: 0; cursor: pointer; }
|
||||
.appearance-theme-input { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
|
||||
.appearance-theme-card { --appearance-theme-inset: 8px; display: block; padding: var(--appearance-theme-inset); border: 1px solid hsl(var(--border)); border-radius: var(--radius-panel); background: hsl(var(--settings-surface)); transition: border-color 160ms ease; }
|
||||
.appearance-theme-option input:focus-visible + .appearance-theme-card { outline: 2px solid hsl(var(--ring) / 0.65); outline-offset: 3px; }
|
||||
:where(:root:not([data-focus-modality="pointer"])) .appearance-theme-option input:focus-visible + .appearance-theme-card { outline: 2px solid hsl(var(--ring) / 0.65); outline-offset: 3px; }
|
||||
.appearance-theme-check { opacity: 0; }
|
||||
.appearance-theme-option input:checked + .appearance-theme-card .appearance-theme-check { opacity: 1; }
|
||||
.appearance-theme-option input:checked + .appearance-theme-card { border-color: hsl(var(--foreground) / 0.5); }
|
||||
@@ -77,11 +77,11 @@ html[data-custom-background] .appearance-reading-card { background: hsl(var(--se
|
||||
html[data-custom-background] .appearance-reading-preview { background: hsl(var(--background) / 0.35); }
|
||||
|
||||
.background-settings-trigger { display: inline-flex; min-height: 32px; align-items: center; justify-content: flex-end; gap: 8px; font-size: 13px; }
|
||||
.background-settings-row:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: -2px; }
|
||||
:where(:root:not([data-focus-modality="pointer"])) .background-settings-row:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: -2px; }
|
||||
.background-settings-thumbnail { width: 52px; height: 32px; border-radius: 7px; background: var(--custom-background-image) center / cover; box-shadow: inset 0 0 0 1px hsl(var(--border) / 0.7); }
|
||||
.background-settings-dialog { width: min(440px, calc(100vw - 32px)); gap: 16px; }
|
||||
.background-settings-preview { position: relative; display: flex; width: 100%; min-width: 0; max-width: 100%; aspect-ratio: 16 / 9; min-height: 180px; align-items: center; justify-content: center; overflow: hidden; border: 1px solid hsl(var(--border) / 0.65); border-radius: var(--radius-panel); background-color: hsl(var(--muted) / 0.5); background-position: center; background-size: cover; cursor: pointer; }
|
||||
.background-settings-preview:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 3px; }
|
||||
:where(:root:not([data-focus-modality="pointer"])) .background-settings-preview:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 3px; }
|
||||
.background-settings-preview-action { position: absolute; z-index: 1; right: 10px; bottom: 10px; display: inline-flex; align-items: center; gap: 5px; min-height: 32px; padding: 0 10px; border: 1px solid hsl(var(--border) / 0.7); border-radius: var(--radius-control); background: hsl(var(--background) / 0.9); color: hsl(var(--foreground)); font-size: 12px; box-shadow: 0 1px 4px hsl(var(--foreground) / 0.1); }
|
||||
.background-settings-footer { display: flex; flex-direction: row; align-items: center; justify-content: flex-end; gap: 8px; }
|
||||
.background-settings-remove { margin-right: auto; }
|
||||
@@ -92,7 +92,7 @@ html[data-custom-background] .appearance-reading-preview { background: hsl(var(-
|
||||
.background-blur-control input[type="range"]::-moz-range-track { height: 4px; border-radius: 999px; background: linear-gradient(to right, hsl(var(--foreground) / 0.65) var(--slider-progress), hsl(var(--muted-foreground) / 0.22) var(--slider-progress)); }
|
||||
.background-blur-control input[type="range"]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; margin-top: -6px; border: 1px solid hsl(var(--foreground) / 0.45); border-radius: 50%; background: hsl(var(--background)); box-shadow: 0 1px 3px hsl(var(--foreground) / 0.18); }
|
||||
.background-blur-control input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 1px solid hsl(var(--foreground) / 0.45); border-radius: 50%; background: hsl(var(--background)); box-shadow: 0 1px 3px hsl(var(--foreground) / 0.18); }
|
||||
.background-blur-control input[type="range"]:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 3px; border-radius: 4px; }
|
||||
:where(:root:not([data-focus-modality="pointer"])) .background-blur-control input[type="range"]:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 3px; border-radius: 4px; }
|
||||
.background-blur-control input[type="range"]:disabled { cursor: default; opacity: 0.5; }
|
||||
.background-settings-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: hsl(var(--muted-foreground)); font-size: 13px; }
|
||||
.background-settings-preview:hover .background-settings-empty { color: hsl(var(--foreground)); }
|
||||
@@ -495,7 +495,7 @@ function ToolsPanel({
|
||||
return (
|
||||
<label
|
||||
key={toolName}
|
||||
className="flex min-h-11 cursor-pointer items-center gap-3 border-b border-border/45 px-3.5 py-2.5 transition-colors last:border-b-0 settings-hover has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-inset has-[:focus-visible]:ring-ring"
|
||||
className="flex min-h-11 cursor-pointer items-center gap-3 border-b border-border/45 px-3.5 py-2.5 transition-colors last:border-b-0 settings-hover has-focus-visible:ring-2 has-focus-visible:ring-inset has-focus-visible:ring-ring"
|
||||
>
|
||||
<span className="relative h-5 w-5 shrink-0">
|
||||
<input
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { surfaceFocusProps } from "@/lib/surface-focus";
|
||||
import { FullAccessIcon, RestrictedAccessIcon, WorkspaceIcon } from "@/components/icons/product-icons";
|
||||
import type { HTMLAttributes, ReactElement, RefObject } from "react";
|
||||
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||
@@ -645,8 +644,8 @@ export function WorkspaceProjectPicker({ disabled, scope, defaultScope, controls
|
||||
</nav>}
|
||||
<div className={cn("mr-[var(--picker-toolbar-inset)] flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-[var(--picker-field-radius)] bg-[#fcfcfc] dark:bg-muted", compact && showLocations && canBrowse && "hidden")}>
|
||||
<div ref={attachColumns} data-workspace-columns className="sidebar-scrollbar flex flex-1 min-h-0 min-w-0 overflow-x-auto overscroll-x-contain">
|
||||
{columns.map((column, columnIndex) => (!compact || columnIndex === currentColumnIndex) && <WorkspaceDirectoryColumn key={columnIndex} {...surfaceFocusProps} options={column.options} selectedPath={column.selectedPath} initialScrollTop={previewingPath ? 0 : currentVisit.scrollTops[columnIndex] ?? 0} visitRevision={history.revision} activeIndex={highlightActive && columnIndex === activeColumn ? activeOption : null}
|
||||
id={`${optionsId}-${columnIndex}`} data-workspace-column={columnIndex} data-current-directory={columnIndex === currentColumnIndex ? "" : undefined} role="listbox" tabIndex={0} aria-activedescendant={highlightActive && columnIndex === activeColumn && column.options.length ? `${optionsId}-${columnIndex}-${activeOption}` : undefined} aria-label={column.path || t("thread.composer.workspace.projectAria")} aria-busy={columnIndex === currentColumnIndex && loading} style={{ width: `${compact ? 100 : 100 / columnCount}%` }} className="sidebar-scrollbar relative min-w-0 shrink-0 overflow-x-hidden overflow-y-auto px-2 outline-none [scrollbar-gutter:stable] data-[keyboard-focus]:ring-2 data-[keyboard-focus]:ring-inset data-[keyboard-focus]:ring-ring/50"
|
||||
{columns.map((column, columnIndex) => (!compact || columnIndex === currentColumnIndex) && <WorkspaceDirectoryColumn key={columnIndex} options={column.options} selectedPath={column.selectedPath} initialScrollTop={previewingPath ? 0 : currentVisit.scrollTops[columnIndex] ?? 0} visitRevision={history.revision} activeIndex={highlightActive && columnIndex === activeColumn ? activeOption : null}
|
||||
id={`${optionsId}-${columnIndex}`} data-workspace-column={columnIndex} data-current-directory={columnIndex === currentColumnIndex ? "" : undefined} role="listbox" tabIndex={0} aria-activedescendant={highlightActive && columnIndex === activeColumn && column.options.length ? `${optionsId}-${columnIndex}-${activeOption}` : undefined} aria-label={column.path || t("thread.composer.workspace.projectAria")} aria-busy={columnIndex === currentColumnIndex && loading} style={{ width: `${compact ? 100 : 100 / columnCount}%` }} className="sidebar-scrollbar relative min-w-0 shrink-0 overflow-x-hidden overflow-y-auto px-2 outline-none [scrollbar-gutter:stable] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/50"
|
||||
onFocus={event => { if (event.target === event.currentTarget) { setActiveColumn(columnIndex); setActiveIndex(0); } }}
|
||||
onKeyDown={event => {
|
||||
if (event.target !== event.currentTarget || event.altKey || event.metaKey || event.ctrlKey || pickingFolder) return;
|
||||
|
||||
@@ -217,6 +217,7 @@ function FileUnifiedDiff({
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 rounded px-1 py-0.5 text-[11px] font-medium",
|
||||
"text-muted-foreground transition-colors hover:bg-muted/65 hover:text-foreground",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
data-testid="file-edit-diff-expand-lines"
|
||||
onClick={() => setExpandedLines(true)}
|
||||
@@ -235,6 +236,7 @@ function FileUnifiedDiff({
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 rounded px-1 py-0.5 text-[11px] font-medium",
|
||||
"text-muted-foreground transition-colors hover:bg-muted/65 hover:text-foreground",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
data-testid="file-edit-diff-collapse-lines"
|
||||
onClick={() => setExpandedLines(false)}
|
||||
@@ -258,6 +260,7 @@ function FileUnifiedDiff({
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 rounded px-1 py-0.5 font-medium",
|
||||
"text-muted-foreground transition-colors hover:bg-muted/65 hover:text-foreground",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
data-testid="file-edit-diff-open-file"
|
||||
onClick={() => onOpenFilePreview(previewPath)}
|
||||
@@ -284,6 +287,7 @@ function FileUnifiedDiff({
|
||||
className={cn(
|
||||
"flex w-full cursor-pointer items-center gap-2 rounded-md border border-border/45 bg-muted/35 px-2 py-1 text-left",
|
||||
"text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/50",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
<ChevronRight
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
.goal-island-trigger:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
.goal-island-trigger:focus-visible > span:last-child {
|
||||
:where(:root:not([data-focus-modality="pointer"])) .goal-island-trigger:focus-visible > span:last-child {
|
||||
text-decoration: underline;
|
||||
text-decoration-thickness: 2px;
|
||||
text-underline-offset: 4px;
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.reasoning-effort-slider:has(input:focus-visible) .reasoning-effort-track {
|
||||
:where(:root:not([data-focus-modality="pointer"])) .reasoning-effort-slider:has(input:focus-visible) .reasoning-effort-track {
|
||||
outline: 2px solid hsl(var(--ring));
|
||||
outline-offset: 5px;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { surfaceFocusProps } from "@/lib/surface-focus";
|
||||
import { useCallback, useEffect, useRef, useState, type PointerEvent } from "react";
|
||||
import { Minus, Plus } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -122,8 +121,8 @@ export function ImageViewport({
|
||||
const buttonClass = "grid size-9 shrink-0 place-items-center rounded-full transition-colors hover:text-foreground disabled:opacity-30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
|
||||
|
||||
return <>
|
||||
<div ref={viewport} data-testid={testId} {...surfaceFocusProps} tabIndex={0} role="group" aria-label={t("lightbox.gestures")}
|
||||
className={cn("flex min-h-0 min-w-0 touch-none select-none items-center justify-center overflow-hidden outline-none data-[keyboard-focus]:ring-1 data-[keyboard-focus]:ring-ring", view.scale > 1 ? dragging ? "cursor-grabbing" : "cursor-grab" : "cursor-zoom-in", className)}
|
||||
<div ref={viewport} data-testid={testId} tabIndex={0} role="group" aria-label={t("lightbox.gestures")}
|
||||
className={cn("flex min-h-0 min-w-0 touch-none select-none items-center justify-center overflow-hidden outline-none focus-visible:ring-1 focus-visible:ring-ring", view.scale > 1 ? dragging ? "cursor-grabbing" : "cursor-grab" : "cursor-zoom-in", className)}
|
||||
onPointerDown={onPointerDown} onPointerMove={onPointerMove} onPointerUp={endPointer} onPointerCancel={endPointer} onLostPointerCapture={endPointer}
|
||||
onDoubleClick={(event) => zoom(viewRef.current.scale > 1 ? 1 : 2, { x: event.clientX, y: event.clientY })}
|
||||
onKeyDown={(event) => {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { createRoot } from "react-dom/client";
|
||||
|
||||
import { installFocusModality } from "@/lib/focus-modality";
|
||||
import { initializeGalleryI18n } from "./i18n";
|
||||
import { Gallery } from "./Gallery";
|
||||
import "@/globals.css";
|
||||
import "./gallery.css";
|
||||
|
||||
installFocusModality();
|
||||
|
||||
const root = document.getElementById("root");
|
||||
if (!root) throw new Error("Gallery root element missing");
|
||||
|
||||
|
||||
+16
-4
@@ -234,6 +234,11 @@
|
||||
@apply border-border;
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 2px solid hsl(var(--ring) / 0.55);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
*,
|
||||
::before,
|
||||
::after {
|
||||
@@ -1043,10 +1048,10 @@
|
||||
|
||||
[data-context-block-active] .message-block-menu-trigger,
|
||||
[data-message-context-menu-open] .message-block-menu-trigger,
|
||||
.message-block-menu-trigger:focus-visible,
|
||||
:where(:root:not([data-focus-modality="pointer"])) .message-block-menu-trigger:focus-visible,
|
||||
[data-context-block-active] .message-block-hover-time,
|
||||
[data-message-context-menu-open] .message-block-hover-time,
|
||||
.message-block-hover-time:focus-visible {
|
||||
:where(:root:not([data-focus-modality="pointer"])) .message-block-hover-time:focus-visible {
|
||||
pointer-events: auto;
|
||||
opacity: 1;
|
||||
}
|
||||
@@ -1422,7 +1427,14 @@
|
||||
}
|
||||
}
|
||||
.thread-composer-surface:focus-within { outline: 2px solid Highlight; }
|
||||
[data-keyboard-focus] { outline: 2px solid Highlight; outline-offset: -2px; }
|
||||
}
|
||||
|
||||
:root[data-focus-modality="pointer"] :focus-visible:not(
|
||||
textarea,
|
||||
[contenteditable],
|
||||
input:not([type="button"], [type="submit"], [type="reset"], [type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"], [type="image"])
|
||||
) {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.thread-composer-footer-actions {
|
||||
@@ -1635,7 +1647,7 @@
|
||||
}
|
||||
|
||||
@media (forced-colors: active) {
|
||||
[data-workbench-move-handle]:focus-visible {
|
||||
:where(:root:not([data-focus-modality="pointer"])) [data-workbench-move-handle]:focus-visible {
|
||||
outline: 2px solid CanvasText;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
const KEYBOARD_NAVIGATION_KEYS = new Set([
|
||||
"Tab",
|
||||
"ArrowUp",
|
||||
"ArrowDown",
|
||||
"ArrowLeft",
|
||||
"ArrowRight",
|
||||
"Home",
|
||||
"End",
|
||||
"PageUp",
|
||||
"PageDown",
|
||||
"Enter",
|
||||
" ",
|
||||
]);
|
||||
|
||||
const NON_TEXT_INPUT_TYPES = new Set([
|
||||
"button",
|
||||
"checkbox",
|
||||
"color",
|
||||
"file",
|
||||
"image",
|
||||
"radio",
|
||||
"range",
|
||||
"reset",
|
||||
"submit",
|
||||
]);
|
||||
|
||||
function isTextEntryElement(target: EventTarget | null): boolean {
|
||||
if (!(target instanceof HTMLElement)) return false;
|
||||
if (target instanceof HTMLTextAreaElement || target.isContentEditable) return true;
|
||||
if (target instanceof HTMLInputElement) {
|
||||
return !NON_TEXT_INPUT_TYPES.has((target.type || "text").toLowerCase());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isKeyboardFocusKey(event: KeyboardEvent): boolean {
|
||||
if (event.isComposing || event.ctrlKey || event.metaKey || event.altKey) return false;
|
||||
if (!KEYBOARD_NAVIGATION_KEYS.has(event.key)) return false;
|
||||
if (isTextEntryElement(event.target)) {
|
||||
if (event.key === "Tab") return true;
|
||||
return event.key === "Enter" && event.target instanceof HTMLInputElement;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
interface InstalledModality {
|
||||
count: number;
|
||||
teardown: () => void;
|
||||
}
|
||||
|
||||
const installedDocuments = new WeakMap<Document, InstalledModality>();
|
||||
|
||||
/**
|
||||
* Track whether the user is navigating by keyboard or pointer on `html[data-focus-modality]`.
|
||||
*
|
||||
* Browsers widen native `:focus-visible` on any keyboard event (such as holding Shift while
|
||||
* clicking, Shift + wheel scrolling, pressing Escape, or triggering shortcuts). Gating focus
|
||||
* indicators on explicit keyboard navigation keys prevents stray focus outlines during pointer
|
||||
* workflows while keeping full keyboard accessibility.
|
||||
*/
|
||||
export function installFocusModality(doc: Document = document): () => void {
|
||||
const existing = installedDocuments.get(doc);
|
||||
if (existing) {
|
||||
existing.count += 1;
|
||||
let released = false;
|
||||
return () => {
|
||||
if (released) return;
|
||||
released = true;
|
||||
existing.count -= 1;
|
||||
if (existing.count === 0) {
|
||||
existing.teardown();
|
||||
installedDocuments.delete(doc);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const root = doc.documentElement;
|
||||
const previous = root.dataset.focusModality;
|
||||
if (!previous) root.dataset.focusModality = "pointer";
|
||||
|
||||
const setPointer = () => {
|
||||
root.dataset.focusModality = "pointer";
|
||||
};
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (isKeyboardFocusKey(event)) root.dataset.focusModality = "keyboard";
|
||||
};
|
||||
|
||||
doc.addEventListener("pointerdown", setPointer, { capture: true, passive: true });
|
||||
doc.addEventListener("mousedown", setPointer, { capture: true, passive: true });
|
||||
doc.addEventListener("touchstart", setPointer, { capture: true, passive: true });
|
||||
doc.addEventListener("keydown", onKeyDown, { capture: true });
|
||||
|
||||
const entry: InstalledModality = {
|
||||
count: 1,
|
||||
teardown: () => {
|
||||
doc.removeEventListener("pointerdown", setPointer, { capture: true });
|
||||
doc.removeEventListener("mousedown", setPointer, { capture: true });
|
||||
doc.removeEventListener("touchstart", setPointer, { capture: true });
|
||||
doc.removeEventListener("keydown", onKeyDown, { capture: true });
|
||||
if (previous === undefined) delete root.dataset.focusModality;
|
||||
else root.dataset.focusModality = previous;
|
||||
},
|
||||
};
|
||||
installedDocuments.set(doc, entry);
|
||||
|
||||
let released = false;
|
||||
return () => {
|
||||
if (released) return;
|
||||
released = true;
|
||||
entry.count -= 1;
|
||||
if (entry.count === 0) {
|
||||
entry.teardown();
|
||||
installedDocuments.delete(doc);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type { HTMLAttributes } from "react";
|
||||
|
||||
const MODIFIER_KEYS = new Set(["Shift", "Control", "Alt", "Meta", "CapsLock"]);
|
||||
|
||||
/** Preserve keyboard focus cues without treating Shift + wheel as navigation. */
|
||||
export const surfaceFocusProps = {
|
||||
onFocusCapture(event) {
|
||||
if (event.target !== event.currentTarget) return;
|
||||
if (event.currentTarget.matches(":focus-visible")) event.currentTarget.dataset.keyboardFocus = "true";
|
||||
else delete event.currentTarget.dataset.keyboardFocus;
|
||||
},
|
||||
onBlurCapture(event) {
|
||||
if (event.target === event.currentTarget) delete event.currentTarget.dataset.keyboardFocus;
|
||||
},
|
||||
onPointerDownCapture(event) {
|
||||
delete event.currentTarget.dataset.keyboardFocus;
|
||||
},
|
||||
onKeyDownCapture(event) {
|
||||
if (event.target === event.currentTarget && !MODIFIER_KEYS.has(event.key)
|
||||
&& !event.ctrlKey && !event.metaKey && !event.altKey) event.currentTarget.dataset.keyboardFocus = "true";
|
||||
},
|
||||
} satisfies HTMLAttributes<HTMLElement>;
|
||||
@@ -3,6 +3,7 @@ import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import "./globals.css";
|
||||
import { initializeI18n } from "./i18n";
|
||||
import { installFocusModality } from "./lib/focus-modality";
|
||||
import { initializePairReturn } from "./lib/remote-pair-return";
|
||||
|
||||
// `crypto.randomUUID` is only defined in secure contexts (HTTPS or localhost).
|
||||
@@ -24,6 +25,7 @@ if (typeof globalThis.crypto !== "undefined" && !("randomUUID" in globalThis.cry
|
||||
const root = document.getElementById("root");
|
||||
if (!root) throw new Error("root element missing");
|
||||
|
||||
installFocusModality();
|
||||
initializePairReturn();
|
||||
window.addEventListener("hashchange", initializePairReturn);
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import postcss from "postcss";
|
||||
import tailwindcss from "tailwindcss";
|
||||
import loadConfig from "tailwindcss/loadConfig";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { installFocusModality } from "@/lib/focus-modality";
|
||||
|
||||
describe("focus modality", () => {
|
||||
const cleanups: Array<() => void> = [];
|
||||
|
||||
afterEach(() => {
|
||||
while (cleanups.length > 0) cleanups.pop()?.();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
function setupModality() {
|
||||
const cleanup = installFocusModality(document);
|
||||
cleanups.push(cleanup);
|
||||
return cleanup;
|
||||
}
|
||||
|
||||
it("keeps pointer modality across Shift+click, modifier keys, Escape, and shortcuts", () => {
|
||||
setupModality();
|
||||
const button = document.createElement("button");
|
||||
button.textContent = "View diff";
|
||||
document.body.append(button);
|
||||
|
||||
expect(document.documentElement.dataset.focusModality).toBe("pointer");
|
||||
|
||||
// Shift held while clicking, followed by key repeat and Escape.
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "Shift", shiftKey: true, bubbles: true }));
|
||||
button.dispatchEvent(new MouseEvent("mousedown", { shiftKey: true, bubbles: true }));
|
||||
button.focus();
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "Shift", shiftKey: true, repeat: true, bubbles: true }));
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "c", ctrlKey: true, bubbles: true }));
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "k", metaKey: true, bubbles: true }));
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", altKey: true, bubbles: true }));
|
||||
|
||||
expect(document.documentElement.dataset.focusModality).toBe("pointer");
|
||||
});
|
||||
|
||||
it("enters keyboard modality on keyboard navigation and keeps it across Escape until pointer input", () => {
|
||||
setupModality();
|
||||
const button = document.createElement("button");
|
||||
document.body.append(button);
|
||||
button.focus();
|
||||
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("keyboard");
|
||||
|
||||
// Escape during keyboard interaction preserves keyboard focus rings on return.
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("keyboard");
|
||||
|
||||
// Any pointer press switches back to pointer modality, even with Shift held.
|
||||
button.dispatchEvent(new MouseEvent("mousedown", { shiftKey: true, bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("pointer");
|
||||
|
||||
// Arrow and activation keys on non-text controls re-enter keyboard modality.
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("keyboard");
|
||||
|
||||
button.dispatchEvent(new Event("touchstart", { bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("pointer");
|
||||
|
||||
button.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("keyboard");
|
||||
});
|
||||
|
||||
it("distinguishes text-entry editing from keyboard focus navigation", () => {
|
||||
setupModality();
|
||||
const input = document.createElement("input");
|
||||
const textarea = document.createElement("textarea");
|
||||
document.body.append(input, textarea);
|
||||
|
||||
// Editing keys inside inputs do not flip pointer modality into keyboard navigation.
|
||||
input.focus();
|
||||
input.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowLeft", bubbles: true }));
|
||||
input.dispatchEvent(new KeyboardEvent("keydown", { key: " ", bubbles: true }));
|
||||
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("pointer");
|
||||
|
||||
// Submitting a single-line input with Enter hands keyboard focus to the destination control.
|
||||
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("keyboard");
|
||||
|
||||
// Pressing Enter inside a multiline textarea does not flip pointer modality.
|
||||
textarea.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
|
||||
textarea.focus();
|
||||
textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("pointer");
|
||||
|
||||
// Tabbing out of a textarea always enters keyboard navigation.
|
||||
textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", bubbles: true }));
|
||||
expect(document.documentElement.dataset.focusModality).toBe("keyboard");
|
||||
});
|
||||
|
||||
it("gates Tailwind focus-visible variants and base outlines on pointer modality while exempting text inputs", async () => {
|
||||
const config = loadConfig(resolve(process.cwd(), "tailwind.config.js"));
|
||||
const source = readFileSync(resolve(process.cwd(), "src/globals.css"), "utf8");
|
||||
const result = await postcss([tailwindcss({
|
||||
...config,
|
||||
content: [{
|
||||
raw: 'class="focus-visible:ring-2 group-focus-visible:ring-2 peer-focus-visible:ring-2 has-focus-visible:ring-2"',
|
||||
}],
|
||||
})]).process(source, { from: undefined });
|
||||
|
||||
const selectors: string[] = [];
|
||||
result.root.walkRules((rule) => {
|
||||
if (rule.selector.includes("focus-visible")) selectors.push(rule.selector);
|
||||
});
|
||||
|
||||
expect(selectors.some((selector) =>
|
||||
selector.includes(".focus-visible\\:ring-2:focus-visible:where(:root:not([data-focus-modality=\"pointer\"]) *")
|
||||
&& selector.includes("textarea"),
|
||||
)).toBe(true);
|
||||
expect(selectors.some((selector) =>
|
||||
selector.includes(':where(:root:not([data-focus-modality="pointer"])) .group:focus-visible .group-focus-visible\\:ring-2'),
|
||||
)).toBe(true);
|
||||
expect(selectors.some((selector) =>
|
||||
selector.includes(':where(:root:not([data-focus-modality="pointer"])) .peer:focus-visible ~ .peer-focus-visible\\:ring-2'),
|
||||
)).toBe(true);
|
||||
expect(selectors.some((selector) =>
|
||||
selector.includes(':where(:root:not([data-focus-modality="pointer"])) .has-focus-visible\\:ring-2:has(:focus-visible)'),
|
||||
)).toBe(true);
|
||||
expect(selectors.some((selector) =>
|
||||
selector.includes(':root[data-focus-modality="pointer"] :focus-visible:not('),
|
||||
)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -158,11 +158,41 @@ export default {
|
||||
plugins: [
|
||||
animate,
|
||||
typography,
|
||||
plugin(({ addVariant, addUtilities }) => {
|
||||
plugin(({ addVariant, matchVariant, addUtilities }) => {
|
||||
const textEntrySelector =
|
||||
'textarea, [contenteditable], input:not([type="button"], [type="submit"], [type="reset"], [type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"], [type="image"])';
|
||||
addUtilities({ ".rounded-full": { cornerShape: "round" } });
|
||||
// Revealing controls on emulated hover can consume the first Safari
|
||||
// tap. Keep these sidebar hover effects on hover-capable pointers.
|
||||
addVariant("media-hover", "@media (hover: hover)");
|
||||
// Gate non-text-entry focus rings on keyboard navigation modality so
|
||||
// Shift+click, Escape, and shortcuts after pointer clicks stay quiet.
|
||||
addVariant(
|
||||
"focus-visible",
|
||||
`&:focus-visible:where(:root:not([data-focus-modality="pointer"]) *, ${textEntrySelector})`,
|
||||
);
|
||||
matchVariant(
|
||||
"group-focus-visible",
|
||||
(_value, { modifier }) => (
|
||||
modifier
|
||||
? `:where(:root:not([data-focus-modality="pointer"])) :merge(.group\\/${modifier}):focus-visible &`
|
||||
: `:where(:root:not([data-focus-modality="pointer"])) :merge(.group):focus-visible &`
|
||||
),
|
||||
{ values: { DEFAULT: "" } },
|
||||
);
|
||||
matchVariant(
|
||||
"peer-focus-visible",
|
||||
(_value, { modifier }) => (
|
||||
modifier
|
||||
? `:where(:root:not([data-focus-modality="pointer"])) :merge(.peer\\/${modifier}):focus-visible ~ &`
|
||||
: `:where(:root:not([data-focus-modality="pointer"])) :merge(.peer):focus-visible ~ &`
|
||||
),
|
||||
{ values: { DEFAULT: "" } },
|
||||
);
|
||||
addVariant(
|
||||
"has-focus-visible",
|
||||
':where(:root:not([data-focus-modality="pointer"])) &:has(:focus-visible)',
|
||||
);
|
||||
}),
|
||||
],
|
||||
};
|
||||
Reference in new issue
Block a user