Skip to main content Skip to list of components
Service phase: Beta

This is a new service – give us your feedback to help improve it.

Components

Textarea

Use the textarea component to allow the users to enter a longer string of text information such as feedback.

Status
To be reviewed

Contents

Open this example in new tab

Contents

HTML

<div class="tna-form-item">
  <div class="tna-form-item__header">
    <label class="tna-form-item__label tna-heading-m" for="feedback">
      Enter your feedback
    </label>
  </div>
  <div class="tna-form-item__body">
    <textarea id="feedback" class="tna-textarea" name="feedback" spellcheck="false" autocapitalize="off" autocorrect="off" rows="5"></textarea>
  </div>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

Required.

The label for the textarea field.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the textarea title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the textarea component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

value string

The form field value.

error object

If set, the details of any errors.

See macro options for error.

characterCount object

Configuration for the character count feature. Can not be used with itemiseRows.

See macro options for characterCount.

spellcheck boolean

If true, enable spellcheck for the text input.

Default value: false

autocapitalize string

If true, enable automatic capitalization for the text input. This is not supported in all browsers.

Default value: off

autocorrect boolean

If true, enable autocorrect for the text input. This is not supported in all browsers.

Default value: false

size string

Set the width of the textarea. Can be m, l or xl.

rows number

Set the number of visible text lines for the textarea. A scrollbar will appear if the content exceeds the height.

Default value: 5

itemiseRows boolean

If true, when JavaScript is available, parse each row of the textarea content into a list of items. Ignored if characterCount is enabled.

Default value: false

formItemClasses string

Classes to add to the textarea form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the textarea form group.

classes string

Classes to add to the textarea.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for characterCount
Name Type Description
max number

Required.

The maximum number of characters (or words if countType is set to words).

countType string

The type of character count to display. Can be length, characters or words. length counts the number of raw characters used, characters counts the number of visual characters, and words counts the number of words.

Default value: length

threshold number

The character count threshold in percent at which to start displaying a warning.

Default value: 80

debounceDuration number

The debounce duration in milliseconds for updating the character count.

Default value: 1000

{% from "nationalarchives/components/textarea/macro.njk" import tnaTextarea %}

{{ tnaTextarea({
  label: "Enter your feedback",
  id: "feedback",
  name: "feedback"
}) }}

Jinja

Important information

This is an experimental feature showing a Jinja2 macro based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/textarea/macro.html" import tnaTextarea %}

{{ tnaTextarea({
  "label": "Enter your feedback",
  "id": "feedback",
  "name": "feedback"
}) }}
Open this example in new tab

Contents

HTML

<div class="tna-form-item">
  <div class="tna-form-item__header">
    <label class="tna-form-item__label tna-heading-m" for="feedback">
      Enter your feedback
    </label>
  </div>
  <div class="tna-form-item__body">
    <textarea id="feedback" class="tna-textarea" name="feedback" spellcheck="false" autocapitalize="off" autocorrect="off" rows="5">I like this 👍🏼</textarea>
  </div>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

Required.

The label for the textarea field.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the textarea title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the textarea component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

value string

The form field value.

error object

If set, the details of any errors.

See macro options for error.

characterCount object

Configuration for the character count feature. Can not be used with itemiseRows.

See macro options for characterCount.

spellcheck boolean

If true, enable spellcheck for the text input.

Default value: false

autocapitalize string

If true, enable automatic capitalization for the text input. This is not supported in all browsers.

Default value: off

autocorrect boolean

If true, enable autocorrect for the text input. This is not supported in all browsers.

Default value: false

size string

Set the width of the textarea. Can be m, l or xl.

rows number

Set the number of visible text lines for the textarea. A scrollbar will appear if the content exceeds the height.

Default value: 5

itemiseRows boolean

If true, when JavaScript is available, parse each row of the textarea content into a list of items. Ignored if characterCount is enabled.

Default value: false

formItemClasses string

Classes to add to the textarea form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the textarea form group.

classes string

Classes to add to the textarea.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for characterCount
Name Type Description
max number

Required.

The maximum number of characters (or words if countType is set to words).

countType string

The type of character count to display. Can be length, characters or words. length counts the number of raw characters used, characters counts the number of visual characters, and words counts the number of words.

Default value: length

threshold number

The character count threshold in percent at which to start displaying a warning.

Default value: 80

debounceDuration number

The debounce duration in milliseconds for updating the character count.

Default value: 1000

{% from "nationalarchives/components/textarea/macro.njk" import tnaTextarea %}

{{ tnaTextarea({
  label: "Enter your feedback",
  id: "feedback",
  name: "feedback",
  value: "I like this 👍🏼"
}) }}

Jinja

Important information

This is an experimental feature showing a Jinja2 macro based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/textarea/macro.html" import tnaTextarea %}

{{ tnaTextarea({
  "label": "Enter your feedback",
  "id": "feedback",
  "name": "feedback",
  "value": "I like this 👍🏼"
}) }}
Open this example in new tab

Contents

HTML

<div class="tna-form-item">
  <div class="tna-form-item__header">
    <label class="tna-form-item__label tna-heading-m" for="feedback">
      Enter your feedback
    </label>
  </div>
  <p id="feedback-hint" class="tna-form-item__hint">
    Tell us what you think about this service.
  </p>
  <div class="tna-form-item__body">
    <textarea id="feedback" class="tna-textarea" name="feedback" spellcheck="false" autocapitalize="off" autocorrect="off" rows="5" aria-describedby="feedback-hint  "></textarea>
  </div>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

Required.

The label for the textarea field.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the textarea title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the textarea component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

value string

The form field value.

error object

If set, the details of any errors.

See macro options for error.

characterCount object

Configuration for the character count feature. Can not be used with itemiseRows.

See macro options for characterCount.

spellcheck boolean

If true, enable spellcheck for the text input.

Default value: false

autocapitalize string

If true, enable automatic capitalization for the text input. This is not supported in all browsers.

Default value: off

autocorrect boolean

If true, enable autocorrect for the text input. This is not supported in all browsers.

Default value: false

size string

Set the width of the textarea. Can be m, l or xl.

rows number

Set the number of visible text lines for the textarea. A scrollbar will appear if the content exceeds the height.

Default value: 5

itemiseRows boolean

If true, when JavaScript is available, parse each row of the textarea content into a list of items. Ignored if characterCount is enabled.

Default value: false

formItemClasses string

Classes to add to the textarea form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the textarea form group.

classes string

Classes to add to the textarea.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for characterCount
Name Type Description
max number

Required.

The maximum number of characters (or words if countType is set to words).

countType string

The type of character count to display. Can be length, characters or words. length counts the number of raw characters used, characters counts the number of visual characters, and words counts the number of words.

Default value: length

threshold number

The character count threshold in percent at which to start displaying a warning.

Default value: 80

debounceDuration number

The debounce duration in milliseconds for updating the character count.

Default value: 1000

{% from "nationalarchives/components/textarea/macro.njk" import tnaTextarea %}

{{ tnaTextarea({
  label: "Enter your feedback",
  id: "feedback",
  name: "feedback",
  hint: "Tell us what you think about this service."
}) }}

Jinja

Important information

This is an experimental feature showing a Jinja2 macro based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/textarea/macro.html" import tnaTextarea %}

{{ tnaTextarea({
  "label": "Enter your feedback",
  "id": "feedback",
  "name": "feedback",
  "hint": "Tell us what you think about this service."
}) }}
Open this example in new tab

Contents

HTML

<div class="tna-form-item tna-form-item--error">
  <div class="tna-form-item__header">
    <label class="tna-form-item__label tna-heading-m" for="feedback">
      Enter your feedback
    </label>
  </div>
  <p id="feedback-error" class="tna-form-item__error">
    <span class="tna-visually-hidden">Error:</span> Enter some feedback
  </p>
  <div class="tna-form-item__body">
    <textarea id="feedback" class="tna-textarea" name="feedback" spellcheck="false" autocapitalize="off" autocorrect="off" rows="5" aria-describedby=" feedback-error "></textarea>
  </div>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

Required.

The label for the textarea field.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the textarea title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the textarea component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

value string

The form field value.

error object

If set, the details of any errors.

See macro options for error.

characterCount object

Configuration for the character count feature. Can not be used with itemiseRows.

See macro options for characterCount.

spellcheck boolean

If true, enable spellcheck for the text input.

Default value: false

autocapitalize string

If true, enable automatic capitalization for the text input. This is not supported in all browsers.

Default value: off

autocorrect boolean

If true, enable autocorrect for the text input. This is not supported in all browsers.

Default value: false

size string

Set the width of the textarea. Can be m, l or xl.

rows number

Set the number of visible text lines for the textarea. A scrollbar will appear if the content exceeds the height.

Default value: 5

itemiseRows boolean

If true, when JavaScript is available, parse each row of the textarea content into a list of items. Ignored if characterCount is enabled.

Default value: false

formItemClasses string

Classes to add to the textarea form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the textarea form group.

classes string

Classes to add to the textarea.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for characterCount
Name Type Description
max number

Required.

The maximum number of characters (or words if countType is set to words).

countType string

The type of character count to display. Can be length, characters or words. length counts the number of raw characters used, characters counts the number of visual characters, and words counts the number of words.

Default value: length

threshold number

The character count threshold in percent at which to start displaying a warning.

Default value: 80

debounceDuration number

The debounce duration in milliseconds for updating the character count.

Default value: 1000

{% from "nationalarchives/components/textarea/macro.njk" import tnaTextarea %}

{{ tnaTextarea({
  label: "Enter your feedback",
  id: "feedback",
  name: "feedback",
  error: {
    text: "Enter some feedback"
  }
}) }}

Jinja

Important information

This is an experimental feature showing a Jinja2 macro based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/textarea/macro.html" import tnaTextarea %}

{{ tnaTextarea({
  "label": "Enter your feedback",
  "id": "feedback",
  "name": "feedback",
  "error": {
    "text": "Enter some feedback"
  }
}) }}

You can set a soft limit on the number of characters (or words) allowed in a textarea.

Important information

This component feature is still in the experimental phase. Length calculations can differ between older and newer browsers.
Open this example in new tab

Contents

HTML

<div class="tna-form-item" data-module="tna-textarea-character-count">
  <div class="tna-form-item__header">
    <label class="tna-form-item__label tna-heading-m" for="feedback">
      Enter your feedback
    </label>
  </div>
  <div class="tna-form-item__body">
    <textarea id="feedback" class="tna-textarea" name="feedback" spellcheck="false" autocapitalize="off" autocorrect="off" rows="5" aria-describedby="  feedback-count" data-max-length="100"></textarea>
    <div id="feedback-count" class="tna-visually-hidden">
      You can enter up to 100 characters</div>
    <p class="tna-textarea-count" aria-hidden="true">
      You can enter up to 100 characters</p>
    <div class="tna-textarea-count__screen-reader-status tna-visually-hidden" aria-live="polite">
      You can enter up to 100 characters</div>
  </div>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

Required.

The label for the textarea field.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the textarea title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the textarea component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

value string

The form field value.

error object

If set, the details of any errors.

See macro options for error.

characterCount object

Configuration for the character count feature. Can not be used with itemiseRows.

See macro options for characterCount.

spellcheck boolean

If true, enable spellcheck for the text input.

Default value: false

autocapitalize string

If true, enable automatic capitalization for the text input. This is not supported in all browsers.

Default value: off

autocorrect boolean

If true, enable autocorrect for the text input. This is not supported in all browsers.

Default value: false

size string

Set the width of the textarea. Can be m, l or xl.

rows number

Set the number of visible text lines for the textarea. A scrollbar will appear if the content exceeds the height.

Default value: 5

itemiseRows boolean

If true, when JavaScript is available, parse each row of the textarea content into a list of items. Ignored if characterCount is enabled.

Default value: false

formItemClasses string

Classes to add to the textarea form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the textarea form group.

classes string

Classes to add to the textarea.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for characterCount
Name Type Description
max number

Required.

The maximum number of characters (or words if countType is set to words).

countType string

The type of character count to display. Can be length, characters or words. length counts the number of raw characters used, characters counts the number of visual characters, and words counts the number of words.

Default value: length

threshold number

The character count threshold in percent at which to start displaying a warning.

Default value: 80

debounceDuration number

The debounce duration in milliseconds for updating the character count.

Default value: 1000

{% from "nationalarchives/components/textarea/macro.njk" import tnaTextarea %}

{{ tnaTextarea({
  label: "Enter your feedback",
  id: "feedback",
  name: "feedback",
  characterCount: {
    max: 100
  }
}) }}

Jinja

Important information

This is an experimental feature showing a Jinja2 macro based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/textarea/macro.html" import tnaTextarea %}

{{ tnaTextarea({
  "label": "Enter your feedback",
  "id": "feedback",
  "name": "feedback",
  "characterCount": {
    "max": 100
  }
}) }}

There are three types of counter:

length (default)

The length is calculated using code points (raw characters). Using this counter type means that some multibyte characters such as emojis and certain non-Latin characters are counted as multiple characters.

