diff --git a/web/src/pages/SharedPage.tsx b/web/src/pages/SharedPage.tsx
index add6961..16a5bfb 100644
--- a/web/src/pages/SharedPage.tsx
+++ b/web/src/pages/SharedPage.tsx
@@ -12,7 +12,7 @@ import { api, ApiError } from '@/lib/api';
import type { AnswerState, PublicCollection, PublicDeck, PublicDocument, PublicNote, PublicPayload, PublicQuiz, ShareAi, SnapshotQuestion } from '@/lib/types';
import { cx, formatBytes, plural, useDocumentTitle, useLocalStorage, useMediaQuery, useTheme } from '@/lib/util';
import { Markdown } from '@/ui/Markdown';
-import { Badge, Button, EmptyState, IconButton, Input, PageLoading, Segmented, Switch } from '@/ui';
+import { Badge, Button, EmptyState, IconButton, Input, NumberInput, PageLoading, Segmented, Switch } from '@/ui';
/* ------------------------------ frame ------------------------------ */
@@ -275,7 +275,7 @@ function SharedQuiz({ quiz, storageKey, back, explainUrl, onImmersive }: { quiz:
{prefs.timed && (
)}
@@ -593,8 +593,9 @@ export default function SharedPage() {
}
})();
// A row, so the assistant drawer can sit beside the page on wide screens (it floats over it below 1360px).
+ // Clipped sideways so the drawer sliding in from off-screen never widens or scrolls the page.
return (
-
+
{page}
{assistant}
diff --git a/web/src/ui/index.tsx b/web/src/ui/index.tsx
index 4395c69..41749f9 100644
--- a/web/src/ui/index.tsx
+++ b/web/src/ui/index.tsx
@@ -123,6 +123,85 @@ export const Input = forwardRef;
});
+/** Fits a typed number into a field's limits; null when the text is not a number. */
+export function settleNumber(text: string, opts: { min?: number; max?: number; integer?: boolean }): number | null {
+ if (text.trim() === '') return null;
+ const n = Number(text);
+ if (!Number.isFinite(n)) return null;
+ const whole = opts.integer === false ? n : Math.round(n);
+ return Math.min(opts.max ?? Infinity, Math.max(opts.min ?? -Infinity, whole));
+}
+
+type NumberInputProps = Omit, 'value' | 'onChange' | 'type' | 'min' | 'max'> & {
+ value: number | null;
+ min?: number;
+ max?: number;
+ /** Whole numbers only (the default). */
+ integer?: boolean;
+ /** An empty field means "no value" (null) instead of going back to the last number. */
+ allowEmpty?: boolean;
+ /** Every value within the limits as it is typed, and the settled value when the field is left. */
+ onValueChange: (value: number | null) => void;
+ /** The settled value when the field is left or Enter is pressed (for fields that save on blur). */
+ onCommit?: (value: number | null) => void;
+};
+
+/**
+ * A number field that can be cleared and retyped freely. While it has focus the text is kept as
+ * typed (empty, or out of range part-way through "150"); values within the limits are passed on
+ * as they are typed. On leaving the field (or Enter) the value is fitted into the limits, and an
+ * empty field goes back to the last value unless `allowEmpty`.
+ */
+export const NumberInput = forwardRef(function NumberInput(
+ { value, min, max, integer = true, allowEmpty = false, onValueChange, onCommit, onBlur, onKeyDown, onFocus, ...rest },
+ ref,
+) {
+ const [draft, setDraft] = useState(null);
+ const shown = draft ?? (value === null ? '' : String(value));
+ const settle = () => {
+ if (draft === null) return;
+ const fitted = settleNumber(draft, { min, max, integer });
+ const next = fitted ?? (allowEmpty ? null : value);
+ setDraft(null);
+ if (next !== value) onValueChange(next);
+ onCommit?.(next);
+ };
+ return (
+ {
+ setDraft(shown);
+ onFocus?.(e);
+ }}
+ onChange={(e) => {
+ const text = e.target.value;
+ setDraft(text);
+ if (text.trim() === '') {
+ if (allowEmpty && value !== null) onValueChange(null);
+ return;
+ }
+ const n = Number(text);
+ const whole = integer ? Math.round(n) : n;
+ if (Number.isFinite(n) && whole >= (min ?? -Infinity) && whole <= (max ?? Infinity) && whole !== value) onValueChange(whole);
+ }}
+ onBlur={(e) => {
+ settle();
+ onBlur?.(e);
+ }}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') settle();
+ onKeyDown?.(e);
+ }}
+ {...rest}
+ />
+ );
+});
+
export const Textarea = forwardRef & { autoGrow?: boolean; maxRows?: number }>(function Textarea(
{ className, autoGrow, maxRows = 16, onChange, value, rows = 3, ...rest },
ref,