Skip to main content

Form Component

The <Form> component provides a structured layout for forms, seamlessly integrating with the useForm hook. It handles the form submission, displays submit and optional cancel buttons.

Basic Usage​

The component renders a <form> element. Wrap your form fields within the <Form> component.

import { Form, InputField } from "react-better-html";

function LoginForm() {
return (
<Form submitButtonText="Login" gap={10} onSubmit={(event) => {}}>
<InputField label="Username" name="username" />
<InputField.password label="Password" name="password" />
</Form>
);
}

Common Props​

  • form - the object returned by the useForm hook.
  • name / id - passed to the <form> element.
  • gap - the gap between the child elements within the form.
  • withDividers - if true, a <Divider.horizontal /> will be rendered between the child elements.
  • actionButtonsLocation - controls the horizontal alignment of the action buttons - left, center or right (default).
  • isDestructive - if true, the submit button will be rendered using the Button.destructive variant.
  • renderActionButtons - additional elements rendered next to the action buttons.
  • onSubmit - a onSubmit handler for the form. If provided, this will be used instead of the onSubmit function from the form prop.

Submit button​

  • submitButtonText - the text to display on the submit button. If provided, a submit button will be rendered.
  • submitButtonLoaderName - the name of the loader to display on the submit button.
  • submitButtonIsLoading - renders the submit button in loading state. When the form prop is passed, its isSubmitting state is used as well.
  • submitButtonIsDisabled - a boolean to manually disable the submit button. It is also disabled automatically when a required field from the form prop is empty.
  • submitButtonId - the id attribute for the submit button.

Cancel button​

  • onClickCancel - if provided, a cancel button will be rendered. The callback function will be called when the button is clicked.
  • cancelButtonText - the text of the cancel button (defaults to Cancel).
  • cancelButtonLoaderName / cancelButtonIsLoading - the loading state of the cancel button.
  • cancelButtonIsDisabled - disables the cancel button.
  • cancelButtonId - the id attribute for the cancel button.