Textarea
Several lines of text: a description, a note, a rule. It grows as the person writes.
import { Textarea } from '@sypnia/ui/react'
A description
It starts two lines tall and grows with the text.
One or two sentences for the people you invite.
Code
import { Field, FormGrid, Textarea } from '@sypnia/ui/react';
// It grows with what is written, and can be dragged taller.
export default function Basic() {
return (
<FormGrid>
<Field label="Description" optional hint="One or two sentences for the people you invite." wide>
<Textarea defaultValue="Orders, customers and products of the online store. The mobile app and the back office both read from here." />
</Field>
</FormGrid>
);
} Machine text
A condition in SQL, in the mono face and without spell checking.
A condition in SQL. A row is visible when it is true.
Code
import { Field, FormGrid, Textarea } from '@sypnia/ui/react';
export default function Machine() {
return (
<FormGrid>
<Field label="Access rule" hint="A condition in SQL. A row is visible when it is true." wide>
<Textarea machine rows={3} spellCheck={false} defaultValue={"customer_id = auth.user_id()\nand status <> 'draft'"} />
</Field>
</FormGrid>
);
} Limit and disabled
The hint counts characters from the start; delete some text to clear the error.
118 of 120 characters
Refunds are closed for this order.
Code
import { useState } from 'react';
import { Field, FormGrid, Textarea } from '@sypnia/ui/react';
export default function States() {
const [note, setNote] = useState('Refund approved by phone. The customer keeps the damaged item and gets a new one on the next shipment, free of charge.');
const max = 120;
return (
<FormGrid>
<Field label="Note for the order" hint={`${note.length} of ${max} characters`}
error={note.length > max ? `Shorten the note: it has ${note.length - max} characters too many.` : undefined}>
<Textarea value={note} onChange={(e) => setNote(e.target.value)} />
</Field>
<Field label="Reason for the refund" hint="Refunds are closed for this order.">
<Textarea disabled defaultValue="Arrived damaged." />
</Field>
</FormGrid>
);
} When to use it
Use it when
- The answer may take more than one line: descriptions, notes, messages.
- A short piece of code or a condition: add
machine.
Do not use it when
- One line is enough: use Input.
- It is real code with highlighting, line numbers or many lines: that is CodeEditor.
- There is a strict limit and you only say so after the person passes it. Say the limit in the hint from the start.
For everyone
- Inside a Field it takes the label, the hint and the error by itself.
- Enter adds a line; it never submits the form. Tab leaves the field.
- It can be dragged taller, and grows with its content where the browser allows it.
Props
| Textarea | Type | Default |
|---|---|---|
machine | boolean |