TextInput

Capture string input from user
Import

Usage

Radius
xs
sm
md
lg
xl
Size
xs
sm
md
lg
xl
<TextInput
placeholder="Your name"
label="Full name"
required
/>

Controlled

import { useState } from 'react';
import { TextInput } from '@mantine/core';
function Demo() {
const [value, setValue] = useState('');
return <TextInput value={value} onChange={(event) => setValue(event.currentTarget.value)} />;
}

Invalid state and error

Invalid email
// Error as boolean – red border color
<TextInput error />
// Error as React node – red border color and message below input
<TextInput error="Invalid email" />

Disabled state

<TextInput disabled />

With icon

<TextInput icon={<At />} />

With right section

<TextInput label="Your email" placeholder="Your email" rightSection={<Loader size="xs" />} />

Get input ref

import { useRef } from 'react';
import { TextInput } from '@mantine/core';
function Demo() {
const ref = useRef(null);
return <TextInput ref={ref} />;
}

Accessibility

Provide aria-label in case you use component without label for screen reader support:

<TextInput /> // -> not ok, input is not labeled
<TextInput label="My input" /> // -> ok, input and label is connected
<TextInput aria-label="My input" /> // -> ok, label is not visible but will be announced by screen reader
Build fully functional accessible web applications faster than ever
Feedback
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback