real forms across the plugin, so enter submits instead of doing nothing
connection settings, add/move/rename/options dialogs and daemon settings all put their fields in a div, so the button was the only way to submit and enter silently did nothing — a keyboard trap wearing a layout. wrapped each in a <form onSubmit>, made every non-submit button in those forms type="button" (test port, update blocklist, discard, cancel, remove-file, known-dir shortcuts), and dropped RenameDialog's manual onKeyDown enter check now that the form handles it natively. the toolbar's filter box is left alone — it has no submit action. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+15
-7
@@ -1,4 +1,4 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import type { FormEvent, ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { Loader2, Plug, ShieldCheck } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -45,7 +45,8 @@ export const SettingsView = () => {
|
||||
|
||||
const dirty = Object.keys(draft).length > 0;
|
||||
|
||||
const apply = async () => {
|
||||
const apply = async (ev?: FormEvent) => {
|
||||
ev?.preventDefault();
|
||||
await save.mutateAsync(draft);
|
||||
setDraft({});
|
||||
};
|
||||
@@ -80,7 +81,7 @@ export const SettingsView = () => {
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex h-full min-h-0 flex-col">
|
||||
<form onSubmit={apply} className="flex h-full min-h-0 flex-col">
|
||||
<Tabs defaultValue="download" className="flex min-h-0 flex-1 flex-col">
|
||||
<TabsList className="mx-4 mt-3 w-fit shrink-0">
|
||||
<TabsTrigger value="download">Downloads</TabsTrigger>
|
||||
@@ -167,7 +168,13 @@ export const SettingsView = () => {
|
||||
{bool('peer-port-random-on-start', 'Pick a random port on each start')}
|
||||
{bool('port-forwarding-enabled', 'Ask the router to forward it (UPnP / NAT-PMP)')}
|
||||
<div>
|
||||
<Button size="sm" variant="outline" onClick={() => portTest.mutate()} disabled={portTest.isPending}>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => portTest.mutate()}
|
||||
disabled={portTest.isPending}
|
||||
>
|
||||
{portTest.isPending ? (
|
||||
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
@@ -207,6 +214,7 @@ export const SettingsView = () => {
|
||||
{text('blocklist-url', 'Blocklist URL')}
|
||||
<div className="flex items-center gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => updateBlocklist.mutate()}
|
||||
@@ -284,16 +292,16 @@ export const SettingsView = () => {
|
||||
<span className="flex-1 text-xs text-muted-foreground">
|
||||
{Object.keys(draft).length} unsaved change{Object.keys(draft).length === 1 ? '' : 's'}
|
||||
</span>
|
||||
<Button size="sm" variant="ghost" onClick={() => setDraft({})}>
|
||||
<Button type="button" size="sm" variant="ghost" onClick={() => setDraft({})}>
|
||||
Discard
|
||||
</Button>
|
||||
<Button size="sm" onClick={apply} disabled={save.isPending}>
|
||||
<Button type="submit" size="sm" disabled={save.isPending}>
|
||||
{save.isPending && <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user