Skip to main content

Input

A basic widget for getting the user input is a text field. Keyboard and mouse can be used for providing or changing data.

When To Use

  • A user input in a form field is needed
  • A search input is required

Import

import { TxInput } from "tx-design-ui";

Examples

Basic Usage

Basic usage example.

import { TxInput } from "tx-design-ui";
import { useState } from "react";

function App() {
const [value, setValue] = useState("");

return <TxInput placeholder="Enter text" value={value} onChange={e => setValue(e.target.value)} />;
}

Size

There are three sizes of an Input box: large, medium (default), and small.

<TxInput size="large" placeholder="Large input" />
<TxInput size="medium" placeholder="Medium input" />
<TxInput size="small" placeholder="Small input" />

Prefix and Suffix

You can use prefix and suffix props to add icons or other elements to the input.

import { SvgIcon } from "tx-design-ui";

<TxInput prefix={<SvgIcon.IconUserSquare01 />} placeholder="Username" />
<TxInput suffix={<SvgIcon.IconKeySquare01 />} placeholder="With suffix" />
<TxInput
prefix={<SvgIcon.IconUserSquare01 />}
suffix={<SvgIcon.IconKeySquare01 />}
placeholder="With both"
/>

Status

Add status to Input with status, which could be success, warning, error, or info.

<TxInput status="success" placeholder="Success" />
<TxInput status="warning" placeholder="Warning" />
<TxInput status="error" placeholder="Error" />
<TxInput status="info" placeholder="Info" />

Fill Variant

Use the fill prop to create a filled input style.

<TxInput placeholder="Default outline" />
<TxInput fill placeholder="Filled input" />

// Combine with status
<TxInput fill status="success" placeholder="Success filled" />
<TxInput fill status="error" placeholder="Error filled" />

Password Input

Use password prop to create a password input with toggle visibility.

<TxInput password placeholder="Password" />
<TxInput password passwordToggle={false} placeholder="Password without toggle" />

Allow Clear

Make the Input clearable with allowClear prop.

<TxInput allowClear placeholder="Clearable input" />
<TxInput allowClear fill placeholder="Clearable filled input" />

Disabled

Disabled Input.

<TxInput disabled placeholder="Disabled input" />
<TxInput disabled fill placeholder="Disabled filled input" />

Custom Placeholder Color

You can customize the placeholder color using the placeholderColor prop.

<TxInput placeholder="Custom placeholder" placeholderColor="#ff6b6b" />

Combined Features

Combine multiple features for advanced usage.

import { SvgIcon } from "tx-design-ui";

<TxInput
prefix={<SvgIcon.IconUserSquare01 />}
status="success"
size="large"
allowClear
placeholder="Advanced input"
/>

<TxInput
password
prefix={<SvgIcon.IconKeySquare01 />}
status="error"
allowClear
placeholder="Password with features"
/>

API

PropertyTypeDefaultDescription
valuestring | number-The input content value
onChangefunction(e)-Callback when user input
placeholderstring""The placeholder text
type'text' | 'password' | 'email' | 'number' | 'tel' | 'url''text'The type of input
size'small' | 'medium' | 'large''medium'The size of the input box
disabledbooleanfalseWhether the input is disabled
prefixReactNode-The prefix icon or element for the Input
suffixReactNode-The suffix icon or element for the Input
status'success' | 'warning' | 'error' | 'info'-Set validation status
fillbooleanfalseWhether to use filled style
passwordbooleanfalseWhether to show password input
passwordTogglebooleantrueWhether to show toggle password visibility button
allowClearbooleanfalseWhether to show clear button
onClearfunction()-Callback when clear button is clicked
placeholderColorstring'#8c9bab'Custom placeholder text color
backgroundstring-Custom background color
colorstring-Custom text color
maxLengthnumber-Maximum length of input

Notes

  • When using password prop, the input type will be automatically set to password
  • The clear button only appears when there is a value in the input
  • Status colors automatically apply to prefix/suffix icons
  • The fill variant provides a different visual style with a filled background
  • Password toggle icon changes based on password visibility state