-
Notifications
You must be signed in to change notification settings - Fork 967
/
Copy pathremix-form.tsx
35 lines (32 loc) · 1.11 KB
/
remix-form.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { type ElementRef, type ComponentProps, forwardRef } from "react";
import { Form, type FormProps } from "@remix-run/react";
export const defaultTag = "form";
export const RemixForm = forwardRef<
ElementRef<typeof defaultTag>,
Omit<ComponentProps<typeof defaultTag>, "action"> &
Pick<FormProps, "encType"> & {
// Remix's default behavior includes method values in both uppercase and lowercase,
// resulting in our UI displaying a list that encompasses both variants.
method?: Lowercase<NonNullable<FormProps["method"]>>;
action?: string;
}
>(({ action, ...props }, ref) => {
// remix casts action to relative url
if (
action === undefined ||
action === "" ||
(typeof action === "string" && action?.startsWith("/"))
) {
return (
<Form
action={action}
{...props}
ref={ref}
// Preserve scroll position for navigation on the same path, as it's used for filtering and sorting
preventScrollReset={action === undefined || action === ""}
/>
);
}
return <form {...props} ref={ref} />;
});
RemixForm.displayName = "Form";