TextField
Use TextField to create a text input field.
To add the TextField
component to your app:
import {TextField} from '@stripe/ui-extension-sdk/ui';
<TextField label="Business name" placeholder="Acme Inc…" onChange={(e) => { console.log(e.target.value); }} />
TextField props
Property | Type |
---|---|
| Optional
Specifies one of the possible autocomplete behaviors. |
| Optional
If |
| Optional
Related types: CSS. |
| Optional
Specifies the initial value that a user can change. |
| Optional
Descriptive text that will be rendered adjacent to the control’s label. |
| Optional
Sets whether or not the element should be disabled. Prevents selection. |
| Optional
Error text that will be rendered below the control. |
| Optional
Specifies the |
| Optional
Visually hides the specified elements. The hidden elements will still be present and visible to screen readers. |
| Optional
Sets whether or not the element is in an invalid state. This is a display-only prop, and will not prevent form submission. |
| Optional
Text that describes the control. Will be both visible and clickable. |
| Optional
Specifies the maximum length of text. |
| Optional
Specifies the minimum length of text. |
| Optional
Specifies the name for this input that’s submitted with the form. |
| Optional
Required for controlled inputs. Fires immediately when the input’s value is changed by the user (for example, it fires on every keystroke). Behaves like the browser input event. |
| Optional
Fires when a key is pressed. |
| Optional
Fires when a key is released. |
| Optional
Displayed in a dimmed color when the input value is empty. |
| Optional
If |
| Optional
If |
| Optional
The size of the component. |
| Optional
If explicitly set to |
| Optional
Overrides the default Tab button behavior. Avoid using values other than |
| Optional
Choose between the text-alike types on an input. |
| Optional
Controls the input’s text. When you pass this prop, you must also pass an |
| OptionalDeprecated
|
CSS
Property | Type |
---|---|
| Optional
The width of the component. See Sizing for details. |
Invalid
You can set invalid
on a TextField element to render the component with a red outline as a visual indicator that the value provided isn’t acceptable. Omitting this property defaults to false
.
<TextField label="Current year" defaultValue="1892" invalid />
Type
You can set the type
property for the TextField to render it differently depending on the type of text value expected. This is similar to the type attribute on an <input />
, but is restricted to types that allow text. Omitting this property defaults to text
.
<TextField label="Text" type="text" /> <TextField label="Password" type="password" /> <TextField label="Search" type="search" /> <TextField label="Number" type="number" />
Size
Changing the size
allows you to choose variants with slightly more or slightly less room than the default. In general you don’t want to mix and match different sizes within the same form. The default is medium
.
<TextField label="Small" size="small" /> <TextField label="Medium" size="medium" /> <TextField label="Large" size="large" />
Disabled and read only
You can mark a field as disabled
, which prevents any interaction and changes the styling. Disabled means that no data from that form element is submitted when the form is submitted.
You can also make a field as readOnly
. Read-only means any data from within the element will be submitted, but the user can’t change it.
<TextField label="Disabled" defaultValue="Field is disabled" disabled /> <TextField label="Readonly" defaultValue="Field is readonly" readOnly />
State management
Use the TextField
component as an uncontrolled input:
<TextField onChange={(e) => { console.log(e); }} label="First name" />
Width
Set the width of a TextField
component using the available values with the css
prop:
<TextField label="Search" type="search" css={{width: 'fill'}} />