Input
Use the Input component for labeled form fields with helper text, validation feedback, icons, and password visibility controls.
Import Input
Import Input from Tavix:
import { Input } from "tavix";Component API
<Input
label
type="text"
error
helperText
leadingIcon
trailingIcon
onTrailingIconClick
required={false}
...props
/>Props
label: Visible label associated with the input.type: Native input type. Defaults totext.error: Validation message. Takes precedence overhelperText.helperText: Supporting text shown below the input when there is noerror.leadingIcon: Tavix icon name rendered inside the left side of the input.trailingIcon: Tavix icon name rendered inside the right side of the input.onTrailingIconClick: Callback invoked when the trailing icon is clicked.required: Marks the input as required and displays an asterisk. Defaults tofalse....props: Additional native input props, such asid,name,value,placeholder,disabled,readOnly, and event handlers.
Behavior
- Generates an accessible id with React
useIdwhen noidis provided. - Associates the label with the input through
htmlForandid. - Adds
aria-requiredwhenrequiredistrue. - Adds
aria-invalidwhenerroris provided. - Links helper or error text through
aria-describedby. - Gives error text an
alertrole. - Displays an error icon when
erroris provided and the input is not a password input. - Password inputs render a visibility toggle that switches between
passwordandtext. - Password inputs give the toggle an accessible label and pressed state.
- When both
errorandhelperTextare provided, only the error message is displayed.
Examples
Basic fields
<Input label="Name" placeholder="Enter your name" />
<Input
label="Email"
type="email"
placeholder="Enter your email"
/>
<Input
label="Phone"
type="tel"
placeholder="Enter phone number"
/>Required and helper text
<Input
label="Username"
placeholder="Enter username"
required
/>
<Input
label="Username"
placeholder="Enter username"
helperText="Username must be at least 6 characters."
/>Icons
<Input
label="Search"
placeholder="Search..."
leadingIcon="search"
/>
<Input
label="Email"
type="email"
placeholder="Enter email"
trailingIcon="mail"
/>
<Input
label="Search"
placeholder="Search..."
leadingIcon="search"
trailingIcon="x"
/>Interactive trailing icon
<Input
label="Search"
placeholder="Search..."
trailingIcon="search"
onTrailingIconClick={() => {
console.log("Search clicked");
}}
/>Password field
<Input
label="Password"
type="password"
placeholder="Enter password"
/>
<Input
label="Password"
type="password"
placeholder="Enter password"
leadingIcon="lock"
/>The visibility button is rendered automatically for type="password".
Error, disabled, and read-only states
<Input
label="Email"
type="email"
placeholder="Enter email"
error="Please enter a valid email address."
/>
<Input
label="Disabled"
placeholder="Disabled input"
disabled
/>
<Input
label="Read Only"
value="Read only value"
readOnly
/>Supported types
Use any native input type supported by the browser. Common examples include:
textemailtelpasswordsearchurlnumber
Additional native attributes and event handlers can be passed through ...props.
Behavior
- Generates an accessible
idwith ReactuseIdwhen noidis provided. - Associates the label with the input through
htmlForandid. - Adds
aria-requiredwhenrequiredistrue. - Adds
aria-invalidwhenerroris provided. - Links helper or error text through
aria-describedby. - Gives error text an
alertrole. - Displays an error icon when
erroris provided and the input is not a password input. - Renders a visibility toggle for password inputs.
- Displays only the error message when both
errorandhelperTextare provided.
Notes
- The component renders a native
inputelement and preserves standard browser form behavior. - Icon names must be registered in the Tavix icon registry.
- Styling uses Tavix semantic colors, spacing, typography, and form tokens.