Textarea

分类:

other

日期:

2022-2-06

标签:

chakra

The Textarea component allows you to easily create multi-line text inputs.

Import#

import { Textarea } from '@chakra-ui/react';

Usage#

<Textarea placeholder="Here is a sample placeholder" />

Controlled Textarea#

function Example() {
let [value, setValue] = React.useState('');
let handleInputChange = e => {
let inputValue = e.target.value;
setValue(inputValue);
};
return (
<>
<Text mb="8px">Value: {value}</Text>
<Textarea
value={value}
onChange={handleInputChange}
placeholder="Here is a sample placeholder"
size="sm"
/>
</>
);
}

Resize behavior#

You can add resize prop to change the Textarea resize behavior.

function ResizeExample() {
const [resize, setResize] = React.useState('horizontal');
return (
<>
<RadioGroup defaultValue={resize} onChange={setResize} mb={6}>
<Stack direction="row" spacing={5}>
<Radio value="horizontal">Horizontal</Radio>
<Radio value="vertical">Vertical</Radio>
<Radio value="none">None</Radio>
</Stack>
</RadioGroup>
<Textarea
placeholder="Here is a sample placeholder"
size="sm"
resize={resize}
/>
</>
);
}

Disabled Textarea#

<Textarea isDisabled placeholder="Here is a sample placeholder" />

Invalid Textarea#

<Textarea isInvalid placeholder="Here is a sample placeholder" />

Props#

The Textarea composes the Input component.

colorScheme

Color Schemes Textarea

(string & {})

errorBorderColor

The border color when the textarea is invalid. Use color keys in `theme.colors` @example errorBorderColor = "red.500"

string

focusBorderColor

The border color when the textarea is focused. Use color keys in `theme.colors` @example focusBorderColor = "blue.500"

string

isDisabled

If true, the form control will be disabled. This has 2 side effects: - The FormLabel will have `data-disabled` attribute - The form element (e.g, Input) will be disabled

boolean

isInvalid

If true, the form control will be invalid. This has 2 side effects: - The FormLabel and FormErrorIcon will have `data-invalid` set to true - The form element (e.g, Input) will have `aria-invalid` set to true

boolean

isReadOnly

If true, the form control will be readonly

boolean

isRequired

If true, the form control will be required. This has 2 side effects: - The FormLabel will show a required indicator - The form element (e.g, Input) will have `aria-required` set to true

boolean

size

"xs" | "sm" | "md" | "lg"
"md"

variant

"outline" | "flushed" | "filled" | "unstyled"
"outline"
footer logo

© 2022 Designed with chakra ui. Powered by contentlayerjs and nextjs etc. All rights reserved

TwitterYouTubeGithub