Components Text input Text inputs allow users to enter any combination of letters, numbers, or symbols to answer questions and provide data.
Examples Interact with each 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 InputBlock from "@govtnz/ds/build/mustache/InputBlock.mustache";
// The variables InputBlock are all strings that are mustache templates.
export default `${Mustache.render(InputBlock, {
type: `text`,
label: `Event name`,
name: `anyName`,
id: `anyId`
})}`;
React (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock type="text" label="Event name" name="anyName" id="anyId" />
);
React (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock type="text" label="Event name" name="anyName" id="anyId" />
);
React with Styled Components (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js-styled-components/InputBlock";
export default () => (
<InputBlock type="text" label="Event name" name="anyName" id="anyId" />
);
React with Styled Components (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts-styled-components/InputBlock";
export default () => (
<InputBlock type="text" label="Event name" name="anyName" id="anyId" />
);
Vue (JavaScript) <template>
<input-block type="text" label="Event name" name="anyName" id="anyId" />
</template>
<script>
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-js/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
Vue (TypeScript) <template>
<input-block type="text" label="Event name" name="anyName" id="anyId" />
</template>
<script lang="ts">
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-ts/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: InputBlock.css
OR in Sass (SCSS): InputBlock.scss
-->
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId"> Event name </label>
<input class="g-inputBlock-input" id="anyId" name="anyName" type="text" />
</div>
twig-embed {% embed "InputBlock.html.twig" with {'type':'text', 'label':'Event name', 'name':'anyName', 'id':'anyId'} only %}{% endembed %}
Error state
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 InputBlock from "@govtnz/ds/build/mustache/InputBlock.mustache";
// The variables InputBlock are all strings that are mustache templates.
export default `${Mustache.render(InputBlock, {
type: `text`,
label: `Event name`,
name: `anyName`,
id: `anyId2f`,
errorId: true,
error: `Enter a known event name`
})}`;
React (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId2f"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
React (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId2f"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
React with Styled Components (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js-styled-components/InputBlock";
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId2f"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
React with Styled Components (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts-styled-components/InputBlock";
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId2f"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
Vue (JavaScript) <template>
<input-block
type="text"
label="Event name"
name="anyName"
id="anyId2f"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
</template>
<script>
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-js/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
Vue (TypeScript) <template>
<input-block
type="text"
label="Event name"
name="anyName"
id="anyId2f"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
</template>
<script lang="ts">
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-ts/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: InputBlock.css
OR in Sass (SCSS): InputBlock.scss
-->
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId2f"> Event name </label>
<div class="g-inputBlock-error-message" id="anyErrorId2Error">
<span class="g-inputBlock-visually-hidden"> Error: </span> Enter a known
event name
</div>
<input
class="g-inputBlock-input"
id="anyId2f"
name="anyName"
aria-describedby="anyErrorId2Error"
type="text"
/>
</div>
twig-embed {% embed "InputBlock.html.twig" with {'type':'text', 'label':'Event name', 'name':'anyName', 'id':'anyId2f', 'errorId':'anyErrorId2Error', 'error':'Enter a known event name'} only %}{% endembed %}
When to use it Use the text input component for single line answers, such as a user’s name or phone number.
When not to use it If you expect multiple line answers from users, do not use the text input component. Use the textarea
component instead (currently under development).
How it works Text input components need be clearly labelled, sized for the answer you require, and provided with any hints the user needs to complete them successfully.
Label text inputs All text inputs must have visible labels. Placeholder text is not an acceptable replacement for a label because it vanishes when users start typing.
Labels should be aligned above the text input they refer to. They should be short, direct, and written in sentence case. Do not use colons at the end of labels.
If you’re asking just one question per page, you can put the <label>
inside the page heading. This is good practice, as it means that users of screen readers will only hear the contents once.
Use appropriately-sized text inputs Help users understand what they should enter by making each text input box the right size for the content it’s intended for.
By default, the width of text inputs in the design system is fluid and will fit the full width of the container they are placed into.
If you want to make the input smaller, you can either use a fixed-width input, or use the width override classes to create a smaller fluid-width input.
Fixed-width text input
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 InputBlock from "@govtnz/ds/build/mustache/InputBlock.mustache";
// The variables InputBlock are all strings that are mustache templates.
export default `${Mustache.render(InputBlock, {
width: `30`,
label: `30 character width`,
hint: `Fits a short sentence answer or a long address line.`,
name: `anyNameWidth30`,
id: `anyId3`,
maxLength: `30`,
hintId: `anyHintId3`
})}${Mustache.render(InputBlock, {
type: `email`,
width: `20`,
label: `20 character width`,
hint: `Fits an email address.`,
name: `anyNameWidth20`,
id: `anyId4`,
hintId: `anyHintId4`,
maxLength: `20`
})}${Mustache.render(InputBlock, {
width: `10`,
label: `10 character width`,
hint: `Fits a name.`,
name: `anyNameWidth10`,
id: `anyId5`,
hintId: `anyHintId5`,
maxLength: `10`
})}${Mustache.render(InputBlock, {
width: `5`,
label: `5 character width`,
hint: `Fits a post code.`,
name: `anyNameWidth5`,
id: `anyId6`,
hintId: `anyHintId6`,
maxLength: `5`
})}${Mustache.render(InputBlock, {
width: `4`,
label: `4 character width`,
hint: `Fits a 4-digit group of a credit card number.`,
name: `anyNameWidth4`,
id: `anyId7`,
hintId: `anyHintId7`,
maxLength: `4`
})}${Mustache.render(InputBlock, {
width: `3`,
label: `3 character width`,
hint: `Fits a prefix for a mobile number.`,
name: `anyNameWidth3`,
id: `anyId8`,
hintId: `anyHintId8`,
maxLength: `3`
})}${Mustache.render(InputBlock, {
width: `2`,
label: `2 character width`,
hint: `Fits the 2-digit part of a bank account number.`,
name: `anyNameWidth2`,
id: `anyId9`,
hintId: `anyHintId9`,
maxLength: `2`
})}`;
React (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<React.Fragment>
<InputBlock
width="30"
label="30 character width"
hint="Fits a short sentence answer or a long address line."
name="anyNameWidth30"
id="anyId3"
maxLength="30"
hintId="anyHintId3"
/>
<InputBlock
type="email"
width="20"
label="20 character width"
hint="Fits an email address."
name="anyNameWidth20"
id="anyId4"
hintId="anyHintId4"
maxLength="20"
/>
<InputBlock
width="10"
label="10 character width"
hint="Fits a name."
name="anyNameWidth10"
id="anyId5"
hintId="anyHintId5"
maxLength="10"
/>
<InputBlock
width="5"
label="5 character width"
hint="Fits a post code."
name="anyNameWidth5"
id="anyId6"
hintId="anyHintId6"
maxLength="5"
/>
<InputBlock
width="4"
label="4 character width"
hint="Fits a 4-digit group of a credit card number."
name="anyNameWidth4"
id="anyId7"
hintId="anyHintId7"
maxLength="4"
/>
<InputBlock
width="3"
label="3 character width"
hint="Fits a prefix for a mobile number."
name="anyNameWidth3"
id="anyId8"
hintId="anyHintId8"
maxLength="3"
/>
<InputBlock
width="2"
label="2 character width"
hint="Fits the 2-digit part of a bank account number."
name="anyNameWidth2"
id="anyId9"
hintId="anyHintId9"
maxLength="2"
/>
</React.Fragment>
);
React (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<React.Fragment>
<InputBlock
width="30"
label="30 character width"
hint="Fits a short sentence answer or a long address line."
name="anyNameWidth30"
id="anyId3"
maxLength="30"
hintId="anyHintId3"
/>
<InputBlock
type="email"
width="20"
label="20 character width"
hint="Fits an email address."
name="anyNameWidth20"
id="anyId4"
hintId="anyHintId4"
maxLength="20"
/>
<InputBlock
width="10"
label="10 character width"
hint="Fits a name."
name="anyNameWidth10"
id="anyId5"
hintId="anyHintId5"
maxLength="10"
/>
<InputBlock
width="5"
label="5 character width"
hint="Fits a post code."
name="anyNameWidth5"
id="anyId6"
hintId="anyHintId6"
maxLength="5"
/>
<InputBlock
width="4"
label="4 character width"
hint="Fits a 4-digit group of a credit card number."
name="anyNameWidth4"
id="anyId7"
hintId="anyHintId7"
maxLength="4"
/>
<InputBlock
width="3"
label="3 character width"
hint="Fits a prefix for a mobile number."
name="anyNameWidth3"
id="anyId8"
hintId="anyHintId8"
maxLength="3"
/>
<InputBlock
width="2"
label="2 character width"
hint="Fits the 2-digit part of a bank account number."
name="anyNameWidth2"
id="anyId9"
hintId="anyHintId9"
maxLength="2"
/>
</React.Fragment>
);
React with Styled Components (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js-styled-components/InputBlock";
export default () => (
<React.Fragment>
<InputBlock
width="30"
label="30 character width"
hint="Fits a short sentence answer or a long address line."
name="anyNameWidth30"
id="anyId3"
maxLength="30"
hintId="anyHintId3"
/>
<InputBlock
type="email"
width="20"
label="20 character width"
hint="Fits an email address."
name="anyNameWidth20"
id="anyId4"
hintId="anyHintId4"
maxLength="20"
/>
<InputBlock
width="10"
label="10 character width"
hint="Fits a name."
name="anyNameWidth10"
id="anyId5"
hintId="anyHintId5"
maxLength="10"
/>
<InputBlock
width="5"
label="5 character width"
hint="Fits a post code."
name="anyNameWidth5"
id="anyId6"
hintId="anyHintId6"
maxLength="5"
/>
<InputBlock
width="4"
label="4 character width"
hint="Fits a 4-digit group of a credit card number."
name="anyNameWidth4"
id="anyId7"
hintId="anyHintId7"
maxLength="4"
/>
<InputBlock
width="3"
label="3 character width"
hint="Fits a prefix for a mobile number."
name="anyNameWidth3"
id="anyId8"
hintId="anyHintId8"
maxLength="3"
/>
<InputBlock
width="2"
label="2 character width"
hint="Fits the 2-digit part of a bank account number."
name="anyNameWidth2"
id="anyId9"
hintId="anyHintId9"
maxLength="2"
/>
</React.Fragment>
);
React with Styled Components (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts-styled-components/InputBlock";
export default () => (
<React.Fragment>
<InputBlock
width="30"
label="30 character width"
hint="Fits a short sentence answer or a long address line."
name="anyNameWidth30"
id="anyId3"
maxLength="30"
hintId="anyHintId3"
/>
<InputBlock
type="email"
width="20"
label="20 character width"
hint="Fits an email address."
name="anyNameWidth20"
id="anyId4"
hintId="anyHintId4"
maxLength="20"
/>
<InputBlock
width="10"
label="10 character width"
hint="Fits a name."
name="anyNameWidth10"
id="anyId5"
hintId="anyHintId5"
maxLength="10"
/>
<InputBlock
width="5"
label="5 character width"
hint="Fits a post code."
name="anyNameWidth5"
id="anyId6"
hintId="anyHintId6"
maxLength="5"
/>
<InputBlock
width="4"
label="4 character width"
hint="Fits a 4-digit group of a credit card number."
name="anyNameWidth4"
id="anyId7"
hintId="anyHintId7"
maxLength="4"
/>
<InputBlock
width="3"
label="3 character width"
hint="Fits a prefix for a mobile number."
name="anyNameWidth3"
id="anyId8"
hintId="anyHintId8"
maxLength="3"
/>
<InputBlock
width="2"
label="2 character width"
hint="Fits the 2-digit part of a bank account number."
name="anyNameWidth2"
id="anyId9"
hintId="anyHintId9"
maxLength="2"
/>
</React.Fragment>
);
Vue (JavaScript) <template>
<input-block
width="30"
label="30 character width"
hint="Fits a short sentence answer or a long address line."
name="anyNameWidth30"
id="anyId3"
maxLength="30"
hintId="anyHintId3"
/>
<input-block
type="email"
width="20"
label="20 character width"
hint="Fits an email address."
name="anyNameWidth20"
id="anyId4"
hintId="anyHintId4"
maxLength="20"
/>
<input-block
width="10"
label="10 character width"
hint="Fits a name."
name="anyNameWidth10"
id="anyId5"
hintId="anyHintId5"
maxLength="10"
/>
<input-block
width="5"
label="5 character width"
hint="Fits a post code."
name="anyNameWidth5"
id="anyId6"
hintId="anyHintId6"
maxLength="5"
/>
<input-block
width="4"
label="4 character width"
hint="Fits a 4-digit group of a credit card number."
name="anyNameWidth4"
id="anyId7"
hintId="anyHintId7"
maxLength="4"
/>
<input-block
width="3"
label="3 character width"
hint="Fits a prefix for a mobile number."
name="anyNameWidth3"
id="anyId8"
hintId="anyHintId8"
maxLength="3"
/>
<input-block
width="2"
label="2 character width"
hint="Fits the 2-digit part of a bank account number."
name="anyNameWidth2"
id="anyId9"
hintId="anyHintId9"
maxLength="2"
/>
</template>
<script>
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-js/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
Vue (TypeScript) <template>
<input-block
width="30"
label="30 character width"
hint="Fits a short sentence answer or a long address line."
name="anyNameWidth30"
id="anyId3"
maxLength="30"
hintId="anyHintId3"
/>
<input-block
type="email"
width="20"
label="20 character width"
hint="Fits an email address."
name="anyNameWidth20"
id="anyId4"
hintId="anyHintId4"
maxLength="20"
/>
<input-block
width="10"
label="10 character width"
hint="Fits a name."
name="anyNameWidth10"
id="anyId5"
hintId="anyHintId5"
maxLength="10"
/>
<input-block
width="5"
label="5 character width"
hint="Fits a post code."
name="anyNameWidth5"
id="anyId6"
hintId="anyHintId6"
maxLength="5"
/>
<input-block
width="4"
label="4 character width"
hint="Fits a 4-digit group of a credit card number."
name="anyNameWidth4"
id="anyId7"
hintId="anyHintId7"
maxLength="4"
/>
<input-block
width="3"
label="3 character width"
hint="Fits a prefix for a mobile number."
name="anyNameWidth3"
id="anyId8"
hintId="anyHintId8"
maxLength="3"
/>
<input-block
width="2"
label="2 character width"
hint="Fits the 2-digit part of a bank account number."
name="anyNameWidth2"
id="anyId9"
hintId="anyHintId9"
maxLength="2"
/>
</template>
<script lang="ts">
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-ts/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: InputBlock.css
OR in Sass (SCSS): InputBlock.scss
-->
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId3"> 30 character width </label>
<div class="g-inputBlock-hint" id="anyHintId3">
Fits a short sentence answer or a long address line.
</div>
<input
class="g-inputBlock-input g-inputBlock-input--width-30"
id="anyId3"
name="anyNameWidth30"
aria-describedby="anyHintId3"
maxlength="30"
/>
</div>
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId4"> 20 character width </label>
<div class="g-inputBlock-hint" id="anyHintId4">Fits an email address.</div>
<input
class="g-inputBlock-input g-inputBlock-input--width-20"
id="anyId4"
name="anyNameWidth20"
aria-describedby="anyHintId4"
type="email"
maxlength="20"
/>
</div>
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId5"> 10 character width </label>
<div class="g-inputBlock-hint" id="anyHintId5">Fits a name.</div>
<input
class="g-inputBlock-input g-inputBlock-input--width-10"
id="anyId5"
name="anyNameWidth10"
aria-describedby="anyHintId5"
maxlength="10"
/>
</div>
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId6"> 5 character width </label>
<div class="g-inputBlock-hint" id="anyHintId6">Fits a post code.</div>
<input
class="g-inputBlock-input g-inputBlock-input--width-5"
id="anyId6"
name="anyNameWidth5"
aria-describedby="anyHintId6"
maxlength="5"
/>
</div>
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId7"> 4 character width </label>
<div class="g-inputBlock-hint" id="anyHintId7">
Fits a 4-digit group of a credit card number.
</div>
<input
class="g-inputBlock-input g-inputBlock-input--width-4"
id="anyId7"
name="anyNameWidth4"
aria-describedby="anyHintId7"
maxlength="4"
/>
</div>
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId8"> 3 character width </label>
<div class="g-inputBlock-hint" id="anyHintId8">
Fits a prefix for a mobile number.
</div>
<input
class="g-inputBlock-input g-inputBlock-input--width-3"
id="anyId8"
name="anyNameWidth3"
aria-describedby="anyHintId8"
maxlength="3"
/>
</div>
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId9"> 2 character width </label>
<div class="g-inputBlock-hint" id="anyHintId9">
Fits the 2-digit part of a bank account number.
</div>
<input
class="g-inputBlock-input g-inputBlock-input--width-2"
id="anyId9"
name="anyNameWidth2"
aria-describedby="anyHintId9"
maxlength="2"
/>
</div>
twig-embed {% embed "InputBlock.html.twig" with {'width':'30', 'label':'30 character width', 'hint':'Fits a short sentence answer or a long address line.', 'name':'anyNameWidth30', 'id':'anyId3', 'maxLength':'30', 'hintId':'anyHintId3'} only %}{% endembed %}{% embed "InputBlock.html.twig" with {'type':'email', 'width':'20', 'label':'20 character width', 'hint':'Fits an email address.', 'name':'anyNameWidth20', 'id':'anyId4', 'hintId':'anyHintId4', 'maxLength':'20'} only %}{% endembed %}{% embed "InputBlock.html.twig" with {'width':'10', 'label':'10 character width', 'hint':'Fits a name.', 'name':'anyNameWidth10', 'id':'anyId5', 'hintId':'anyHintId5', 'maxLength':'10'} only %}{% endembed %}{% embed "InputBlock.html.twig" with {'width':'5', 'label':'5 character width', 'hint':'Fits a post code.', 'name':'anyNameWidth5', 'id':'anyId6', 'hintId':'anyHintId6', 'maxLength':'5'} only %}{% endembed %}{% embed "InputBlock.html.twig" with {'width':'4', 'label':'4 character width', 'hint':'Fits a 4-digit group of a credit card number.', 'name':'anyNameWidth4', 'id':'anyId7', 'hintId':'anyHintId7', 'maxLength':'4'} only %}{% endembed %}{% embed "InputBlock.html.twig" with {'width':'3', 'label':'3 character width', 'hint':'Fits a prefix for a mobile number.', 'name':'anyNameWidth3', 'id':'anyId8', 'hintId':'anyHintId8', 'maxLength':'3'} only %}{% endembed %}{% embed "InputBlock.html.twig" with {'width':'2', 'label':'2 character width', 'hint':'Fits the 2-digit part of a bank account number.', 'name':'anyNameWidth2', 'id':'anyId9', 'hintId':'anyHintId9', 'maxLength':'2'} only %}{% endembed %}
Use fixed-width inputs for content that has a specific, known length. For example, postcode inputs should be postcode-sized, and telephone number inputs should be telephone number-sized.
On fixed-width inputs, the width will remain fixed on all screens unless it is wider than the viewport, in which case it will shrink to fit.
Hint text
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 InputBlock from "@govtnz/ds/build/mustache/InputBlock.mustache";
// The variables InputBlock are all strings that are mustache templates.
export default `${Mustache.render(InputBlock, {
type: `text`,
label: `Event name`,
name: `anyName`,
id: `anyId10`,
hint: `The name you'll use on promotional material`,
hintId: `anyHintId10`
})}`;
React (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId10"
hint="The name you'll use on promotional material"
hintId="anyHintId10"
/>
);
React (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId10"
hint="The name you'll use on promotional material"
hintId="anyHintId10"
/>
);
React with Styled Components (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js-styled-components/InputBlock";
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId10"
hint="The name you'll use on promotional material"
hintId="anyHintId10"
/>
);
React with Styled Components (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts-styled-components/InputBlock";
export default () => (
<InputBlock
type="text"
label="Event name"
name="anyName"
id="anyId10"
hint="The name you'll use on promotional material"
hintId="anyHintId10"
/>
);
Vue (JavaScript) <template>
<input-block
type="text"
label="Event name"
name="anyName"
id="anyId10"
hint="The name you'll use on promotional material"
hintId="anyHintId10"
/>
</template>
<script>
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-js/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
Vue (TypeScript) <template>
<input-block
type="text"
label="Event name"
name="anyName"
id="anyId10"
hint="The name you'll use on promotional material"
hintId="anyHintId10"
/>
</template>
<script lang="ts">
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-ts/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: InputBlock.css
OR in Sass (SCSS): InputBlock.scss
-->
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId10"> Event name </label>
<div class="g-inputBlock-hint" id="anyHintId10">
The name you'll use on promotional material
</div>
<input
class="g-inputBlock-input"
id="anyId10"
name="anyName"
aria-describedby="anyHintId10"
type="text"
/>
</div>
twig-embed {% embed "InputBlock.html.twig" with {'type':'text', 'label':'Event name', 'name':'anyName', 'id':'anyId10', 'hint':'The name you'll use on promotional material', 'hintId':'anyHintId10'} only %}{% endembed %}
Use hint text (also known as help text) for advice that’s relevant to the majority of users, like how their information will be used, or where to find it.
Use the autocomplete
attribute Use the autocomplete
attribute on text inputs to help users complete forms more quickly. This lets you specify an input’s purpose so browsers can autofill the information on a user’s behalf if they’ve entered it previously.
For example, to enable autofill on a postcode field, set the autocomplete
attribute to postal-code
. If you are working in production and there is a relevant input purpose, you’ll need to use the autocomplete
attribute to meet Web Content Accessibility Guidelines (WCAG) 2.1 Level AA.
See how to do this in the following example.
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 InputBlock from "@govtnz/ds/build/mustache/InputBlock.mustache";
// The variables InputBlock are all strings that are mustache templates.
export default `${Mustache.render(InputBlock, {
label: `Your postal code`,
hint: `Your postal code will be a four digit number.`,
name: `postalCode`,
id: `postalId`,
hintId: `postalHintId`,
autoComplete: `postal-code`
})}`;
React (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
label="Your postal code"
hint="Your postal code will be a four digit number."
name="postalCode"
id="postalId"
hintId="postalHintId"
autoComplete="postal-code"
/>
);
React (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
label="Your postal code"
hint="Your postal code will be a four digit number."
name="postalCode"
id="postalId"
hintId="postalHintId"
autoComplete="postal-code"
/>
);
React with Styled Components (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js-styled-components/InputBlock";
export default () => (
<InputBlock
label="Your postal code"
hint="Your postal code will be a four digit number."
name="postalCode"
id="postalId"
hintId="postalHintId"
autoComplete="postal-code"
/>
);
React with Styled Components (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts-styled-components/InputBlock";
export default () => (
<InputBlock
label="Your postal code"
hint="Your postal code will be a four digit number."
name="postalCode"
id="postalId"
hintId="postalHintId"
autoComplete="postal-code"
/>
);
Vue (JavaScript) <template>
<input-block
label="Your postal code"
hint="Your postal code will be a four digit number."
name="postalCode"
id="postalId"
hintId="postalHintId"
autoComplete="postal-code"
/>
</template>
<script>
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-js/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
Vue (TypeScript) <template>
<input-block
label="Your postal code"
hint="Your postal code will be a four digit number."
name="postalCode"
id="postalId"
hintId="postalHintId"
autoComplete="postal-code"
/>
</template>
<script lang="ts">
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-ts/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: InputBlock.css
OR in Sass (SCSS): InputBlock.scss
-->
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="postalId"> Your postal code </label>
<div class="g-inputBlock-hint" id="postalHintId">
Your postal code will be a four digit number.
</div>
<input
class="g-inputBlock-input"
id="postalId"
name="postalCode"
aria-describedby="postalHintId"
autocomplete="postal-code"
/>
</div>
twig-embed {% embed "InputBlock.html.twig" with {'label':'Your postal code', 'hint':'Your postal code will be a four digit number.', 'name':'postalCode', 'id':'postalId', 'hintId':'postalHintId', 'autoComplete':'postal-code'} only %}{% endembed %}
Do not disable copy and paste Users often need to copy and paste information into a text input, so do not stop them from doing this.
Sometimes browsers will spellcheck the information a user puts into a text input. If a user enters something that is recognised as a spelling error, sighted users will see a red line under the word.
If you are asking users for information that's not appropriate to spellcheck, like a reference number, name, or email address, disable the spellcheck.
To disable spellcheck, set spellcheck="false"
.
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 InputBlock from "@govtnz/ds/build/mustache/InputBlock.mustache";
// The variables InputBlock are all strings that are mustache templates.
export default `${Mustache.render(InputBlock, {
type: `email`,
label: `Your email address`,
hint: `Please provide your personal email address that we'll contact you on.`,
name: `someEmail`,
id: `anyId122`,
hintId: `anyHintId122`,
spellCheck: `false`
})}`;
React (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="email"
label="Your email address"
hint="Please provide your personal email address that we'll contact you on."
name="someEmail"
id="anyId122"
hintId="anyHintId122"
spellCheck="false"
/>
);
React (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="email"
label="Your email address"
hint="Please provide your personal email address that we'll contact you on."
name="someEmail"
id="anyId122"
hintId="anyHintId122"
spellCheck="false"
/>
);
React with Styled Components (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js-styled-components/InputBlock";
export default () => (
<InputBlock
type="email"
label="Your email address"
hint="Please provide your personal email address that we'll contact you on."
name="someEmail"
id="anyId122"
hintId="anyHintId122"
spellCheck="false"
/>
);
React with Styled Components (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts-styled-components/InputBlock";
export default () => (
<InputBlock
type="email"
label="Your email address"
hint="Please provide your personal email address that we'll contact you on."
name="someEmail"
id="anyId122"
hintId="anyHintId122"
spellCheck="false"
/>
);
Vue (JavaScript) <template>
<input-block
type="email"
label="Your email address"
hint="Please provide your personal email address that we'll contact you on."
name="someEmail"
id="anyId122"
hintId="anyHintId122"
spellCheck="false"
/>
</template>
<script>
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-js/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
Vue (TypeScript) <template>
<input-block
type="email"
label="Your email address"
hint="Please provide your personal email address that we'll contact you on."
name="someEmail"
id="anyId122"
hintId="anyHintId122"
spellCheck="false"
/>
</template>
<script lang="ts">
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-ts/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: InputBlock.css
OR in Sass (SCSS): InputBlock.scss
-->
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId122"> Your email address </label>
<div class="g-inputBlock-hint" id="anyHintId122">
Please provide your personal email address that we'll contact you on.
</div>
<input
class="g-inputBlock-input"
id="anyId122"
name="someEmail"
aria-describedby="anyHintId122"
type="email"
spellcheck="false"
/>
</div>
twig-embed {% embed "InputBlock.html.twig" with {'type':'email', 'label':'Your email address', 'hint':'Please provide your personal email address that we'll contact you on.', 'name':'someEmail', 'id':'anyId122', 'hintId':'anyHintId122', 'spellCheck':'false'} only %}{% endembed %}
Browsers do not consistently spellcheck users’ input by default. If you are asking users a question for which spellcheck would be useful, set the spellcheck
attribute to true
.
Disabled text inputs Disabled input elements cannot be clicked by users. You can use them to prevent users from interacting with a specific input until another action is completed.
However, disabled input elements can confuse users so they are best avoided, if possible.
Error messages Style error messages as shown in the following example.
Error state
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 InputBlock from "@govtnz/ds/build/mustache/InputBlock.mustache";
// The variables InputBlock are all strings that are mustache templates.
export default `${Mustache.render(InputBlock, {
type: `text`,
label: `Event name`,
hint: `The name you'll use on promotional material`,
name: `anyName`,
id: `anyId2f`,
hintId: `anyHintId2`,
errorId: true,
error: `Enter a known event name`
})}`;
React (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="text"
label="Event name"
hint="The name you'll use on promotional material"
name="anyName"
id="anyId2f"
hintId="anyHintId2"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
React (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts/InputBlock";
import "@govtnz/ds/build/css/InputBlock.css"; // or @govtnz/ds/build/scss/InputBlock.scss
export default () => (
<InputBlock
type="text"
label="Event name"
hint="The name you'll use on promotional material"
name="anyName"
id="anyId2f"
hintId="anyHintId2"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
React with Styled Components (JavaScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-js-styled-components/InputBlock";
export default () => (
<InputBlock
type="text"
label="Event name"
hint="The name you'll use on promotional material"
name="anyName"
id="anyId2f"
hintId="anyHintId2"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
React with Styled Components (TypeScript) import React from "react";
import InputBlock from "@govtnz/ds/build/react-ts-styled-components/InputBlock";
export default () => (
<InputBlock
type="text"
label="Event name"
hint="The name you'll use on promotional material"
name="anyName"
id="anyId2f"
hintId="anyHintId2"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
);
Vue (JavaScript) <template>
<input-block
type="text"
label="Event name"
hint="The name you'll use on promotional material"
name="anyName"
id="anyId2f"
hintId="anyHintId2"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
</template>
<script>
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-js/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
Vue (TypeScript) <template>
<input-block
type="text"
label="Event name"
hint="The name you'll use on promotional material"
name="anyName"
id="anyId2f"
hintId="anyHintId2"
errorId="anyErrorId2Error"
error="Enter a known event name"
/>
</template>
<script lang="ts">
import Vue from "vue";
import InputBlock from "@govtnz/ds/build/vue-ts/InputBlock.vue";
export default { components: { "input-block": InputBlock } };
</script>
HTML <!--
Remember to add these styles:
in CSS: InputBlock.css
OR in Sass (SCSS): InputBlock.scss
-->
<div class="g-inputBlock-form-group">
<label class="g-inputBlock-label" for="anyId2f"> Event name </label>
<div class="g-inputBlock-hint" id="anyHintId2">
The name you'll use on promotional material
</div>
<div class="g-inputBlock-error-message" id="anyErrorId2Error">
<span class="g-inputBlock-visually-hidden"> Error: </span> Enter a known
event name
</div>
<input
class="g-inputBlock-input"
id="anyId2f"
name="anyName"
aria-describedby="anyHintId2 anyErrorId2Error"
type="text"
/>
</div>
twig-embed {% embed "InputBlock.html.twig" with {'type':'text', 'label':'Event name', 'hint':'The name you'll use on promotional material', 'name':'anyName', 'id':'anyId2f', 'hintId':'anyHintId2', 'errorId':'anyErrorId2Error', 'error':'Enter a known event name'} 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 your first name’.
Say ‘[whatever it is] must be [number] characters or less’. For example, ‘Address line 1 must have 35 characters or less’.
Say ‘[whatever it is] must be [number] characters or more’. For example, ‘Full name must be 2 characters or more’.
Say ‘[whatever it is] must be between [number] and [number] characters’. For example, ‘Last name must be between 2 and 35 characters’.
Say ‘[whatever it is] must not include [characters]’. For example, ‘Town or city must not include è and $’.
Say ‘[whatever it is] must only include [list of allowed characters]’. For example, ‘Full name must only include letters a to z, hyphens, spaces and apostrophes’.
Say ‘[whatever it is] must be a number [optional example]’. For example, ‘Hours worked a week must be a number, like 30’.
Say ‘[whatever it is] must be a whole number [optional example]’. For example, ‘Hours worked a week must be a whole number, like 30’.
If the number is too low Say ‘[whatever it is] must be [lowest] or more’. For example, ‘Hours worked a week must be 16 or more’.
If the number is too high Say ‘[whatever it is] must be [highest] or less’. For example, ‘Hours worked a week must be 99 or less’.
Say ‘[whatever it is] must be between [lowest] and [highest]’. For example, ‘Hours worked a week must be between 16 and 99’.
Say ‘[whatever it is] must be an amount of money [optional example that includes decimals and non-decimals]’. For example, ‘How much you earn an hour must be an amount of money, like 7.50 or 8’.
Say ‘[whatever it is] must be an amount of money [optional example that includes decimals]’. For example, ‘How much you earn an hour must be an amount of money, like 7.50 or 8.00’.
Say ‘[whatever it is] must include cents, like 123.45 or 156.00’. For example, ‘How much you earn a week must include cents, like 123.45 or 156.00’.
Say ‘[whatever it is] must not include cents, like 123 or 156’. For example, ‘How much you earn a week must not include cents, like 123 or 156’.
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 Text input on 'GitHub issues'.