Skip to content

Commit 416bdb5

Browse files
authored
Merge pull request #153 from abhaykv04/bug/disable-button-until-input
Fix #150: Disable Go button until input is filled
2 parents d20fbba + fe2f7f1 commit 416bdb5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/components/UrlForm.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import { useState } from "react";
12
import { Form } from "remix";
23

34
export type UrlFormProps = {
45
className?: string;
56
};
67

78
export function UrlForm({ className }: UrlFormProps) {
9+
const [inputValue, setInputValue] = useState("");
10+
11+
const isButtonDisabled = !inputValue.length;
12+
813
return (
914
<Form
1015
method="post"
@@ -18,11 +23,16 @@ export function UrlForm({ className }: UrlFormProps) {
1823
id="jsonUrl"
1924
className="block flex-grow text-base text-slate-200 placeholder:text-slate-300 bg-slate-900/40 border border-slate-600 rounded-l-sm py-2 px-3 transition duration-300 focus:ring-indigo-500 focus:border-indigo-500"
2025
placeholder="Enter a JSON URL or paste in JSON here..."
26+
value={inputValue}
27+
onChange={(event) => setInputValue(event.target.value)}
2128
/>
2229
<button
2330
type="submit"
2431
value="Go"
25-
className="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-r-sm text-white bg-lime-500 transition hover:bg-lime-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-lime-500"
32+
className={`inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-r-sm text-white bg-lime-500 transition hover:bg-lime-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-lime-500 ${
33+
isButtonDisabled && "disabled:opacity-50 disabled:hover:bg-lime-500"
34+
}`}
35+
disabled={isButtonDisabled}
2636
>
2737
Go
2838
</button>

0 commit comments

Comments
 (0)