Skip to content

Text Input

Accepts text input from users.

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" />;

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." />
);

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 />
);

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
/>
);

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" />
);
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} />
);

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 />;

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("")}
/>
);
};

Inherits properties from HTMLInputElement.

Prop
Type
Default
disabled boolean false
error boolean false
fullWidth boolean false
helpText string
icon IconProp
iconEnd IconProp
iconEndProps Omit<FontAwesomeIconProps, 'icon'>
iconProps Omit<FontAwesomeIconProps, 'icon'>
label string
onClear () => void
small boolean false
theme "light""dark" "light"