Components
Text input
The text input component allows users to enter short string of text such as their email address, a record title or a postcode.
Contents
HTML
<div class="tna-form-item">
<div class="tna-form-item__header">
<label class="tna-form-item__label tna-heading-m" for="firstname">
Enter your first name
</label>
</div>
<div class="tna-form-item__body">
<input id="firstname" class="tna-text-input" name="firstname" value="" type="text" spellcheck="false" autocapitalize="off" autocorrect="off">
</div>
</div>
Nunjucks
Nunjucks options
| Name | Type | Description |
|---|---|---|
| label | string |
Required. The label for the text input field. |
| headingLevel | number |
The heading level which represents an element from |
| headingSize | string |
The physical size of the text input title ( Default value: |
| id | string |
Required. A unique ID for the text input 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. |
| type | string |
Set the type of the text input (for example Default value: |
| password | boolean |
If Default value: |
| newPassword | boolean |
If Default value: |
| inputmode | string |
Change the |
| spellcheck | boolean |
If Default value: |
| autocapitalize | string |
If Default value: |
| autocorrect | boolean |
If Default value: |
| autocomplete | string |
Set the Default value: |
| size | string |
Set the width of the text input. Can be |
| formItemClasses | string |
Classes to add to the text input group. |
| formItemAttributes | object |
HTML attributes (for example data attributes) to add to the text input form group. |
| classes | string |
Classes to add to the text input. |
| attributes | object |
HTML attributes (for example data attributes) to add to the text input. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required. The error text to display. |
{% from "nationalarchives/components/text-input/macro.njk" import tnaTextInput %}
{{ tnaTextInput({
label: "Enter your first name",
headingSize: "m",
id: "firstname",
name: "firstname"
}) }}
Jinja
Important information
{% from "components/text-input/macro.html" import tnaTextInput %}
{{ tnaTextInput({
"label": "Enter your first name",
"headingSize": "m",
"id": "firstname",
"name": "firstname"
}) }}
Component status
Prefilled
HTML
<div class="tna-form-item">
<div class="tna-form-item__header">
<label class="tna-form-item__label tna-heading-m" for="firstname">
Enter your first name
</label>
</div>
<div class="tna-form-item__body">
<input id="firstname" class="tna-text-input" name="firstname" value="Sam" type="text" spellcheck="false" autocapitalize="off" autocorrect="off">
</div>
</div>
Nunjucks
Nunjucks options
| Name | Type | Description |
|---|---|---|
| label | string |
Required. The label for the text input field. |
| headingLevel | number |
The heading level which represents an element from |
| headingSize | string |
The physical size of the text input title ( Default value: |
| id | string |
Required. A unique ID for the text input 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. |
| type | string |
Set the type of the text input (for example Default value: |
| password | boolean |
If Default value: |
| newPassword | boolean |
If Default value: |
| inputmode | string |
Change the |
| spellcheck | boolean |
If Default value: |
| autocapitalize | string |
If Default value: |
| autocorrect | boolean |
If Default value: |
| autocomplete | string |
Set the Default value: |
| size | string |
Set the width of the text input. Can be |
| formItemClasses | string |
Classes to add to the text input group. |
| formItemAttributes | object |
HTML attributes (for example data attributes) to add to the text input form group. |
| classes | string |
Classes to add to the text input. |
| attributes | object |
HTML attributes (for example data attributes) to add to the text input. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required. The error text to display. |
{% from "nationalarchives/components/text-input/macro.njk" import tnaTextInput %}
{{ tnaTextInput({
label: "Enter your first name",
headingSize: "m",
id: "firstname",
name: "firstname",
value: "Sam"
}) }}
Jinja
Important information
{% from "components/text-input/macro.html" import tnaTextInput %}
{{ tnaTextInput({
"label": "Enter your first name",
"headingSize": "m",
"id": "firstname",
"name": "firstname",
"value": "Sam"
}) }}
Hint
HTML
<div class="tna-form-item">
<div class="tna-form-item__header">
<label class="tna-form-item__label tna-heading-m" for="firstname">
Enter your first name
</label>
</div>
<p id="firstname-hint" class="tna-form-item__hint">
What people call you by
</p>
<div class="tna-form-item__body">
<input id="firstname" class="tna-text-input" name="firstname" value="" aria-describedby="firstname-hint " type="text" spellcheck="false" autocapitalize="off" autocorrect="off">
</div>
</div>
Nunjucks
Nunjucks options
| Name | Type | Description |
|---|---|---|
| label | string |
Required. The label for the text input field. |
| headingLevel | number |
The heading level which represents an element from |
| headingSize | string |
The physical size of the text input title ( Default value: |
| id | string |
Required. A unique ID for the text input 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. |
| type | string |
Set the type of the text input (for example Default value: |
| password | boolean |
If Default value: |
| newPassword | boolean |
If Default value: |
| inputmode | string |
Change the |
| spellcheck | boolean |
If Default value: |
| autocapitalize | string |
If Default value: |
| autocorrect | boolean |
If Default value: |
| autocomplete | string |
Set the Default value: |
| size | string |
Set the width of the text input. Can be |
| formItemClasses | string |
Classes to add to the text input group. |
| formItemAttributes | object |
HTML attributes (for example data attributes) to add to the text input form group. |
| classes | string |
Classes to add to the text input. |
| attributes | object |
HTML attributes (for example data attributes) to add to the text input. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required. The error text to display. |
{% from "nationalarchives/components/text-input/macro.njk" import tnaTextInput %}
{{ tnaTextInput({
label: "Enter your first name",
headingSize: "m",
id: "firstname",
name: "firstname",
hint: "What people call you by"
}) }}
Jinja
Important information
{% from "components/text-input/macro.html" import tnaTextInput %}
{{ tnaTextInput({
"label": "Enter your first name",
"headingSize": "m",
"id": "firstname",
"name": "firstname",
"hint": "What people call you by"
}) }}
Error
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="firstname">
Enter your first name
</label>
</div>
<p id="firstname-error" class="tna-form-item__error">
<span class="tna-!--visually-hidden">Error:</span> Enter a name
</p>
<div class="tna-form-item__body">
<input id="firstname" class="tna-text-input" name="firstname" value="" aria-describedby=" firstname-error" type="text" spellcheck="false" autocapitalize="off" autocorrect="off">
</div>
</div>
Nunjucks
Nunjucks options
| Name | Type | Description |
|---|---|---|
| label | string |
Required. The label for the text input field. |
| headingLevel | number |
The heading level which represents an element from |
| headingSize | string |
The physical size of the text input title ( Default value: |
| id | string |
Required. A unique ID for the text input 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. |
| type | string |
Set the type of the text input (for example Default value: |
| password | boolean |
If Default value: |
| newPassword | boolean |
If Default value: |
| inputmode | string |
Change the |
| spellcheck | boolean |
If Default value: |
| autocapitalize | string |
If Default value: |
| autocorrect | boolean |
If Default value: |
| autocomplete | string |
Set the Default value: |
| size | string |
Set the width of the text input. Can be |
| formItemClasses | string |
Classes to add to the text input group. |
| formItemAttributes | object |
HTML attributes (for example data attributes) to add to the text input form group. |
| classes | string |
Classes to add to the text input. |
| attributes | object |
HTML attributes (for example data attributes) to add to the text input. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required. The error text to display. |
{% from "nationalarchives/components/text-input/macro.njk" import tnaTextInput %}
{{ tnaTextInput({
label: "Enter your first name",
headingSize: "m",
id: "firstname",
name: "firstname",
error: {
text: "Enter a name"
}
}) }}
Jinja
Important information
{% from "components/text-input/macro.html" import tnaTextInput %}
{{ tnaTextInput({
"label": "Enter your first name",
"headingSize": "m",
"id": "firstname",
"name": "firstname",
"error": {
"text": "Enter a name"
}
}) }}
Password
The password text input is enhanced with JavaScript to allow the hiding and showing of the password.
By default, the password input will try and autofill from existing passwords. Use newPassword: true to use a password box that allows password managers to generate a new password.
HTML
<div class="tna-form-item" data-module="tna-text-input-password">
<div class="tna-form-item__header">
<label class="tna-form-item__label tna-heading-m" for="password">
Enter your password
</label>
</div>
<div class="tna-form-item__body">
<input id="password" class="tna-text-input" name="password" value="" type="password" autocomplete="current-password">
</div>
</div>
<div class="tna-form-item" data-module="tna-text-input-password">
<div class="tna-form-item__header">
<label class="tna-form-item__label tna-heading-m" for="password-new">
Create a password
</label>
</div>
<p id="password-new-hint" class="tna-form-item__hint">
Your password must be at least 8 characters long
</p>
<div class="tna-form-item__body">
<input id="password-new" class="tna-text-input" name="password-new" value="" aria-describedby="password-new-hint " type="password" autocomplete="new-password">
</div>
</div>
Nunjucks
Nunjucks options
| Name | Type | Description |
|---|---|---|
| label | string |
Required. The label for the text input field. |
| headingLevel | number |
The heading level which represents an element from |
| headingSize | string |
The physical size of the text input title ( Default value: |
| id | string |
Required. A unique ID for the text input 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. |
| type | string |
Set the type of the text input (for example Default value: |
| password | boolean |
If Default value: |
| newPassword | boolean |
If Default value: |
| inputmode | string |
Change the |
| spellcheck | boolean |
If Default value: |
| autocapitalize | string |
If Default value: |
| autocorrect | boolean |
If Default value: |
| autocomplete | string |
Set the Default value: |
| size | string |
Set the width of the text input. Can be |
| formItemClasses | string |
Classes to add to the text input group. |
| formItemAttributes | object |
HTML attributes (for example data attributes) to add to the text input form group. |
| classes | string |
Classes to add to the text input. |
| attributes | object |
HTML attributes (for example data attributes) to add to the text input. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required. The error text to display. |
{% from "nationalarchives/components/text-input/macro.njk" import tnaTextInput %}
{{ tnaTextInput({
label: "Enter your password",
headingSize: "m",
id: "password",
name: "password",
password: true
}) }}{{ tnaTextInput({
label: "Create a password",
headingSize: "m",
id: "password-new",
name: "password-new",
hint: "Your password must be at least 8 characters long",
password: true,
newPassword: true
}) }}
Jinja
Important information
{% from "components/text-input/macro.html" import tnaTextInput %}
{{ tnaTextInput({
"label": "Enter your password",
"headingSize": "m",
"id": "password",
"name": "password",
"password": True
}) }}{{ tnaTextInput({
"label": "Create a password",
"headingSize": "m",
"id": "password-new",
"name": "password-new",
"hint": "Your password must be at least 8 characters long",
"password": true,
"newPassword": true
}) }}