Skip to main content

Your privacy settings

We use cookies to help you with journey planning and relevant disruptions, remember your login and show you content you might be interested in. If you’re happy with the use of cookies by West Midlands Combined Authority and our selected partners, click ‘Accept all cookies’. Or click ‘Manage cookies’ to learn more.

Manage Cookies
Beta

This is a new service - your feedback will help us to improve it.

Components

Textarea

About

What does it do?

  • Allows users to enter more than one line of text.
  • Allows users to write whatever they like, also called free text.

When to use it?

  • When the user needs to enter lots of text. For example, a paragraph.

When not to use it?

  • When the user needs to enter one line of text. Use the input component instead.
  • Use fixed-width inputs for content that has a known length, e.g. postcode.
  • When there are limited options. Use a different form element that limits the options.


HTML markup
<div class="wmnds-fe-group wmnds-m-t-20">
  <label class="wmnds-fe-label wmnds-m-t-20" for="example-textarea">Textarea label</label>
  <textarea class="wmnds-fe-textarea" id="example-textarea" name="example-textarea" rows="2" maxLength="200" placeholder="Textarea placeholder..." required="true"></textarea>
</div>

Nunjucks markup
{% from "wmnds/components/form-elements/textarea/_textarea.njk" import wmndsTextarea %}

{{
   wmndsTextarea({
      id: "example-textarea",
      name: "example-textarea",
      rows: "2",
      required: true,
      error: false,
      errorMessage: {
         id: null,
         contentText: null,
         contentHTML: "<span>Custom <em>error message</em></span>",
         classes: null
      }
      classes: null,
      value: "",
      label: {
         contentText: "Textarea label",
         contentHTML: "<span>Textarea label <em>updated</em></span>",
         classes: "wmnds-m-t-20"
      },
      disabled: false,
      maxLength: "200",
      placeholder: "Textarea placeholder...",
      formGroup: {
         classes: "wmnds-m-t-20"
      },
   })
}}

Nunjucks properties
NameTypeDescription
idstringRequired. Must be unique. The id of the textarea.
namestringRequired. The name of the textarea, which is submitted with the form data.
rowsstringOptional number of textarea rows. Default is 3 rows.
requiredbooleanIf true, textarea is required/must be filled out. Defaults to false.
errorbooleanIf true, an error will be displayed. Defaults to false.
errorMessageobjectOptions for the error message component. See errorMessage.
classesstringClasses to add to the textarea.
valuestringOptional initial value of the textarea.
labelObjectRequired. Options for the label component. See label.
disabledbooleanIf true, textarea should be disabled. Defaults to false.
maxLengthstringThe maxLength is the maximum number of characters allowed in the text area. It's an optional field.
placeholderstringPlaceholder is a short hint that describes the expected value of a text area. It's an optional field.
formGroupObjectOptions for the form-group wrapper See formGroup below.

Options for errorMessage

NameTypeDescription
idstringId attribute to add to the error message span tag.
contentTextstringRequired. Text to use within the error message. If contentHTML is supplied, this is ignored.
contentHTMLstringRequired. HTML to use within the error message
classesstringClasses to add to the error message span tag.

Options for label

NameTypeDescription
contentTextstringRequired. If contentHTML is set, this is not required. Text to use within the label. If contentHTML is provided, the contentText argument will be ignored.
contentHTMLstringRequired. If contentText is set, this is not required. HTML to use within the label. If contentHTML is provided, the contentText argument will be ignored.
classesstringClasses to add to the label tag.

Options for formGroup

NameTypeDescription
classesstringClasses to add to the form group (e.g. to show error state for the whole group)

Textarea with error


Textarea custom error message

HTML markup
<div class="wmnds-fe-group wmnds-m-t-20 wmnds-fe-group--error">
  <label class="wmnds-fe-label wmnds-m-t-20" for="error-textarea">Textarea label</label>
  <span class="wmnds-fe-error-message">Textarea custom error message</span>
  <textarea class="wmnds-fe-textarea wmnds-fe-input--error" id="error-textarea" name="error-textarea" rows="2" maxLength="200" placeholder="Textarea placeholder..." required="true"></textarea>
</div>

Nunjucks markup
{% from "wmnds/components/form-elements/textarea/_textarea.njk" import wmndsTextarea %}

{{
   wmndsTextarea({
      id: "example-textarea",
      name: "example-textarea",
      rows: "2",
      required: true,
      error: false,
      errorMessage: {
         id: null,
         contentText: null,
         contentHTML: "<span>Custom <em>error message</em></span>",
         classes: null
      }
      classes: null,
      value: "",
      label: {
         contentText: "Textarea label",
         contentHTML: "<span>Textarea label <em>updated</em></span>",
         classes: "wmnds-m-t-20"
      },
      disabled: false,
      maxLength: "200",
      placeholder: "Textarea placeholder...",
      formGroup: {
         classes: "wmnds-m-t-20"
      },
   })
}}

Nunjucks properties
NameTypeDescription
idstringRequired. Must be unique. The id of the textarea.
namestringRequired. The name of the textarea, which is submitted with the form data.
rowsstringOptional number of textarea rows. Default is 3 rows.
requiredbooleanIf true, textarea is required/must be filled out. Defaults to false.
errorbooleanIf true, an error will be displayed. Defaults to false.
errorMessageobjectOptions for the error message component. See errorMessage.
classesstringClasses to add to the textarea.
valuestringOptional initial value of the textarea.
labelObjectRequired. Options for the label component. See label.
disabledbooleanIf true, textarea should be disabled. Defaults to false.
maxLengthstringThe maxLength is the maximum number of characters allowed in the text area. It's an optional field.
placeholderstringPlaceholder is a short hint that describes the expected value of a text area. It's an optional field.
formGroupObjectOptions for the form-group wrapper See formGroup below.

Options for errorMessage

NameTypeDescription
idstringId attribute to add to the error message span tag.
contentTextstringRequired. Text to use within the error message. If contentHTML is supplied, this is ignored.
contentHTMLstringRequired. HTML to use within the error message
classesstringClasses to add to the error message span tag.

Options for label

NameTypeDescription
contentTextstringRequired. If contentHTML is set, this is not required. Text to use within the label. If contentHTML is provided, the contentText argument will be ignored.
contentHTMLstringRequired. If contentText is set, this is not required. HTML to use within the label. If contentHTML is provided, the contentText argument will be ignored.
classesstringClasses to add to the label tag.

Options for formGroup

NameTypeDescription
classesstringClasses to add to the form group (e.g. to show error state for the whole group)