Skip to content

Pills input

Pills input allows users to enter multiple items, such as tags or email addresses, into a single input field.

Usage

Pill Input is a control that lets users enter text, transforming each entry into a distinct "pill". A new entry is added when the Enter key is pressed or when separated by commas or semicolons. Existing pills can be deleted as needed.

Pills input

When to use

  • To add tags to categorize content, making it easier for users to classify and find items based on keywords.
  • To enter email addresses or names, allowing users to easily add or remove recipients.
  • For selecting multiple options from a wide range of choices.

Best practices

  • Guide users with examples in the placeholder, like "Enter tags, separated by commas."
  • If needed, set a maximum number of pills to keep the interface clean.
  • Offer autocomplete suggestions as required.
  • Provide validation when necessary.

Design

Elements

Pills input elements

1. Label (optional), 2. Pills, 3. Container, 4. Helper text (optional)

Interaction states

Pills input interaction states

Label (optional)

Effective labeling helps users understand what information to enter.

  • Keep labels short and clear (should not be wider than the input field).
  • Mandatory fields are marked with an *-asterisk.
  • Labels can be placed on top of fields or to the left (in RTL languages). Prefer top placement of labels, since it provides a consistent left edge alignment, improving scannability.

Pills input label

Validation

Real-time validation can be implemented to ensure that entered text meets specific criteria.

Pills input validation

Responsive behavior

When space is limited, pills are stacked to ensure adaptability across various screen sizes.

Pills input responsive

Code

Usage

import { SiPillsInputComponent } from '@siemens/element-ng/pills-input';

@Component({
  imports: [SiPillsInputComponent, ...]
})

SiPillsInputComponent API Documentation

Source
import { SiPillsInputComponent } from '@siemens/element-ng/pills-input';

Input Properties

NameTypeDefaultDescription
disabled
boolean false

Whether the pills-input is disabled.

errormessageId
string `${this.id()}-errormessage`

This ID will be bound to the aria-describedby attribute of the pills-input. Use this to reference the element containing the error message(s) for the pills-input. It will be picked by the SiFormItemComponent if the pills-input is used inside a form item.

Implements SiFormItemControl

id
string `__si-pills-input-${SiPillsInputComponent.idCounter++}`

The identifier of the pills-input. Will be generated if not provided.

Implements SiFormItemControl

inputElementAriaLabel
TranslatableString $localize`:@@SI_PILLS_INPUT.INPUT_ELEMENT_ARIA_LABEL:Create item`

The aria-label for the inner input where users enter new items.

labelledby
string `${this.id()}-label`

ID that should be assigned to the label element inside the SiFormItemComponent.

If the target control is not of type input, select or button, it cannot be referenced by a label. Instead, aria-labelledby must be used to create a reference to a label. In such a case, an implementation of SiFormItemControl must provide the id of the label in labelledby. SiFormItemComponent will apply the id to the label so that it can be used inside the control to reference it in the aria-labelledby attribute.

Implements SiFormItemControl

placeholder
TranslatableString | undefined

The placeholder to be shown if no value is currently present.

readonly
boolean false

Whether the pills-input is readonly

SiPillsInputCsvDirective API Documentation

Source
import { SiPillsInputCsvDirective } from '@siemens/element-ng/pills-input';

Input Properties

NameTypeDefaultDescription
pillsInputCsvItemRegex
RegExp | undefined undefined

Regex to validate an input string item.

Inherited from SiPillsInputPatternBase

Attributes and Methods

NameTypeDefaultDescription
(readonly) separatorRegexinherited
WritableSignal<RegExp> SEPARATOR_REGEX

Regex to split the input value into segments.

Inherited from SiPillsInputPatternBase

Types Documentation

Represents a translatable string. This can either be a translation key, e.g. ACTIONS.EDIT that will be automatically translated when displayed on the UI or a pre-translated string, e.g. Edit. Equivalent to a normal string in usage and functionality.

Common interface for form item controls. Controls that should be connected to SiFormItemComponent must implement this interface and must be provided using the SI_FORM_ITEM_CONTROL token.

Properties

Except where otherwise noted, content on this site is licensed under MIT License.