Skip to main content

FormInput

FormInput is a wrapper around Input and FormLabel component. It is used to create a form input field with label and error message.

Import

import { FormInput } from "@sparrowengg/twigs-react";

Usage

Result
Loading...
<FormInput label="Email Address" />

Input error

Result
Loading...
<FormInput
  label="Email Address"
  error="Not a valid email address"
/>

Character count

<FormInput
value={"john@example.com"}
showCount={true}
maxLength={10}
/>

Using maxLength and showCount props, you can show the character count of the input field.

Result
Loading...
function CharacterCount() {
  const [value, setValue] = React.useState("");
  return (
    <FormInput
      label="Email Address"
      value={value}
      onChange={(e) => setValue(e.target.value)}
      showCount
      maxLength={10}
    />
  );
}

Props

PropertyDescriptionTypeDefault
variantstyle of inputdefault filleddefault
onChangefunction
sizeinput sizesm md lg xlmd
disabledbooleanfalse
leftIconAppend icon on the left side of inputJSX Element
rightIconAppend icon on the right side of inputJSX Element
cssCustom styles for inputobject
errorMessage for input errorstring
maxLengthMaximum allowed charactersnumber
showCountShow remaining allowed character lengthboolean
errorBorderShow error border when there is errorbooleanfalse
requiredIndicatorShow required indicator next to input labelboolean, JSX Element