diff --git a/.jules/palette.md b/.jules/palette.md index e69de29..a4aec54 100644 --- a/.jules/palette.md +++ b/.jules/palette.md @@ -0,0 +1,3 @@ +## 2024-05-18 - Wrap Inputs in Forms for Native Submit +**Learning:** Wrapping `` and a corresponding `` in a `` provides highly reliable, accessible native Enter-to-submit behavior and eliminates the need for manual, brittle `onKeyDown` listeners (which often fail to account for assistive tech or autofill). +**Action:** When creating or modifying inputs designed to execute a single action, always prefer a native `` element over a standalone input with an `onKeyDown` Enter listener. Remember to set the button to `type="submit"` and use `e.preventDefault()` in the `onSubmit` handler to prevent page reloads. diff --git a/src/features/library/components/CoverPickerModal.tsx b/src/features/library/components/CoverPickerModal.tsx index 9e73ee7..6761942 100644 --- a/src/features/library/components/CoverPickerModal.tsx +++ b/src/features/library/components/CoverPickerModal.tsx @@ -516,14 +516,19 @@ export function CoverPickerModal({ {/* URL Input */} {showUrlInput ? ( - + { + e.preventDefault() + void handleCustomUrl() + }} + className="flex items-center gap-2" + > handleCustomUrlChange(e.target.value)} onPaste={handleCustomUrlPaste} - onKeyDown={(e) => { if (e.key === 'Enter') void handleCustomUrl() }} placeholder="https://example.com/cover.jpg" aria-invalid={customUrlError ? true : undefined} aria-describedby={customUrlError || isCheckingCustomUrl ? 'cover-url-status' : undefined} @@ -540,15 +545,14 @@ export function CoverPickerModal({ title={!customUrl.trim() ? 'Enter a valid image URL' : isCheckingCustomUrl ? 'Checking image link...' : undefined} > { void handleCustomUrl() }} + type="submit" disabled={!customUrl.trim() || isCheckingCustomUrl} className="rounded-lg bg-accent-600 px-3 py-1.5 text-xs font-medium text-white transition hover:bg-accent-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-500 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-offset-slate-900" > {isCheckingCustomUrl ? 'Checking' : 'Add'} - + {customUrlError ? ( {customUrlError}
{customUrlError}