Components
Textarea
Textarea is used when the user needs to enter text that spans multiple lines.
<ds-field class="ds-field">
<label class="ds-label">Label</label>
<textarea class="ds-input"></textarea>
</ds-field>const Preview = () => { return ( <Field> <Label>Label</Label> <Textarea /> </Field> ); }; render(<Preview />)
Use
Apply the class name ds-input to <textarea>.
<textarea class="ds-input"></textarea>
Example
With Rows
Use the rows attribute to set the number of visible rows in the text area.
This only affects the initial height of the field.
<ds-field class="ds-field">
<label class="ds-label">Description</label>
<textarea class="ds-input" rows="6"></textarea>
</ds-field>const WithRowsEn = () => { return ( <Field> <Label>Description</Label> <Textarea rows={6} /> </Field> ); }; render(<WithRowsEn />)
CSS variables and data attributes
Textarea gets styling from ds-input, so we show variables and data attributes from that class here.
Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.
| Name | Value |
|---|---|
| --dsc-input-accent-color | var(--ds-color-base-default) |
| --dsc-input-accent-color--invalid | var(--ds-color-danger-text-subtle) |
| --dsc-input-background | var(--ds-color-neutral-surface-default) |
| --dsc-input-background--readonly | var(--ds-color-neutral-surface-tinted) |
| --dsc-input-border-color | var(--ds-color-neutral-border-default) |
| --dsc-input-border-color--readonly | var(--ds-color-neutral-border-subtle) |
| --dsc-input-border-radius | var(--ds-border-radius-md) |
| --dsc-input-border-style | solid |
| --dsc-input-border-width | var(--ds-border-width-default) |
| --dsc-input-border-width--toggle | max(var(--ds-border-width-default), var(--ds-size-1) / 2) |
| --dsc-input-color | var(--ds-color-neutral-text-default) |
| --dsc-input-color--readonly | var(--ds-color-neutral-text-default) |
| --dsc-input-color-placeholder | color-mix(in srgb, var(--dsc-input-color), transparent 30%) |
| --dsc-input-font-size | calc(max(1rem, 1em)) |
| --dsc-input-line-height | var(--ds-line-height-md) |
| --dsc-input-outline-color--hover | var(--ds-color-neutral-border-default) |
| --dsc-input-outline-color--toggle--hover | var(--dsc-input-accent-color) |
| --dsc-input-outline-style--hover | solid |
| --dsc-input-outline-width--hover | var(--ds-border-width-default) |
| --dsc-input-padding | var(--dsc-input-padding-block) var(--dsc-input-padding-inline) |
| --dsc-input-padding-block | var(--ds-size-2) |
| --dsc-input-padding-inline | var(--ds-size-3) |
| --dsc-input-size | var(--ds-size-12) |
| --dsc-input-size--toggle | var(--ds-size-6) |
| --dsc-input-stroke-color | var(--ds-color-base-contrast-default) |
| --dsc-input-stroke-color--invalid | var(--ds-color-danger-base-contrast-default) |
| --dsc-input-stroke-width | 0.05em |
| Name | Value |
|---|---|
| data-width | auto |
React
import { Textarea, Label } from "@digdir/designsystemet-react";
<>
<Label htmlFor="my-textarea">Label</Label>
<Textarea id="my-textarea" />
</>;