Address Gadfly review on #8: modal focus/close, dim validation, dedup
Build image / build-and-push (push) Successful in 7s
Build image / build-and-push (push) Successful in 7s
Fixes from the PR #27 adversarial review (considered; not graded). Correctness / error-handling - Modal: focus once on mount and attach the keydown listener once (latest onClose/busy via refs), so a parent re-render (e.g. a background refetch) no longer re-fires focus() and steals it from the input being typed in. - Modal takes a `busy` prop; while a save/delete is in flight, Escape and backdrop clicks don't dismiss it (form/delete modals pass busy=pending), so an action can't be interrupted mid-flight and lose its error. - Form validates the *converted* centimeter values against the server's [1cm, 100m] bounds, so sub-cm / over-100m sizes fail client-side with a clear message instead of a generic server error. - displayFromCm rounds imperial to 0.1 ft so an 8 ft garden (244 cm) prefills as "8", not "8.01". Maintainability - Extracted ui/field.ts (useFieldId + fieldControlClass) shared by TextField/TextArea/Select. Added a `danger` Button variant, used by the delete modal; card edit/delete buttons gained focus-visible rings. - useUpdateGarden takes the id in its mutation variables (no dummy 0 during create). GardensPage shares a close handler; dropped a redundant zod annotation; 409 rebase reuses dimString; renamed `del` -> `deletion`. Verified in a browser: 8 ft round-trips to a prefilled "8"; a sub-cm value is rejected client-side with the modal staying open. tsc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JdQpdYYsTgtkJBxbcpAszi
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
import { forwardRef, useId, type InputHTMLAttributes } from 'react'
|
||||
import { forwardRef, type InputHTMLAttributes } from 'react'
|
||||
import { cn } from '@/lib/cn'
|
||||
import { fieldControlClass, useFieldId } from './field'
|
||||
|
||||
interface TextFieldProps extends InputHTMLAttributes<HTMLInputElement> {
|
||||
label: string
|
||||
hint?: string
|
||||
}
|
||||
|
||||
// A labelled text input. text-base (16px) is deliberate: smaller fonts make iOS
|
||||
// Safari zoom on focus. The field id falls back to the name, then to a generated
|
||||
// id, so the label/hint associations always hold.
|
||||
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(function TextField(
|
||||
{ label, hint, id, name, className, ...props },
|
||||
ref,
|
||||
) {
|
||||
const generatedId = useId()
|
||||
const inputId = id ?? name ?? generatedId
|
||||
const inputId = useFieldId(id, name)
|
||||
const hintId = hint ? `${inputId}-hint` : undefined
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
@@ -26,13 +23,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(function T
|
||||
id={inputId}
|
||||
name={name}
|
||||
aria-describedby={hintId}
|
||||
className={cn(
|
||||
'w-full rounded-md border border-border bg-surface px-3 py-2 text-base text-fg',
|
||||
'placeholder:text-muted/70 outline-none transition-colors',
|
||||
'focus:border-accent focus:ring-2 focus:ring-accent/30',
|
||||
'disabled:opacity-60',
|
||||
className,
|
||||
)}
|
||||
className={cn(fieldControlClass, className)}
|
||||
{...props}
|
||||
/>
|
||||
{hint && (
|
||||
|
||||
Reference in New Issue
Block a user