Text Input
No props are required to display <TextInput>, but it’s recommended to provide a label for accessibility.
import { TextInput } from "stylus-ui/TextInput";
export default () => <TextInput label="Username" />;Help text
Section titled “Help text”To display additional info beneath the input, pass in helpText.
Choose a unique username.
import { TextInput } from "stylus-ui/TextInput";
export default () => ( <TextInput label="Username" helpText="Choose a unique username." />);Sizing
Section titled “Sizing”When displaying an input in a space-constrained location, you can pass small, which decreases the padding and font size.
Choose a unique username.
import { TextInput } from "stylus-ui/TextInput";
export default () => ( <TextInput label="Username" helpText="Choose a unique username." small />);Errors
Section titled “Errors”When displaying an error message, pass error to highlight the input in red.
This username is already taken.
import { TextInput } from "stylus-ui/TextInput";
export default () => ( <TextInput label="Username" helpText="This username is already taken." error />);Placeholders
Section titled “Placeholders”Placeholder text may be used to provide an example of input to the user.
import { TextInput } from "stylus-ui/TextInput";
export default () => ( <TextInput label="Username" placeholder="e.g., johndoe123" />);Disabled
Section titled “Disabled”import { TextInput } from "stylus-ui/TextInput";
export default () => <TextInput label="Username" disabled />;You can add icons to the left or right side of the input using icon or iconEnd props respectively.
import { TextInput } from "stylus-ui/TextInput";import { faUser, faCheck } from "@fortawesome/pro-solid-svg-icons";
export default () => ( <TextInput label="Username" icon={faUser} iconEnd={faCheck} />);Full Width
Section titled “Full Width”To make the input take up the full width of its container, use the fullWidth prop.
import { TextInput } from "stylus-ui/TextInput";
export default () => <TextInput label="Username" fullWidth />;Clearable
Section titled “Clearable”To add a clear button that appears when the input has a value, use the onClear prop.
import { TextInput } from "stylus-ui/TextInput";import { useState } from "react";
export default () => { const [value, setValue] = useState(""); return ( <TextInput label="Username" value={value} onChange={(e) => setValue(e.target.value)} onClear={() => setValue("")} /> );};API Reference
Section titled “API Reference”TextInput
Section titled “TextInput”Inherits properties from HTMLInputElement.