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.
Divider

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

PropDescriptionDefault
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
autoFocus?Whether the element should receive focus on render.-
onFocus?Handler that is called when the element receives focus.-
onBlur?Handler that is called when the element loses focus.-
onFocusChange?Handler that is called when the element's focus status changes.-
onKeyDown?Handler that is called when a key is pressed.-
onKeyUp?Handler that is called when a key is released.-
aria-haspopup?Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.-
aria-controls?Identifies the element (or elements) whose contents or presence are controlled by the current element.-
type?The type of input to render. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype).-
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.-
id?The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).-
aria-label?Defines a string value that labels the current element.-
aria-labelledby?Identifies the element (or elements) that labels 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.-
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).-
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.-
validationBehavior?Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.'native'
onChange?Handler that is called when the value changes.-
isRequired?Whether user input is required on the input before form submission.-
isInvalid?Whether the value is invalid.-
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.-
aria-errormessage?Identifies the element that provides an error message for the object.-
defaultValue?The default value (uncontrolled).-
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).-
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.-
enterKeyHint?An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint].-
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).-
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).-
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).-
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).-
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).-
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).-
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).-
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).-
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).-
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).-
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).-
ref?Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}-
key?-