TextInput
Single-line text input field.
Examples
Section titled “Examples”Default
Section titled “Default”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />With Icon And Clear
Section titled “With Icon And Clear”Clear Name
function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<div style={{display: 'flex', flexDirection: 'column', gap: 16}}> <ControlledTextInput label="Small" placeholder="Small input" size="sm" /> <ControlledTextInput label="Medium" placeholder="Medium input" size="md" /> <ControlledTextInput label="Large" placeholder="Large input" size="lg" /></div>Disabled
Section titled “Disabled”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />Loading
Section titled “Loading”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />With Description
Section titled “With Description”Enter your legal first and last name
function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />Label Hidden
Section titled “Label Hidden”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />Required
Section titled “Required”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />Optional
Section titled “Optional”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />With Label Tooltip
Section titled “With Label Tooltip”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />With End Content
Section titled “With End Content”USD
function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />Status Variants
Section titled “Status Variants”This field is required
This name is already taken
Username is available
function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<div style={{display: 'flex', flexDirection: 'column', gap: 16}}> <ControlledTextInput label="Error" status={{message: 'This field is required', type: 'error'}} value="" /> <ControlledTextInput label="Warning" status={{message: 'This name is already taken', type: 'warning'}} value="admin" /> <ControlledTextInput label="Success" status={{message: 'Username is available', type: 'success'}} value="ada_lovelace" /></div>Email Type
Section titled “Email Type”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />Phone Type
Section titled “Phone Type”For international numbers, include the country code.
function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />Read Only
Section titled “Read Only”function ControlledTextInput({ isOptional, isRequired, value: initialValue = '', ...args}: ControlledTextInputProps): React.JSX.Element { const [value, setValue] = useState(initialValue);
return ( <TextInput {...args} {...getNecessity(isOptional, isRequired)} onChange={setValue} value={value} /> );}
<ControlledTextInput {...args} />TextInput
Section titled “TextInput”Single-line text input field.
When isOptional: false, isRequired: false
| Prop | Type | Default | Description |
|---|---|---|---|
aria-activedescendant | AriaAttributes['aria-activedescendant'] | — | Identifies the currently active element in a composite widget controlled by the input. |
aria-autocomplete | AriaAttributes['aria-autocomplete'] | — | Indicates whether typing displays completion suggestions. |
aria-controls | AriaAttributes['aria-controls'] | — | Identifies the element controlled by the input. |
autoComplete | string | — | HTML autocomplete hint for the browser. |
className | string | — | Additional CSS class names applied to the field root, or to the input wrapper when the input is inside an InputGroup. |
data-testid | string | — | Test ID applied to the input element. |
description | ReactNode | — | Supporting text rendered below the label. |
endContent | ReactNode | — | Content rendered after the input, before the status icon. |
hasAutoFocus | boolean | false | Whether to focus the input on mount. |
hasClear | boolean | false | Whether to show a clear button when the input has a value. |
htmlName | string | — | HTML name attribute. |
isDisabled | boolean | false | Whether the input is disabled. |
isLabelHidden | boolean | false | Whether to visually hide the label. |
isLoading | boolean | false | Whether the input is loading. |
isReadOnly | boolean | false | Whether the value is displayed without allowing focus or interaction. |
label* | string | — | Field label. |
labelIcon | IconComponent | — | Icon shown before the label. |
labelTooltip | ReactNode | — | Tooltip shown beside the label. |
onBlur | (event: FocusEvent<HTMLInputElement>) => void | — | Called when the input loses focus. |
onChange* | ( value: string, event: ChangeEvent<HTMLInputElement> | null, ) => void | — | Called with the next string value. |
onEnter | () => void | — | Called when Enter is pressed. |
onFocus | (event: FocusEvent<HTMLInputElement>) => void | — | Called when the input gains focus. |
onKeyDown | (event: KeyboardEvent<HTMLInputElement>) => void | — | Keyboard event handler for the input. |
placeholder | string | — | Placeholder text. |
ref | Ref<HTMLInputElement> | — | Ref forwarded to the input element. |
role | AriaRole | — | ARIA role applied to the input element. |
size | "sm" | "md" | "lg" | — | Visual size. |
startIcon | IconComponent | — | Icon shown before the input. |
status | InputStatus | — | Status displayed on the field. |
style | CSSProperties | — | Inline styles applied to the field root, or to the input wrapper when the input is inside an InputGroup. |
type | "text" | "tel" | "email" | "password" | — | HTML input type. |
value* | string | — | Controlled input value. |
isOptional | false | — | |
isRequired | false | — |
When isOptional: true, isRequired: false
| Prop | Type | Default | Description |
|---|---|---|---|
aria-activedescendant | AriaAttributes['aria-activedescendant'] | — | Identifies the currently active element in a composite widget controlled by the input. |
aria-autocomplete | AriaAttributes['aria-autocomplete'] | — | Indicates whether typing displays completion suggestions. |
aria-controls | AriaAttributes['aria-controls'] | — | Identifies the element controlled by the input. |
autoComplete | string | — | HTML autocomplete hint for the browser. |
className | string | — | Additional CSS class names applied to the field root, or to the input wrapper when the input is inside an InputGroup. |
data-testid | string | — | Test ID applied to the input element. |
description | ReactNode | — | Supporting text rendered below the label. |
endContent | ReactNode | — | Content rendered after the input, before the status icon. |
hasAutoFocus | boolean | false | Whether to focus the input on mount. |
hasClear | boolean | false | Whether to show a clear button when the input has a value. |
htmlName | string | — | HTML name attribute. |
isDisabled | boolean | false | Whether the input is disabled. |
isLabelHidden | boolean | false | Whether to visually hide the label. |
isLoading | boolean | false | Whether the input is loading. |
isReadOnly | boolean | false | Whether the value is displayed without allowing focus or interaction. |
label* | string | — | Field label. |
labelIcon | IconComponent | — | Icon shown before the label. |
labelTooltip | ReactNode | — | Tooltip shown beside the label. |
onBlur | (event: FocusEvent<HTMLInputElement>) => void | — | Called when the input loses focus. |
onChange* | ( value: string, event: ChangeEvent<HTMLInputElement> | null, ) => void | — | Called with the next string value. |
onEnter | () => void | — | Called when Enter is pressed. |
onFocus | (event: FocusEvent<HTMLInputElement>) => void | — | Called when the input gains focus. |
onKeyDown | (event: KeyboardEvent<HTMLInputElement>) => void | — | Keyboard event handler for the input. |
placeholder | string | — | Placeholder text. |
ref | Ref<HTMLInputElement> | — | Ref forwarded to the input element. |
role | AriaRole | — | ARIA role applied to the input element. |
size | "sm" | "md" | "lg" | — | Visual size. |
startIcon | IconComponent | — | Icon shown before the input. |
status | InputStatus | — | Status displayed on the field. |
style | CSSProperties | — | Inline styles applied to the field root, or to the input wrapper when the input is inside an InputGroup. |
type | "text" | "tel" | "email" | "password" | — | HTML input type. |
value* | string | — | Controlled input value. |
isOptional* | true | — | |
isRequired | false | — |
When isOptional: false, isRequired: true
| Prop | Type | Default | Description |
|---|---|---|---|
aria-activedescendant | AriaAttributes['aria-activedescendant'] | — | Identifies the currently active element in a composite widget controlled by the input. |
aria-autocomplete | AriaAttributes['aria-autocomplete'] | — | Indicates whether typing displays completion suggestions. |
aria-controls | AriaAttributes['aria-controls'] | — | Identifies the element controlled by the input. |
autoComplete | string | — | HTML autocomplete hint for the browser. |
className | string | — | Additional CSS class names applied to the field root, or to the input wrapper when the input is inside an InputGroup. |
data-testid | string | — | Test ID applied to the input element. |
description | ReactNode | — | Supporting text rendered below the label. |
endContent | ReactNode | — | Content rendered after the input, before the status icon. |
hasAutoFocus | boolean | false | Whether to focus the input on mount. |
hasClear | boolean | false | Whether to show a clear button when the input has a value. |
htmlName | string | — | HTML name attribute. |
isDisabled | boolean | false | Whether the input is disabled. |
isLabelHidden | boolean | false | Whether to visually hide the label. |
isLoading | boolean | false | Whether the input is loading. |
isReadOnly | boolean | false | Whether the value is displayed without allowing focus or interaction. |
label* | string | — | Field label. |
labelIcon | IconComponent | — | Icon shown before the label. |
labelTooltip | ReactNode | — | Tooltip shown beside the label. |
onBlur | (event: FocusEvent<HTMLInputElement>) => void | — | Called when the input loses focus. |
onChange* | ( value: string, event: ChangeEvent<HTMLInputElement> | null, ) => void | — | Called with the next string value. |
onEnter | () => void | — | Called when Enter is pressed. |
onFocus | (event: FocusEvent<HTMLInputElement>) => void | — | Called when the input gains focus. |
onKeyDown | (event: KeyboardEvent<HTMLInputElement>) => void | — | Keyboard event handler for the input. |
placeholder | string | — | Placeholder text. |
ref | Ref<HTMLInputElement> | — | Ref forwarded to the input element. |
role | AriaRole | — | ARIA role applied to the input element. |
size | "sm" | "md" | "lg" | — | Visual size. |
startIcon | IconComponent | — | Icon shown before the input. |
status | InputStatus | — | Status displayed on the field. |
style | CSSProperties | — | Inline styles applied to the field root, or to the input wrapper when the input is inside an InputGroup. |
type | "text" | "tel" | "email" | "password" | — | HTML input type. |
value* | string | — | Controlled input value. |
isOptional | false | — | |
isRequired* | true | — |