Textarea

Renders textarea with optional autosize variant
Import

Usage

Radius
xs
sm
md
lg
xl
Size
xs
sm
md
lg
xl
import { Textarea } from '@mantine/core';
function Demo() {
return (
<Textarea
placeholder="Your comment"
label="Your comment"
withAsterisk
/>
);
}

Autosize

Autosize textarea uses react-textarea-autosize package. Textarea height will grow until maxRows are reached or indefinitely if maxRows not set.

import { Textarea } from '@mantine/core';
function Demo() {
return (
<>
<Textarea
placeholder="Autosize with no rows limit"
label="Autosize with no rows limit"
autosize
minRows={2}
/>
<Textarea
label="Autosize with 4 rows max"
placeholder="Autosize with 4 rows max"
autosize
minRows={2}
maxRows={4}
/>
</>
);
}

Controlled

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

Invalid state and error

// Error as boolean – red border color
<Textarea error />
// Error as React node – red border color and message below input
<Textarea error="Comment should not include bad words" />

Get input ref

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

Accessibility

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

<Textarea /> // -> not ok, textarea is not labeled
<Textarea label="My textarea" /> // -> ok, textarea and label is connected
<Textarea aria-label="My textarea" /> // -> ok, label is not visible but will be announced by screen reader
Download more icon variants from https://tabler-icons.io/i/search

Textarea component props

NameTypeDescription
autosize
boolean
If true textarea will grow with content until maxRows are reached
description
ReactNode
Input description, displayed after label
descriptionProps
Record<string, any>
Props spread to description element
disabled
boolean
Disabled input state
error
ReactNode
Displays error message after input
errorProps
Record<string, any>
Props spread to error element
icon
ReactNode
Adds icon on the left side of input
iconWidth
number
Width of icon section in px
id
string
Id is used to bind input and label, if not passed unique id will be generated for each input
inputContainer
(children: ReactNode) => ReactNode
Input container component, defaults to React.Fragment
inputWrapperOrder
("input" | "label" | "description" | "error")[]
Controls order of the Input.Wrapper elements
label
ReactNode
Input label, displayed before input
labelProps
Record<string, any>
Props spread to label element
maxRows
number
Defines maxRows in autosize variant, not applicable to regular variant
minRows
number
Defined minRows in autosize variant and rows in regular variant
radius
number | "xs" | "sm" | "md" | "lg" | "xl"
Input border-radius from theme or number to set border-radius in px
required
boolean
Adds required attribute to the input and red asterisk on the right side of label
rightSection
ReactNode
Right section of input, similar to icon but on the right
rightSectionProps
Record<string, any>
Props spread to rightSection div element
rightSectionWidth
number
Width of right section, is used to calculate input padding-right
size
"xs" | "sm" | "md" | "lg" | "xl"
Input size
variant
"unstyled" | "default" | "filled"
Defines input appearance, defaults to default in light color scheme and filled in dark
withAsterisk
boolean
Determines whether required asterisk should be rendered, overrides required prop, does not add required attribute to the input
wrapperProps
Record<string, any>
Props passed to root element

Textarea component Styles API

NameStatic selectorDescription
wrapper.mantine-Textarea-wrapperRoot Input element
invalid.mantine-Textarea-invalidInvalid input modifier
disabled.mantine-Textarea-disabledInvalid disabled modifier
icon.mantine-Textarea-iconInput icon wrapper on the left side of the input, controlled by icon prop
withIcon.mantine-Textarea-withIconInput element styles when used with icon, controlled by icon prop
input.mantine-Textarea-inputMain input element
rightSection.mantine-Textarea-rightSectionInput right section, controlled by rightSection prop
root.mantine-Textarea-rootRoot element
label.mantine-Textarea-labelLabel element styles, defined by label prop
error.mantine-Textarea-errorError element styles, defined by error prop
description.mantine-Textarea-descriptionDescription element styles, defined by description prop
required.mantine-Textarea-requiredRequired asterisk element styles, defined by required prop