Component size, gzipped: 24kb

Input

Loading
API

An input enables a person to type in text information.

When to use

  • When a person should provide information to the application.

Examples

Basic usage

States





Sizes



Enhancers

@

.00

$
.00

Search

@
.com

Before and After overrides

Search

Search

Alert

Check

MaskedInput

Clearable

Clear value

When clearable is true, pressing the Escape key or clicking the clear icon on the right will clear the input's current value. Other input components such as Textarea, PhoneInput, and PaymentCard also respect the clearable property.

Input for passwords

Input has some built-in logic when you set type to "password". A button is added to the right side of the input which, when activated, toggles the masking of the inputʼs current text. Allowing users to see the text they have entered is considered a usability best practice so we have built-in this behavior.

Please note, that by default the component will use the autocomplete="new-password" attribute. You can change that by providing the autoComplete property to the component, like autoComplete="current-password". You can read more about this decision here.

If you want to opt-out of this behavior, you can override the toggle with a null component:

<Input
type="password"
overrides={{
MaskToggleButton: () => null,
}}
/>

You can also use overrides to customize the icons used in the toggle:

<Input
type="password"
overrides={{
MaskToggleHideIcon: () => '🙈',
MaskToggleShowIcon: () => '🐵',
}}
/>

Note, if all you want to do is change the icons, you could update your theme instead.

Overrides usage

Focus and ref

Create/Delete Tags

hello

In the example above we use overrides to add "tag" functionality to our input. Type a phrase and press enter to create a new tag. Use backspace to remove tags.

Stateful (uncontrolled) usage

As with many of our components, there is also an uncontrolled version, StatefulInput, which manages its own state.

API

Input props

NameTypeDescription
adjoined
enum
Defines styles for inputs that are grouped with other controls.
aria-describedby
string
Sets aria-describedby attribute.
aria-label
string
Sets aria-label attribute.
aria-labelledby
string
Sets aria-labelledby attribute.
autoComplete
string
Determines if browser should provide value suggestions.
autoFocus
boolean
If true the input will be focused on the first mount.
clearable
boolean
If true, adds a clear value icon button to the end of the input container.
disabled
boolean
Renders component in disabled state.
endEnhancer
function
An input helper rendered after and attached to the input field.
error
boolean
Renders component in error state.
id
string
Id attribute value to be added to the input element and as a label's for attribute value.
inputMode
string
A hint as to the type of data that might be entered by the user while editing the element or its contents.
inputRef
ref
A ref to access an input element.
max
string
max value when used as input type=number
min
string
min value when used as input type=number
name
string
Name attribute.
onBlur
function
Called the onBlur event triggers.
onChange
function
Called when input value is changed.
onFocus
function
Called the onFocus event triggers.
onKeyDown
function
Called the onKeyDown event triggers.
onKeyPress
function
Called the onKeyPress event triggers.
onKeyUp
function
Called the onKeyUp event triggers.
overrides
custom
Lets you customize all aspects of the component.
pattern
string
A regex that is used to validate the value of the input on form submission.
placeholder
string
Input's placeholder.
positive
boolean
Renders component in positive state.
required
boolean
Renders component in required state.
size
enum
Renders component in provided size.
startEnhancer
function
An input helper rendered before and attached to the input field.
type
string
Input type attribute.
value
string
Input value attribute.

Input exports

You can import this module like so:

import {StatefulInput} from 'baseui/input'

It exports the following components or utility functions: