Components Textarea The textarea component (also known as multiline input) is used for input fields longer than a single line.
Example Interact with the example to see how it works.
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import TextareaBlock from "@govtnz/ds/build/mustache/TextareaBlock.mustache";
// The variables TextareaBlock are all strings that are mustache templates.
export default `${Mustache.render(TextareaBlock, {
id: `detail`,
name: `detail`,
label: `Can you provide more detail?`,
hintId: `hint1`,
hint: `Do not include personal or financial information, like your IRD number or credit card details.`
})}`;
React (JavaScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-js/TextareaBlock";
import "@govtnz/ds/build/css/TextareaBlock.css"; // or @govtnz/ds/build/scss/TextareaBlock.scss
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
/>
);
React (TypeScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-ts/TextareaBlock";
import "@govtnz/ds/build/css/TextareaBlock.css"; // or @govtnz/ds/build/scss/TextareaBlock.scss
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
/>
);
React with Styled Components (JavaScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-js-styled-components/TextareaBlock";
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
/>
);
React with Styled Components (TypeScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-ts-styled-components/TextareaBlock";
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
/>
);
Vue (JavaScript) <template>
<textarea-block
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
/>
</template>
<script>
import Vue from "vue";
import TextareaBlock from "@govtnz/ds/build/vue-js/TextareaBlock.vue";
export default { components: { "textarea-block": TextareaBlock } };
</script>
Vue (TypeScript) <template>
<textarea-block
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
/>
</template>
<script lang="ts">
import Vue from "vue";
import TextareaBlock from "@govtnz/ds/build/vue-ts/TextareaBlock.vue";
export default { components: { "textarea-block": TextareaBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: TextareaBlock.css
OR in Sass (SCSS): TextareaBlock.scss
-->
<div class="g-textareaBlock-form-group">
<label class="g-textareaBlock-label" for="detail">
Can you provide more detail?
</label>
<div class="g-textareaBlock-hint" id="hint1">
Do not include personal or financial information, like your IRD number or
credit card details.
</div>
<textarea
class="g-textareaBlock-textarea"
id="detail"
name="detail"
aria-describedby="hint1"
>
</textarea>
</div>
twig-embed {% embed "TextareaBlock.html.twig" with {'id':'detail', 'name':'detail', 'label':'Can you provide more detail?', 'hintId':'hint1', 'hint':'Do not include personal or financial information, like your IRD number or credit card details.'} only %}{% endembed %}
When to use this component Use the textarea component when you need to let users enter an amount of text that’s longer than a single line.
When not to use this component Users can find open-ended questions difficult to answer. It might be better to break up one complex open question into a series of simple ones.
Ask a simple closed question If you need to let users select a single answer from a list of options, use radio buttons . For selecting one or more options, or to toggle a single option on or off, use checkboxes .
Ask a simple open question If you need to let users enter shorter answers no longer than a single line, such as a phone number or name, use the text input component.
How it works Label textareas You must label textareas. Placeholder text is not a suitable substitute for a label, as it may disappear when users click inside the textarea.
Labels must be aligned above the textarea they refer to. They should be short, direct and written in sentence case. Do not use colons at the end of labels.
Use appropriately-sized textareas Make the height of a textarea proportional to the amount of text you expect users to enter. You can set the height of a textarea by by specifying the rows
attribute.
Allow users to resize the textarea by dragging the resize handle icon in the bottom-right corner of the textarea.
Do not disable copy and paste Users will often need to copy and paste information into a textarea, so do not stop them from doing this.
Error messages Error messages should be styled like this:
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import TextareaBlock from "@govtnz/ds/build/mustache/TextareaBlock.mustache";
// The variables TextareaBlock are all strings that are mustache templates.
export default `${Mustache.render(TextareaBlock, {
id: `detail`,
name: `detail`,
label: `Can you provide more detail?`,
hintId: `hint1`,
hint: `Do not include personal or financial information, like your IRD number or credit card details.`,
errorId: true,
error: `Enter more detail`
})}`;
React (JavaScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-js/TextareaBlock";
import "@govtnz/ds/build/css/TextareaBlock.css"; // or @govtnz/ds/build/scss/TextareaBlock.scss
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
errorId="errorId"
error="Enter more detail"
/>
);
React (TypeScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-ts/TextareaBlock";
import "@govtnz/ds/build/css/TextareaBlock.css"; // or @govtnz/ds/build/scss/TextareaBlock.scss
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
errorId="errorId"
error="Enter more detail"
/>
);
React with Styled Components (JavaScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-js-styled-components/TextareaBlock";
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
errorId="errorId"
error="Enter more detail"
/>
);
React with Styled Components (TypeScript) import React from "react";
import TextareaBlock from "@govtnz/ds/build/react-ts-styled-components/TextareaBlock";
export default () => (
<TextareaBlock
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
errorId="errorId"
error="Enter more detail"
/>
);
Vue (JavaScript) <template>
<textarea-block
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
errorId="errorId"
error="Enter more detail"
/>
</template>
<script>
import Vue from "vue";
import TextareaBlock from "@govtnz/ds/build/vue-js/TextareaBlock.vue";
export default { components: { "textarea-block": TextareaBlock } };
</script>
Vue (TypeScript) <template>
<textarea-block
id="detail"
name="detail"
label="Can you provide more detail?"
hintId="hint1"
hint="Do not include personal or financial information, like your IRD number or credit card details."
errorId="errorId"
error="Enter more detail"
/>
</template>
<script lang="ts">
import Vue from "vue";
import TextareaBlock from "@govtnz/ds/build/vue-ts/TextareaBlock.vue";
export default { components: { "textarea-block": TextareaBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: TextareaBlock.css
OR in Sass (SCSS): TextareaBlock.scss
-->
<div class="g-textareaBlock-form-group">
<label class="g-textareaBlock-label" for="detail">
Can you provide more detail?
</label>
<div class="g-textareaBlock-hint" id="hint1">
Do not include personal or financial information, like your IRD number or
credit card details.
</div>
<div class="g-textareaBlock-error-message" id="errorId">
<span class="g-textareaBlock-visually-hidden"> Error: </span> Enter more
detail
</div>
<textarea
class="g-textareaBlock-textarea"
id="detail"
name="detail"
aria-describedby="hint1 errorId"
>
</textarea>
</div>
twig-embed {% embed "TextareaBlock.html.twig" with {'id':'detail', 'name':'detail', 'label':'Can you provide more detail?', 'hintId':'hint1', 'hint':'Do not include personal or financial information, like your IRD number or credit card details.', 'errorId':'errorId', 'error':'Enter more detail'} only %}{% endembed %}
Make sure error messages follow the guidance below, and that you have specific error messages for specific error states.
Say ‘Enter [whatever it is]’.
For example, ‘Enter summary’.
Say ‘[whatever it is] must be [number] characters or fewer’.
For example, ‘Summary must be 400 characters or fewer’.
Say ‘[whatever it is] must be [number] characters or more’.
For example, ‘Summary must be 10 characters or more’.
Say ‘[whatever it is] must be between [number] and [number] characters’.
For example, ‘Summary must be between 10 and 400 characters’.
Say ‘[whatever it is] must not include [characters]’.
For example, ‘Summary must not include ē and $’.
Say ‘[whatever it is] must only include [list of allowed characters]’.
For example, ‘Summary must only include letters a to z, hyphens, spaces and apostrophes.’
Credit Guidance, original HTML and CSS derived from GOV.UK Design System .
Get in touch If you’ve got a question, idea, or suggestion, email the Design System (DS) team at info@digital.govt.nz , use our NZGDS Slack app , or discuss Textarea on 'GitHub issues'.