Input

Input component is a component that is used to get user input in a text field.

Import#

Usage#

Here's a basic usage of the Input component.

Editable Example

Changing the size of the Input#

There are three sizes of an Input : large (40px), default (32px) and small (24px).

Editable Example

Changing the appearance of the input#

The input component comes in 3 variants, outline, unstyled , flushed , and filled. Pass the variant prop and set it to either of these values.

Editable Example

Left and Right Addons#

Just like bootstrap, you can add addons to the left and right of the input component. Chakra UI exports InputGroup, InputLeftAddon, InputRightAddon to help with this use case.

+234
https://
.com
Editable Example

Add elements inside input#

In some scenarios, you might need to add an icon or button inside the input component. Chakra UI exports InputLeftElement, and InputRightElement to help with this use case.

$
Editable Example

Password Input Example#

Let's use these components to create a password input with a show/hide password functionality.

Editable Example

Controlled Input#

Value:

Editable Example

Changing the focus and error border colors#

You can change the border color that shows when the input receives focus (focusBorderColor) and when isInvalid is set to true (errorBorderColor). The value can be set to a color in the theme object, like teal.400 or a raw CSS value.

Editable Example

Props#

The Input component composes PseudoBox so you can pass all PseudoBox props, and React.InputHTMLAttributes.

NameTypeDefaultDescription
asReact.ElementTypeinputThe component to use in place of input.
aria-labelstringAccessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers.
aria-describedbystringAccessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers.
isDisabledbooleanfalseIf true, the input will be disabled. This sets aria-disabled=true and you can style this state by passing _disabled prop.
isInvalidbooleanfalseIf true, the input will indicate an error. This sets aria-invalid=true and you can style this state by passing _invalid prop.
isRequiredbooleanfalseIf true, the input element will be required.
isFullWidthbooleanfalseIf true, the input element will span the full width of it's parent.
isReadOnlybooleanfalseIf true, prevents the value of the input from being edited.
sizesm, md, lgmdThe visual size of the input element.
variantoutline, unstyled, flushed, filledoutlineThe variant of the input style to use.
focusBorderColorstringThe border color when the input is focused.
errorBorderColorstringThe border color when isInvalid is set to true.

Proudly made in 🇳🇬

Released under the MIT License.

Copyright © 2019 Segun Adebayo