The Input component is a component that is used to get user input in a text field.
Here's a basic usage example of the Input component:
There are three sizes of an Input:
sm
(24px
)md
(32px
)lg
(40px
)The input component comes in 4 variants: outline
, unstyled
, flushed
, and
filled
. Pass the variant
prop and set it to one of these values.
Like bootstrap, you can add addons to the left and right of the input component.
Chakra UI exports InputGroup
, InputLeftAddon
, and InputRightAddon
to help
with this use case.
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.
If the left or right is an icon or text, you can Users can pass
pointerEvents="none"
to InputLeftElement
or InputRightElement
to ensure
that clicking on them focused the input.
Let's use these components to create a password input with a show/hide password functionality:
Value:
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.
The Input component composes Box so you can pass all Box
props, and React.InputHTMLAttributes
.
Name | Type | Default | Description |
---|---|---|---|
as | React.ElementType | input | The component to use in place of input . |
aria-label | string | Accessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers. | |
aria-describedby | string | Accessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers. | |
isDisabled | boolean | false | If true , the input will be disabled. This sets aria-disabled=true and you can style this state by passing _disabled prop. |
isInvalid | boolean | false | If true , the input will indicate an error. This sets aria-invalid=true and you can style this state by passing _invalid prop. |
isRequired | boolean | false | If true , the input element will be required. |
isFullWidth | boolean | false | If true , the input element will span the full width of it's parent. |
isReadOnly | boolean | false | If true , prevents the value of the input from being edited. |
size | sm , md , lg | md | The visual size of the input element. |
variant | outline , unstyled , flushed , filled | outline | The variant of the input style to use. |
focusBorderColor | string | The border color when the input is focused. | |
errorBorderColor | string | The border color when isInvalid is set to true . |