TextArea
Om komponenten
TextArea, eller fritekstfelt, er et skjemaelement som gir brukeren mulighet til å skrive tekst over flere linjer.
Egnet til:
- Når bruker skal kunne skrive lengre tekster, som å gi en beskrivelse.
Uegnet til:
- Korte tekster, slik som navn eller medlemsnummer. Bruk da heller TextField.

Varianter
Uncontrolled
Uncontrolled TextArea med label
<TextArea label="Beskrivelse" />
Uncontrolled TextArea med label og description
<TextArea label="Beskrivelse" description="Maks 250 tegn" />
Uncontrolled TextArea med label og placeholder
<TextArea placeholder="Gi en kort beskrivelse" label="Beskrivelse" />
Uncontrolled TextArea med usynlig label
<TextArea aria-label="Beskrivelse" />
Validering
Uncontrolled TextArea med feilmelding
<TextArea label="Beskrivelse" errorMessage="Her er det noe feil!" />
Uncontrolled, påkrevd TextArea
<form onSubmit={(e) => e.preventDefault()} className="grid gap-6" > <TextArea label="Beskrivelse" isRequired /> <Button type="submit" className="w-fit"> Send inn </Button> </form>
Uncontrolled TextArea med maks tre linjer
<TextArea label="Beskrivelse" rows={3} />
Controlled
Controlled TextArea
function(){ const [text, setText] = React.useState(""); return <TextArea label="Beløp" value={text} onChange={setText} /> }
Props
TextArea
| Prop | Description | Default |
|---|---|---|
className? | Additional CSS className for the element. | - |
description? | Help text for the form control. | - |
errorMessage? | Error message for the form control. Automatically sets `isInvalid` to true | - |
label? | Label for the form control. | - |
placeholder? | Placeholder text. Only visible when the input value is empty. | - |
style? | Additional style properties for the element. | - |
rows? | The number of visible text lines for the control. | 2 |
ref? | Ref for the textarea element. | - |
form? | The `<form>` element to associate the input with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). | - |
slot? | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. | - |
pattern? | Regex pattern that the value of the input must match to be valid. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefpattern). | - |
defaultValue? | The default value (uncontrolled). | - |
autoFocus? | Whether the element should receive focus on render. | - |
dir? | - | |
enterKeyHint? | An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint). | - |
hidden? | - | |
id? | The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). | - |
lang? | - | |
spellCheck? | An enumerated attribute that defines whether the element may be checked for spelling errors. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck). | - |
translate? | - | |
autoCorrect? | An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete). | - |
inert? | - | |
inputMode? | Hints at the type of data that might be entered by the user while editing the element or its contents. See [MDN](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute). | - |
aria-activedescendant? | Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application. | - |
aria-autocomplete? | Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made. | - |
aria-controls? | Identifies the element (or elements) whose contents or presence are controlled by the current element. | - |
aria-describedby? | Identifies the element (or elements) that describes the object. | - |
aria-details? | Identifies the element (or elements) that provide a detailed, extended description for the object. | - |
aria-errormessage? | Identifies the element that provides an error message for the object. | - |
aria-haspopup? | Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. | - |
aria-label? | Defines a string value that labels the current element. | - |
aria-labelledby? | Identifies the element (or elements) that labels the current element. | - |
onCopy? | Handler that is called when the user copies text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy). | - |
onCut? | Handler that is called when the user cuts text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut). | - |
onPaste? | Handler that is called when the user pastes text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste). | - |
onCompositionEnd? | Handler that is called when a text composition system completes or cancels the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionend_event). | - |
onCompositionStart? | Handler that is called when a text composition system starts a new text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event). | - |
onCompositionUpdate? | Handler that is called when a new character is received in the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionupdate_event). | - |
onFocus? | Handler that is called when the element receives focus. | - |
onBlur? | Handler that is called when the element loses focus. | - |
onChange? | Handler that is called when the value changes. | - |
onBeforeInput? | Handler that is called when the input value is about to be modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event). | - |
onInput? | Handler that is called when the input value is modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event). | - |
onKeyDown? | Handler that is called when a key is pressed. | - |
onKeyUp? | Handler that is called when a key is released. | - |
onAuxClick? | - | |
onAuxClickCapture? | - | |
onClick? | - | |
onClickCapture? | - | |
onContextMenu? | - | |
onContextMenuCapture? | - | |
onDoubleClick? | - | |
onDoubleClickCapture? | - | |
onMouseDown? | - | |
onMouseDownCapture? | - | |
onMouseEnter? | - | |
onMouseLeave? | - | |
onMouseMove? | - | |
onMouseMoveCapture? | - | |
onMouseOut? | - | |
onMouseOutCapture? | - | |
onMouseOver? | - | |
onMouseOverCapture? | - | |
onMouseUp? | - | |
onMouseUpCapture? | - | |
onSelect? | Handler that is called when text in the input is selected. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/select_event). | - |
onTouchCancel? | - | |
onTouchCancelCapture? | - | |
onTouchEnd? | - | |
onTouchEndCapture? | - | |
onTouchMove? | - | |
onTouchMoveCapture? | - | |
onTouchStart? | - | |
onTouchStartCapture? | - | |
onPointerDown? | - | |
onPointerDownCapture? | - | |
onPointerMove? | - | |
onPointerMoveCapture? | - | |
onPointerUp? | - | |
onPointerUpCapture? | - | |
onPointerCancel? | - | |
onPointerCancelCapture? | - | |
onPointerEnter? | - | |
onPointerLeave? | - | |
onPointerOver? | - | |
onPointerOverCapture? | - | |
onPointerOut? | - | |
onPointerOutCapture? | - | |
onGotPointerCapture? | - | |
onGotPointerCaptureCapture? | - | |
onLostPointerCapture? | - | |
onLostPointerCaptureCapture? | - | |
onScroll? | - | |
onScrollCapture? | - | |
onWheel? | - | |
onWheelCapture? | - | |
onAnimationStart? | - | |
onAnimationStartCapture? | - | |
onAnimationEnd? | - | |
onAnimationEndCapture? | - | |
onAnimationIteration? | - | |
onAnimationIterationCapture? | - | |
onTransitionCancel? | - | |
onTransitionCancelCapture? | - | |
onTransitionEnd? | - | |
onTransitionEndCapture? | - | |
onTransitionRun? | - | |
onTransitionRunCapture? | - | |
onTransitionStart? | - | |
onTransitionStartCapture? | - | |
onFocusChange? | Handler that is called when the element's focus status changes. | - |
type? | The type of input to render. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype). | 'text' |
name? | The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). | - |
value? | The current value (controlled). | - |
excludeFromTabOrder? | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. | - |
autoComplete? | Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). | - |
maxLength? | The maximum number of characters supported by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength). | - |
minLength? | The minimum number of characters required by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength). | - |
isRequired? | Whether user input is required on the input before form submission. | - |
isInvalid? | Whether the value is invalid. | - |
validationBehavior? | Whether to use native HTML form validation to prevent form submission when a field value is missing or invalid, or mark fields as required or invalid via ARIA. | 'native' |
validate? | A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if `validationBehavior="native"`. For realtime validation, use the `isInvalid` prop instead. | - |