Skip to main content
TextInput
@coinbase/cds-web@8.34.1
A control for entering text.
Import
import { TextInput } from '@coinbase/cds-web/controls/TextInput'
SourceView source codeStorybookView StorybookFigmaView Figma (internal only)
Related components
View as Markdown

Note TextField extends props from HTMLInputElement on web. On mobile, it extends TextInputProps from react-native.

Input Label

Default composition of Inputs.

Loading...

Accessible Text Inputs

TextInput comes with an accessibilityLabel prop. If no accessibilityLabel is passed, it will use the label as the accessibilityLabel. If you want an accessibilityLabel that differs from the Label, you can set this prop.

Here, since no accessibilityLabel is passed, the accessibilityLabel will be "Email".

<TextInput label="Email" />

Example of passing an accessibilityLabel. For web, this will set aria-label="Enter a Coinbase Email" under the hood

<TextInput accessibilityLabel="Enter a Coinbase Email" label="Email" />
Accessibility tip

Like any component system, much of the responsibility for building accessible UIs is in your hands as the consumer to properly implement the component composition. We'll do our best to provide sane fallbacks, but here are the biggest gotchas for TextInputs you can watch out for.


aria-* attr overrides

Any time you use variant='negative', we assume you're showing an error state. If for some reason this is not the case, you will want to use aria-invalid={false} to override the default configuration.


Message format

It's also advised you always format helperText with Error: ${errorMessage}. We'd do that for you, but i18n isn't baked into CDS. Take a look at the example below:

Loading...

Placeholder Text

Loading...

Borderless TextInput (web)

A borderless TextInput SHOULD NOT be used alone. It should be used with a TypeAhead component.

Loading...

Helper Text

Default Sentiment

Loading...

Color Surge Enabled

Loading...

Content Alignment

Loading...

Label Variants

TextInput supports two label variants: outside (default) and inside. Note that the compact prop, when set to true, will override label variant preference.

Warning

When using the inside label variant, you should always include a placeholder prop.

Loading...

Custom Label

If you need to render a custom label (e.g. a label with a tooltip), you can use the labelNode prop.

Loading...

StartContent & EndContent

Examples of Input Objects placed at the Start

Loading...

Read Only

TextInput supports a read-only state which is visually distinct from the disabled state. Read-only inputs have a secondary background color and can still be focused.

Loading...

Example of Input Objects placed at the End

Here are some examples and best practices when using end content in a TextField.

Loading...

Password input

Password Input - Use Icon Buttons at the end for actions like showing a password or clearing text from an input.

a11y tip: Always provide an accessibilityLabel to start/end nodes to clearly communicate state/actions

Loading...

If needed, you can add a Link + Icon Button like this example here. Use this sparingly and only at the End of an Input.

Loading...

Disabled

Loading...

TextArea Example (mobile)

On mobile, TextInput is versatile enough to support a "TextArea" as well. You just need to add multiline prop. Here is an example

const [text, onChangeText] = useState('');

<MockTextInput
onChangeText={onChangeText}
value={text}
label="Textarea"
helperText="Write about yourself"
variant="foregroundMuted"
multiline
value="
A really really really really
long piece
of text
displayed. A really really really really
long piece
of text
displayed.
A really really really really
long piece
of text
displayed
"
/>;

Example of a Form

We recommend that you use spacing 3 when building stacked forms.

Loading...

Example of a Sign Up Form

Loading...

Testing

Testing different parts of the input

You can also use the testIDMap to test different parts of the TextInput. If you use testID, it will add the testID to the root of the TextInput.

Loading...

Date Picker Example

You can construct a DatePicker using TextInput

Loading...

TextInput While Keyboard Is Open (mobile)

If you have the keyboard open, then closing the keyboard and interacting with the text input requires 2 taps, which isn't a great user experience.

To fix this issue, you can wrap the TextInput in a ScrollView, and set keyboardShouldPersistTaps="always".

function TextInputKeyboardExample() {
return (
<ScrollView style={{ height: '100%' }} keyboardShouldPersistTaps="always">
<TextInput label="Amount" type="number" compact placeholder="98329.23" suffix="USD" />
</ScrollView>
);
}

Is this page useful?

Coinbase Design is an open-source, adaptable system of guidelines, components, and tools that aid the best practices of user interface design for crypto products.