Use when you have technical limitations on the length of text, such as stoaring the value in a database or sending it through an API.

characters

The character count tries to use locale-sensitive text segmentation. This more closely aligns to the number of visual characters on screen.

Use when there is no technical limitation in your service or the limit far exceeds your desired length by a factor of at least 10 to account for multibyte characters.

words

Like characters, the number of words is counted using locale-sensitive text segmentation. Some older browsers that lack the necessary features will fall back to simply counting words as blocks of characters with spaces in between.

Use when you want to try and limit the complexity of text input, for example keeping an enquiry simple by limiting it to 100 words.

Comparison of count types
Example text length characters words words (older browser)
text 4 4 1 1
♥ 1 1 0 1
❤️ 2 1 0 1
🤦🏼‍♂️ 7 1 0 1
cafȩ́ 6 4 1 1
TheNationalArchives 19 19 1 1
The_National💪🏼Archives 24 21 2 1
Open this example in new tab

Contents

HTML

<div class="tna-container">
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    <div class="tna-form-item" data-module="tna-textarea-character-count">
      <div class="tna-form-item__header">
        <label class="tna-form-item__label tna-heading-m" for="input1">
          Enter text (length)
        </label>
      </div>
      <div class="tna-form-item__body">
        <textarea id="input1" class="tna-textarea" name="input1" spellcheck="false" autocapitalize="off" autocorrect="off" rows="2" aria-describedby="  input1-count" data-max-length="100" data-debounce-duration="100">I ❤️ design</textarea>
        <div id="input1-count" class="tna-visually-hidden">
          You can enter up to 100 characters</div>
        <p class="tna-textarea-count" aria-hidden="true">
          You can enter up to 100 characters</p>
        <div class="tna-textarea-count__screen-reader-status tna-visually-hidden" aria-live="polite">
          You can enter up to 100 characters</div>
      </div>
    </div>
  </div>
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    <div class="tna-form-item" data-module="tna-textarea-character-count">
      <div class="tna-form-item__header">
        <label class="tna-form-item__label tna-heading-m" for="input2">
          Enter text (characters)
        </label>
      </div>
      <div class="tna-form-item__body">
        <textarea id="input2" class="tna-textarea" name="input2" spellcheck="false" autocapitalize="off" autocorrect="off" rows="2" aria-describedby="  input2-count" data-max-length="100" data-count-type="characters" data-debounce-duration="100">I ❤️ design</textarea>
        <div id="input2-count" class="tna-visually-hidden">
          You can enter up to 100 characters</div>
        <p class="tna-textarea-count" aria-hidden="true">
          You can enter up to 100 characters</p>
        <div class="tna-textarea-count__screen-reader-status tna-visually-hidden" aria-live="polite">
          You can enter up to 100 characters</div>
      </div>
    </div>
  </div>
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    <div class="tna-form-item" data-module="tna-textarea-character-count">
      <div class="tna-form-item__header">
        <label class="tna-form-item__label tna-heading-m" for="input3">
          Enter text (words)
        </label>
      </div>
      <div class="tna-form-item__body">
        <textarea id="input3" class="tna-textarea" name="input3" spellcheck="false" autocapitalize="off" autocorrect="off" rows="2" aria-describedby="  input3-count" data-max-length="10" data-count-type="words" data-debounce-duration="100">I ❤️ design</textarea>
        <div id="input3-count" class="tna-visually-hidden">
          You can enter up to 10 words</div>
        <p class="tna-textarea-count" aria-hidden="true">
          You can enter up to 10 words</p>
        <div class="tna-textarea-count__screen-reader-status tna-visually-hidden" aria-live="polite">
          You can enter up to 10 words</div>
      </div>
    </div>
  </div>
</div>
<script>
  const inputs = [
    document.getElementById("input1"),
    document.getElementById("input2"),
    document.getElementById("input3")
  ];
  const update = (event) => {
    inputs
      .filter(input => input !== event.target)
      .forEach(input => {
        input.value = event.target.value;
        input.dispatchEvent(new Event("focus"));
      })
  }
  inputs.forEach(input => {
    input.addEventListener("input", update);
  });
</script>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

Required.

The label for the textarea field.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the textarea title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the textarea component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

value string

The form field value.

error object

If set, the details of any errors.

See macro options for error.

characterCount object

Configuration for the character count feature. Can not be used with itemiseRows.

