# All files / form Form.tsx

84.31% Statements 43/51
100% Branches 1/1
33.33% Functions 1/3
84.31% Lines 43/51

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    521x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x

    30x
    30x
    30x
    30x
    30x
    30x
    1x
     "use client";
    import { forwardRef, type FormHTMLAttributes } from "react";

    const noop = (): void => {
      // do nothing
    };

    export interface FormProps extends FormHTMLAttributes<HTMLFormElement> {
      /**
       * Boolean if the form should no longer prevent default submit behavior. If
       * you enable this prop you should honestly just use a `<form>` element
       * instead
       *
       * @defaultValue `false`
       */
      disablePreventDefault?: boolean;
    }

    /**
     * **Client Component**
     *
     * This is probably one of the least useful components available as it doesn't
     * do much styling or logic. All this form component will do is add basic flex
     * behavior and prevent the default form submit behavior.
     */
    export const Form = forwardRef<HTMLFormElement, FormProps>(
      function Form(props, ref) {
        const {
          children,
          onSubmit = noop,
          disablePreventDefault = false,
          ...remaining
        } = props;

        return (
          <form
            {...remaining}
            onSubmit={(event) => {
              if (!disablePreventDefault) {
                event.preventDefault();
              }

              onSubmit(event);
            }}
            ref={ref}
          >
            {children}
          </form>
        );
      }
    );