- style
Tag input
- 1 Description
- 2 Types
- 3 Usage & Behavior
- 3.1 General guidelines
- 3.1.1 Structure
- 3.1.2 Default State
- 3.1.3 Internal Logic
- 3.2 States
- 3.3 Interaction
- 3.3.1 Browsable list
- 3.3.2 Auto-complete
- 3.3.3 Applied tag pills
- 3.4 Validation and Errors
- 3.5 Best practices
- 3.1 General guidelines
- 4 Accessibility Compliance
- 4.1 Focus management
- 4.1.1 Browsable list
- 4.1.2 Auto-complete tag field
- 4.1 Focus management
- 5 Design
- 6 Code
Description
Tag inputs allow multiple metadata tags to be added to a piece of content from a pre-defined set.
Categorising content with tags can make it easier to find, instigate workflows, and control access permissions. Common tagsets include department, region, product, and personal information such as email addresses.
Note: Where tags are subsequently being used to filter content, use the Filter Pane.
Types
Type | Usage | Image |
Browsable list |
| |
Auto-complete |
|
|
Usage & Behavior
General guidelines
Each tagset should have its own tag input.
Structure
Browsable list
A browsable list tag input consists of:
the tag field, containing:
applied tag pills, showing the tags already selected, containing:
a tag label.
a remove icon button.
a trigger button to open the tag menu, shown to the right of the applied tag pills.
a tag menu, containing:
Auto-complete
An auto-complete tag input consists of:
the tag field, containing:
applied tag pills, showing the tags already selected, containing:
a tag label.
a text area, to the right of any applied tags.
a tag menu, containing:
a list of up to 20 tags.
a scrollbar, where needed.
a View All Tags link after the last tag (optional).
Default State
Where appropriate, tags may be pre-applied by default.
Internal Logic
Search
For both input types, search should follow the logic and behavior of Live Search.
Tag field
Pills should be arranged left-to-right, top to bottom, in the order in which the tags were applied.
The width of each pill will depend on its content, within minimum and maximum limits.
Where a tag label exceeds the maximum pill width it should be truncated, with the full label shown in a Tooltip on hover.
The trigger button should move as tags are applied, always being shown to the right of the last applied tag pill. (Browsable list only).
The tag field may optionally expand as more tags are applied. A limit may be set to the field height.
When the maximum field height is reached and there is no more space for additional pills, a vertical Scrollbar will be added to the field.
When pills are removed, the field will shrink again.
Tag menu ordering
Browsable list:
The list of tags should be in a logical order to make them easy to scan, such as alphabetically, numerically, or by frequency of use.
The tag order should remain the same when a search is applied.
Auto-complete:
When the tag field is first selected, the tags should be ordered by frequency or recency.
After search, the results should be ordered by relevance.
States
For the states of the tag menu list items, follow Lists.
State | Browsable list tag field | Browsable list - tag pills | Auto-complete tag field | Auto-complete - tag pills |
---|---|---|---|---|
Regular |
| |||
Hover | On hover over Close icon button: | |||
Active | ||||
Disabled | ||||
Error | N/A | |||
Warning | N/A | N/A | ||
Focused |
Interaction
Browsable list
The tag menu will be opened when the user clicks on either:
the trigger button, or
any blank space in the tag field.
Tag menu
The search field will be focused by default when the menu is first opened.
In the search field:
entering characters will filter the tags using Live Search.
pressing Enter will:
leave the focus on the search field, and
leave the tag menu open.
Within the tag list:
clicking anywhere on the tag label or checkbox selects and applies the tag. The tag menu remains open.
Clicking outside of the tag menu closes it.
Auto-complete
Tag field
When the tag field is selected:
the tag menu is opened.
the most frequently or recently selected tags are shown.
As characters are entered, the tags will be filtered using Live Search.
Pressing Enter while focus is on the tag field:
applies the first tag in the tag menu,
clears the current search, and
closes the tag menu.
Where no matching tags are shown, pressing Enter while focus is on the tag field:
keeps the existing search string, and
keeps the tag menu open.
Tag menu
Clicking on a tag will:
apply the focused tag,
clear the current search,
close the tag menu, and
return the focus to the tag field, ready to search again.
Clicking outside of the tag menu closes it. The existing search string should be kept.
Applied tag pills
Tags can be removed by:
clicking on a pill to select it and pressing the Delete key. Multiple pills can be selected by using drag.
clicking the X button on the right-hand side of a pill. (Browsable list only).
pressing the Delete key when there are no search characters applied. Ctrl/cmd-A can also be used to select all tags before deleting. (Auto-complete only).
When a pill is removed, the remaining pills will move to the left to close the gap.
Hovering on a pill label may open a Tooltip showing further details, where relevant.
Validation and Errors
The tag menu should show an empty state when a search has no matching tags. See Live Search.
Best practices
Use:
a browsable list for smaller tagsets where the user is unlikely to know which tags are available.
auto-complete for larger tagsets where the user is likely to know the exact label for the tag(s) they’re looking for.
Don’t use:
where only one tag can be applied to an item → use a Drop-down Menu instead.
to apply filters when searching for content → use the Filter Pane instead.
Accessibility Compliance
Unless otherwise specified, see our general compliance information in Fundamentals - Accessibility.
Focus management
When a tag input is first selected, screen readers should state how many tags are currently applied.
Browsable list
For the behavior of the tag menu, follow Drop-down Menu.
Keyboard | Tag field trigger button | Tag pills |
---|---|---|
| ||
Tab |
| Navigates to the next component outside of the tag input. |
Shift + Tab | Reverse tab. | Reverse tab. |
Space | Selects the trigger button to open the tag menu. | N/A |
Enter | Selects the trigger button to open the tag menu. | Removes the pill, de-selecting the tag. Focus moves to the pill or trigger button immediately to its right. |
Delete and Backspace | N/A | Removes the pill, de-selecting the tag. Focus moves to the pill or trigger button immediately to its right. |
Esc | N/A | N/A |
Arrows | Left/Right: moves between the pills and trigger button. Up/Down:
| Left/Right: moves between the pills and trigger button. Up/Down:
|
Page up/Home | Navigates to the first pill. | Navigates to the first pill. |
Page down/End | N/A | Navigates to the trigger button. |
Auto-complete tag field
For the behavior of the tag menu, follow Live Search.
Keyboard | Tag field text area | Applied tag pills |
---|---|---|
| ||
Tab |
| Navigates to the next component. |
Shift + Tab | Reverse tab. | Reverse tab. |
Space | Acts as text input. | N/A |
Enter | N/A | Moves focus to the text area. |
Esc | N/A | N/A |
Delete |
| Removes the pill, de-selecting the tag. |
Arrows | Left/Right:
Up/Down: moves focus to the suggested search results. | Left/Right: moves between the pills. Up/Down: N/A |
Page up/Home | Navigates to the first pill. | Navigates to the first pill. |
Page down/End | N/A | Navigates to the text area. |
a-z, A-Z | Acts as text input. | Automatically moves focus to the text area and acts as text input. |
Design
Zeplin link | Image |