See macro options for characterCount.

spellcheck boolean

If true, enable spellcheck for the text input.

Default value: false

autocapitalize string

If true, enable automatic capitalization for the text input. This is not supported in all browsers.

Default value: off

autocorrect boolean

If true, enable autocorrect for the text input. This is not supported in all browsers.

Default value: false

size string

Set the width of the textarea. Can be m, l or xl.

rows number

Set the number of visible text lines for the textarea. A scrollbar will appear if the content exceeds the height.

Default value: 5

itemiseRows boolean

If true, when JavaScript is available, parse each row of the textarea content into a list of items. Ignored if characterCount is enabled.

Default value: false

formItemClasses string

Classes to add to the textarea form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the textarea form group.

classes string

Classes to add to the textarea.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for characterCount
Name Type Description
max number

Required.

The maximum number of characters (or words if countType is set to words).

countType string

The type of character count to display. Can be length, characters or words. length counts the number of raw characters used, characters counts the number of visual characters, and words counts the number of words.

Default value: length

threshold number

The character count threshold in percent at which to start displaying a warning.

Default value: 80

debounceDuration number

The debounce duration in milliseconds for updating the character count.

Default value: 1000

{% from "nationalarchives/components/textarea/macro.njk" import tnaTextarea %}

<div class="tna-container">
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    {{ tnaTextarea({
      label: "Enter text (length)",
      id: "input1",
      name: "input1",
      value: "I ❤️ design",
      rows: 2,
      characterCount: {
        max: 100,
        debounceDuration: 100
      }
    }) }}
  </div>
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    {{ tnaTextarea({
      label: "Enter text (characters)",
      id: "input2",
      name: "input2",
      value: "I ❤️ design",
      rows: 2,
      characterCount: {
        max: 100,
        countType : "characters",
        debounceDuration: 100
      }
    }) }}
  </div>
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    {{ tnaTextarea({
      label: "Enter text (words)",
      id: "input3",
      name: "input3",
      value: "I ❤️ design",
      rows: 2,
      characterCount: {
        max: 10,
        countType : "words",
        debounceDuration: 100
      }
    }) }}
  </div>
</div>

<script>
  const inputs = [
    document.getElementById("input1"),
    document.getElementById("input2"),
    document.getElementById("input3")
  ];
  const update = (event) => {
    inputs
      .filter(input => input !== event.target)
      .forEach(input => {
        input.value = event.target.value;
        input.dispatchEvent(new Event("focus"));
      })
  }
  inputs.forEach(input => {
    input.addEventListener("input", update);
  });
</script>

Jinja

Important information

This is an experimental feature showing a Jinja2 macro based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/textarea/macro.html" import tnaTextarea %}

<div class="tna-container">
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    {{ tnaTextarea({
      "label": "Enter text (length)",
      "id": "input1",
      "name": "input1",
      "value": "I ❤️ design",
      "rows": 2,
      "characterCount": {
        "max": 100,
        "debounceDuration": 100
      }
    }) }}
  </div>
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    {{ tnaTextarea({
      "label": "Enter text (characters)",
      "id": "input2",
      "name": "input2",
      "value": "I ❤️ design",
      "rows": 2,
      "characterCount": {
        "max": 100,
        countType : "characters",
        "debounceDuration": 100
      }
    }) }}
  </div>
  <div class="tna-column tna-column--width-1-3 tna-column--full-small tna-column--full-tiny tna-!--margin-vertical-m">
    {{ tnaTextarea({
      "label": "Enter text (words)",
      "id": "input3",
      "name": "input3",
      "value": "I ❤️ design",
      "rows": 2,
      "characterCount": {
        "max": 10,
        countType : "words",
        "debounceDuration": 100
      }
    }) }}
  </div>
</div>

<script>
  const inputs = [
    document.getElementById("input1"),
    document.getElementById("input2"),
    document.getElementById("input3")
  ];
  const update = (event) => {
    inputs
      .filter(input => input !== event.target)
      .forEach(input => {
        input.value = event.target.value;
        input.dispatchEvent(new Event("focus"));
      })
  }
  inputs.forEach(input => {
    input.addEventListener("input", update);
  });
</script>

Keep in mind:

Important information

This component feature is still in the experimental phase.

Allow users to enter a number of values into a field with the itemised textarea. This component does not feature autocomplete.

Without JavaScript, this renders a normal <textarea> where values can be separated by line breaks.

Open this example in new tab

Contents

