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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user