Input

Base component to create custom inputs
Import

Disclaimer

!important: In most cases, you should not use Input component in your application. Input component is a base for other inputs and was not designed to be used directly.

// Incorrect usage, input is not accessible
<InputWrapper label="Input label">
<Input />
</InputWrapper>
// Use TextInput instead of Input everywhere you want to use Input,
// it is accessible by default and includes InputWrapper
<TextInput label="Input label" description="Input description" />

Usage

Input component is used as base for all other inputs (Select, TextInput, Textarea and others). The single purpose of Input is to provide shared styles and features to other inputs. Use other components listed above to build forms (as they provide better accessibility) and Input component as base for your own custom inputs with Mantine theme.

Variant
Radius
xs
sm
md
lg
xl
Size
xs
sm
md
lg
xl
<Input
icon={<MailIcon />}
placeholder="Your email"
/>

Variants

Input has 3 variants, all of which are available on all Mantine inputs. Note that unstyled input variant may significantly impact usability, use it wisely.

<Input variant="default" placeholder="Default variant" />
<Input variant="filled" placeholder="Filled variant" />
<Input variant="unstyled" placeholder="Unstyled variant" />

Icon and right section

new
<Input
icon={<TwitterLogoIcon />}
placeholder="Your twitter"
rightSection={rightSection}
rightSectionWidth={70}
styles={{ rightSection: { pointerEvents: 'none' } }}
/>

Right section with Tooltip:

import { Input, Tooltip } from '@mantine/core';
import { InfoCircledIcon } from '@modulz/radix-icons';
function Demo() {
const rightSection = (
<Tooltip label="We do not send spam" position="top" placement="end">
<InfoCircledIcon />
</Tooltip>
);
return <Input placeholder="Your email" rightSection={rightSection} />;
}

Sizes

Component has 5 premade sizes: xs, sm, md, lg, xl, use size prop to control input height, padding and font-size:

<Input size="xl" placeholder="xl input size" />

Custom component

As Input component is intended to be a base for all other inputs, you can pass component prop which will define root element:

<Input component="button">Button input</Input>
<Input component="select" rightSection={<ChevronDownIcon />}>
<option value="1">1</option>
<option value="2">2</option>
</Input>

Headless variant

If you want to add your own styles to input it's better to start from scratch rather than overriding Mantine styles, use special headless variant which does not include any Mantine styles but still supports all other features: icon, right section, etc.:

$
<Input
variant="headless"
placeholder="Add your own styles with styles API"
icon={<TwitterLogoIcon />}
rightSection="$"
styles={{
input: {
width: '100%',
boxSizing: 'border-box',
}
}}
/>

Get input ref

You can get input ref by passing ref prop to Input component:

import { useRef } from 'react';
import { Input } from '@mantine/core';
function Demo() {
const ref = useRef(null);
return <Input ref={ref} />;
}
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