feat(webui): exact-value keyboard input on generation sliders
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2662,6 +2662,9 @@ function GenerationParamSlider({
|
||||
}) {
|
||||
const anchor = override ?? fallback ?? min;
|
||||
const [draft, setDraft] = useState<number | null>(null);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [editText, setEditText] = useState("");
|
||||
const editActiveRef = useRef(false);
|
||||
const shown = draft ?? anchor;
|
||||
const isOverride = override !== null || draft !== null;
|
||||
|
||||
@@ -2672,6 +2675,29 @@ function GenerationParamSlider({
|
||||
}
|
||||
};
|
||||
|
||||
const startEdit = () => {
|
||||
setEditText(shown.toFixed(2));
|
||||
editActiveRef.current = true;
|
||||
setEditing(true);
|
||||
};
|
||||
|
||||
const finishEdit = (shouldCommit: boolean) => {
|
||||
if (!editActiveRef.current) return;
|
||||
editActiveRef.current = false;
|
||||
setEditing(false);
|
||||
if (!shouldCommit) return;
|
||||
const trimmed = editText.trim();
|
||||
if (trimmed === "") {
|
||||
// Empty input resets to the registry default (only meaningful when an
|
||||
// override exists).
|
||||
if (override !== null) void onCommit(null);
|
||||
return;
|
||||
}
|
||||
const parsed = Number(trimmed);
|
||||
if (!Number.isFinite(parsed) || parsed < min || parsed > max) return;
|
||||
commit(parsed);
|
||||
};
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
@@ -2682,8 +2708,8 @@ function GenerationParamSlider({
|
||||
disabled
|
||||
? `Pick a model to override the registry-configured ${ariaLabel}`
|
||||
: override === null
|
||||
? `${ariaLabel}: registry default ${fallback ?? "unset"} — drag to override`
|
||||
: `${ariaLabel} override — click the value to reset`
|
||||
? `${ariaLabel}: registry default ${fallback ?? "unset"} — drag to override or click the value to type one`
|
||||
: `${ariaLabel} override — click the value to type an exact one; empty + Enter resets`
|
||||
}
|
||||
>
|
||||
<input
|
||||
@@ -2711,26 +2737,43 @@ function GenerationParamSlider({
|
||||
onBlur={(event) => commit(Number(event.target.value))}
|
||||
className="w-16 cursor-pointer accent-[var(--brand)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => {
|
||||
if (override !== null) void onCommit(null);
|
||||
}}
|
||||
title={
|
||||
override !== null
|
||||
? `Reset ${ariaLabel} to the registry default`
|
||||
: undefined
|
||||
}
|
||||
className={cn(
|
||||
"w-12 text-left text-xs tabular-nums",
|
||||
isOverride
|
||||
? "font-medium text-foreground"
|
||||
: "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{shown.toFixed(2)}
|
||||
</button>
|
||||
{editing ? (
|
||||
<input
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
aria-label={`${ariaLabel} exact value`}
|
||||
autoFocus
|
||||
value={editText}
|
||||
onChange={(event) => setEditText(event.target.value)}
|
||||
onFocus={(event) => event.target.select()}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
finishEdit(true);
|
||||
} else if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
finishEdit(false);
|
||||
}
|
||||
}}
|
||||
onBlur={() => finishEdit(true)}
|
||||
className="w-12 text-left text-xs tabular-nums font-medium text-foreground bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
/>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={startEdit}
|
||||
title={`Click to type an exact ${ariaLabel} value`}
|
||||
className={cn(
|
||||
"w-12 text-left text-xs tabular-nums",
|
||||
isOverride
|
||||
? "font-medium text-foreground"
|
||||
: "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{shown.toFixed(2)}
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user