Textarea
A basic widget for getting the user text or messages.
import { Textarea } from 'rizzui/textarea';
Default
The default style of Textarea component.
import { Textarea } from 'rizzui/textarea';
export default function App() {
return <Textarea label="Message" placeholder="Write your message..." />;
}
Variants
You can change the style of Textarea using variant property.
import { Textarea } from 'rizzui/textarea';
export default function App() {
return (
<>
<Textarea label="Outline" placeholder="Enter your message" />
<Textarea label="Flat" variant="flat" placeholder="Enter your message" />
<Textarea label="Text" variant="text" placeholder="Enter your message" />
</>
);
}
Sizes
You can change the style of Textarea using size property.
import { Textarea } from 'rizzui/textarea';
export default function App() {
return (
<>
<Textarea label="Small" placeholder="Enter your message" size="sm" />
<Textarea label="Default" placeholder="Enter your message" />
<Textarea label="Large" placeholder="Enter your message" size="lg" />
</>
);
}
With Custom Rows & Cols
You can change rows and cols of Textarea using rows & cols property.
import { Textarea } from 'rizzui/textarea';
export default function App() {
return (
<Textarea
rows={6}
cols={50}
label="Message"
placeholder="Enter your message"
textareaClassName="overflow-y-auto w-full md:w-auto"
defaultValue="Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptate architecto aliquam nulla et!
Amet corrupti a consectetur aliquid qui eius soluta! Quibusdam debitis natus optio quasi
assumenda provident dolores animi? Lorem ipsum dolor sit amet consectetur adipisicing elit.
Voluptate architecto aliquam nulla et! Amet corrupti a consectetur aliquid qui eius soluta!
Quibusdam debitis natus optio quasi assumenda provident dolores animi?"
/>
);
}
With Character Count
You can set character limit and show character counter of Textarea using maxLength & renderCharacterCount property.
'use client';
import { useState } from 'react';
import { Textarea } from 'aegon-ui';
export default function App() {
const [state, setState] = useState('Do not lose hope, nor be sad.');
return (
<Textarea
label="Message"
value={state}
maxLength={100}
onChange={(e) => setState(e.target.value)}
renderCharacterCount={({ characterCount, maxLength }) => (
<div className="text-right text-sm opacity-70 rtl:text-left">
{characterCount}/{maxLength}
</div>
)}
/>
);
}
With Clearable Button
You can add a clear button of Textarea using clearable property.
'use client';
import { useState } from 'react';
import { Textarea } from 'aegon-ui';
export default function App() {
const [state, setState] = useState(
'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.'
);
return (
<Textarea
label="Message"
clearable
value={state}
onClear={() => setState('')}
onChange={(e) => setState(e.target.value)}
/>
);
}
Disabled
You can change disabled state of Textarea using disabled property.
'use client';
import { Textarea } from 'rizzui/textarea';
export default function App() {
return <Textarea disabled label="Message" placeholder="Enter your message" />;
}
With Helper Text
You can add helper text to Textarea using helperText property.
import { Textarea } from 'rizzui/textarea';
export default function App() {
return (
<Textarea
label="Message"
placeholder="Enter your message"
helperText="This is helper text."
/>
);
}
With Error Message
You can show the validation error message using error property.
import { Textarea } from 'rizzui/textarea';
export default function App() {
return (
<Textarea
label="Message"
error="This field is required"
placeholder="Enter your message"
/>
);
}
API Reference
Textarea Props
Here is the API documentation of the Textarea component. And the rest of the props are the same as the original html textarea field.
| Props | Type | Description | Default |
|---|---|---|---|
| label | ReactNode | Set field label | __ |
| labelWeight | LabelWeight | Set label font weight | "medium" |
| variant | TextareaVariants | The variants of the component are: | "outline" |
| size | TextareaSizes | The size of the component. "sm" is equivalent to the dense input styling. | "md" |
| children | ReactNode | Default value in textarea | __ |
| cols | number | Set custom cols | __ |
| rows | number | Set custom rows | 5 |
| placeholder | string | __ | |
| disabled | boolean | Whether the textarea is disabled | __ |
| error | string | Show error message using this prop | __ |
| helperText | ReactNode | Add helper text. Can be a string or a React component | __ |
| clearable | boolean | Add clearable option | __ |
| onClear | TextareaOnClear | Callback function called when the clear button is clicked | __ |
| renderCharacterCount | TextareaRenderCharacterCount | Use this prop to show character count limit | __ |
| labelClassName | string | Use labelClassName prop to do some additional style for the label | __ |
| textareaClassName | string | Add custom classes for the input field extra style | __ |
| helperClassName | string | This prop allows you to customize the helper message style | __ |
| errorClassName | string | This prop allows you to customize the error message style | __ |
| className | string | Add custom classes to the root of the component | __ |
| ref | Ref<HTMLTextAreaElement> | __ | |
| ... | TextareaHTMLAttributes | native props like value, onChange, onFocus, onBlur ... | __ |
Textarea Variants
type TextareaVariants = 'outline' | 'flat' | 'text';
Label Weight
type LabelWeight = 'normal' | 'medium' | 'semibold' | 'bold';
Textarea Sizes
type TextareaSizes = 'sm' | 'md' | 'lg';
Textarea onClear
type TextareaOnClear = (event) => void;
Textarea Render Character Count
type TextareaRenderCharacterCount =
| (({
characterCount,
maxLength,
}: {
characterCount?: number;
maxLength?: number;
}) => ReactNode)
| undefined;