Chips

Chips is used to enter multiple values on an input field.


import { ChipsModule } from 'primeng/chips';

Chips is used as a controlled input with ngModel property where it should be an array.



<p-chips [(ngModel)]="values"></p-chips>

Chips can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.



<form [formGroup]="formGroup">
    <p-chips formControlName="values"></p-chips>
</form>

A new chip is added when enter key is pressed, separator property allows definining an additional key. Currently only valid value is , to create a new item when comma key is pressed.



<p-chips [(ngModel)]="values" separator="," placeholder="Hint: a, b, c"></p-chips>

A new chip is added when enter key is pressed, separator property allows definining an additional key. Currently only valid value is , to create a new item when comma key is pressed.



<p-chips [(ngModel)]="values" [separator]="separatorExp" placeholder="Hint: a, b c"></p-chips>

A chip is customized using a ng-template element where the value is passed as the implicit variable.



<p-chips [(ngModel)]="values">
    <ng-template let-item pTemplate="item"> {{ item }} - (active) <i class="pi pi-user ml-2"></i> </ng-template>
</p-chips>

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-chipsContainer element.
p-chips-tokenChip element container.
p-chips-token-iconIcon of a chip.
p-chips-token-labelLabel of a chip.
p-chips-input-tokenContainer of input element.
Accessibility guide documents the specification of this component based on WCAG guidelines, the implementation is in progress.

Screen Reader

Value to describe the component can either be provided via label tag combined with inputId prop or using aria-labelledby, aria-label props. Chip list uses listbox role with aria-orientation set to horizontal whereas each chip has the option role with aria-label set to the label of the chip.


<label for="chips1">Tags</label>
<p-chips inputId="chips1"></p-chips>

<span id="chips2">Tags</span>
<p-chips aria-labelledby="chips2"></p-chips>

<p-chips aria-label="Tags"></p-chips>

Input Field Keyboard Support

KeyFunction
tabMoves focus to the input element
enterAdds a new chips using the input field value.
backspaceDeletes the previous chip if the input field is empty.
left arrowMoves focus to the previous chip if available and input field is empty.

Chip Keyboard Support

KeyFunction
left arrowMoves focus to the previous chip if available.
right arrowMoves focus to the next chip, if there is none then input field receives the focus.
backspaceDeletes the chips and adds focus to the input field.