Textarea

Multi-line text input with optional autosize functionality.

Import

import { Textarea } from '@tidbcloud/uikit'

Basic Usage

import { Textarea } from '@tidbcloud/uikit'
 
function Demo() {
  return <Textarea label="Your comment" placeholder="Enter your comment" />
}

Controlled

import { useState } from 'react'
import { Textarea } from '@tidbcloud/uikit'
 
function Demo() {
  const [value, setValue] = useState('')
  return (
    <Textarea value={value} onChange={(event) => setValue(event.currentTarget.value)} label="Controlled textarea" />
  )
}

Autosize

Textarea height grows with content:

import { Textarea } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <>
      <Textarea label="Autosize with no limit" placeholder="Start typing..." autosize minRows={2} />
 
      <Textarea label="Autosize with max rows" placeholder="Start typing..." autosize minRows={2} maxRows={4} />
    </>
  )
}

Enable Resize

<Textarea label="Resizable" placeholder="Your comment" resize="vertical" />

Error State

<Textarea label="With error" placeholder="Enter text" error="This field is required" />

Key Props

PropTypeDescription
valuestringControlled value
defaultValuestringDefault value (uncontrolled)
onChange(event) => voidCalled when value changes
labelReactNodeInput label
descriptionReactNodeInput description
placeholderstringPlaceholder text
errorReactNodeError message
disabledbooleanDisable input
autosizebooleanEnable autosize
minRowsnumberMinimum rows (with autosize)
maxRowsnumberMaximum rows (with autosize)
resize'none' | 'vertical' | 'horizontal' | 'both'CSS resize property
sizeMantineSizeInput size
radiusMantineRadiusBorder radius