# Textarea A styled multi-line text input with optional label, description, default value, and HTMX attributes. --- ## HTML structure ``` div.flex.flex-col.gap-1.5 label[for={id}].text-sm.font-medium ← omitted when label is empty {label} textarea[id, name, placeholder, rows, class, $$HxAttrs$$] {defaultValue} p.text-sm.text-muted-foreground ← omitted when description is empty {description} ``` --- ## CSS mechanics | Class | Effect | |---|---| | `flex min-h-[80px] w-full rounded-md border border-input bg-background` | Full-width field with minimum height | | `px-3 py-2 text-sm` | Inner padding and text size | | `focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring` | Keyboard focus ring | | `disabled:cursor-not-allowed disabled:opacity-50` | Disabled state | | `placeholder:text-muted-foreground` | Muted placeholder text | | `resize-y` | Allows vertical resize only | --- ## Constructor signature ```csharp public Textarea( string id, string name = "", string placeholder = "", string label = "", string description = "", string defaultValue = "", string extraClasses = "", string hxAttrs = "", int rows = 3) ``` | Parameter | Description | |---|---| | `id` | Element id and label `for` target | | `name` | Form field name | | `placeholder` | Placeholder text | | `label` | Optional visible label | | `description` | Optional helper text below the field | | `defaultValue` | Pre-filled content of the textarea | | `extraClasses` | Additional Tailwind classes on the textarea | | `hxAttrs` | Verbatim HTMX / data attributes | | `rows` | Number of visible rows (default: 3) | --- ## Usage examples ### Comment field ```csharp new Textarea( id: "comment", name: "comment", placeholder: "Write a comment…", label: "Comment", rows: 5) ``` ### Bio field with default value ```csharp new Textarea( id: "bio", name: "bio", label: "Bio", description: "Tell us about yourself (max 280 characters)", defaultValue: user.Bio ?? "") ``` ### Auto-expand with HTMX ```csharp new Textarea( id: "notes", name: "notes", label: "Notes", rows: 3, hxAttrs: """oninput="this.style.height=''; this.style.height=this.scrollHeight+'px'"""") ``` ### Auto-save on input ```csharp new Textarea( id: "draft", name: "content", label: "Draft", hxAttrs: """hx-post="/drafts/save" hx-trigger="keyup changed delay:500ms" hx-include="[name='content']"""") ``` ### Reading in a form handler ```csharp public record Command([property: FromForm] string Comment); // command.Comment contains the textarea value ``` --- ## Tips and tricks - HTML-encode the `defaultValue` if it contains user-supplied content — it is placed directly inside the `