Skip to main content
TextInput
@coinbase/cds-web@9.28.0
A control for entering text.
import { TextInput } from '@coinbase/cds-web/controls/TextInput'
Related components

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

Input Label​

Default composition of Inputs.

Loading...

Sizes​

size accepts s, m, and l. Defaults to l.

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​

For borderless TextInput usage, prefer adding a focus border with focusedBorderWidth. If you need a fully borderless input (including focus), use that pattern with a TypeAhead composition.

Loading...

Helper Text​

Default Sentiment​

Loading...

Color Surge Enabled​

Loading...

Content Alignment​

Loading...

Label Variants​

TextInput supports two label variants: outside (default) and inside. size and labelVariant are independent — use labelVariant="inside" with any size. At sizes s and m, an inside label sits inline in the start slot; at size l, it stacks vertically above the field.

Warning

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

Loading...

Custom Label​

You can pass a ReactNode to labelNode to render a custom label. If you want to include a tooltip, ensure the touch target is at least 24x24 for accessibility compliance.

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...

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...

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.