HTML

<div class="tna-form-item">
  <div class="tna-form-item__header">
    <label class="tna-form-item__label tna-heading-m" for="series-no-js">
      Search series (without JavaScript)
    </label>
  </div>
  <p id="series-no-js-hint" class="tna-form-item__hint">
    Enter each series on a separate line
  </p>
  <div class="tna-form-item__body">
    <textarea id="series-no-js" class="tna-textarea" name="series-no-js" spellcheck="false" autocapitalize="off" autocorrect="off" rows="5" aria-describedby="series-no-js-hint  ">   Series 1
   
Series 2   
   Series 3   </textarea>
  </div>
</div>
<div class="tna-form-item" data-module="tna-textarea-itemised-rows" data-enhanced-hint="Enter a series and press enter">
  <div class="tna-form-item__header">
    <label class="tna-form-item__label tna-heading-m" for="series">
      Search series (with JavaScript)
    </label>
  </div>
  <p id="series-hint" class="tna-form-item__hint">
    Enter each series on a separate line
  </p>
  <div class="tna-form-item__body">
    <textarea id="series" class="tna-textarea" name="series" spellcheck="false" autocapitalize="off" autocorrect="off" rows="5" aria-describedby="series-hint  ">   Series 1
   
Series 2   
   Series 3   </textarea>
  </div>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

Required.

The label for the textarea field.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the textarea title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the textarea component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

value string

The form field value.

error object

If set, the details of any errors.

See macro options for error.

characterCount object

Configuration for the character count feature. Can not be used with itemiseRows.

See macro options for characterCount.

spellcheck boolean

If true, enable spellcheck for the text input.

Default value: false

autocapitalize string

If true, enable automatic capitalization for the text input. This is not supported in all browsers.

Default value: off

autocorrect boolean

If true, enable autocorrect for the text input. This is not supported in all browsers.

Default value: false

size string

Set the width of the textarea. Can be m, l or xl.

rows number

Set the number of visible text lines for the textarea. A scrollbar will appear if the content exceeds the height.

Default value: 5

itemiseRows boolean

If true, when JavaScript is available, parse each row of the textarea content into a list of items. Ignored if characterCount is enabled.

Default value: false

formItemClasses string

Classes to add to the textarea form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the textarea form group.

classes string

Classes to add to the textarea.

attributes object

HTML attributes (for example data attributes) to add to the textarea.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for characterCount
Name Type Description
max number

Required.

The maximum number of characters (or words if countType is set to words).

countType string

The type of character count to display. Can be length, characters or words. length counts the number of raw characters used, characters counts the number of visual characters, and words counts the number of words.

Default value: length

threshold number

The character count threshold in percent at which to start displaying a warning.

Default value: 80

debounceDuration number

The debounce duration in milliseconds for updating the character count.

Default value: 1000

{% from "nationalarchives/components/textarea/macro.njk" import tnaTextarea %}

{{ tnaTextarea({
  label: "Search series (without JavaScript)",
  hint: "Enter each series on a separate line",
  id: "series-no-js",
  name: "series-no-js",
  value: "   Series 1\n   \nSeries 2   \n   Series 3   "
}) }}

{{ tnaTextarea({
  label: "Search series (with JavaScript)",
  hint: "Enter each series on a separate line",
  id: "series",
  name: "series",
  value: "   Series 1\n   \nSeries 2   \n   Series 3   ",
  itemiseRows: true,
  formItemAttributes: {
    "data-enhanced-hint": "Enter a series and press enter"
  }
}) }}

Jinja

Important information

This is an experimental feature showing a Jinja2 macro based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/textarea/macro.html" import tnaTextarea %}

{{ tnaTextarea({
  "label": "Search series (without JavaScript)",
  "hint": "Enter each series on a separate line",
  "id": "series-no-js",
  "name": "series-no-js",
  "value": "   Series 1\n   \nSeries 2   \n   Series 3   "
}) }}

{{ tnaTextarea({
  "label": "Search series (with JavaScript)",
  "hint": "Enter each series on a separate line",
  "id": "series",
  "name": "series",
  "value": "   Series 1\n   \nSeries 2   \n   Series 3   ",
  "itemiseRows": True,
  "formItemAttributes": {
    "data-enhanced-hint": "Enter a series and press enter"
  }
}) }}
Tested without CSS
Yes
Passed DAC audit
Not yet audied

Something not right?

We are working to improve this service and appreciate your input.