UNPKG

67.5 kBJavaScriptView Raw
1import { SPACE, BACKSPACE, DELETE, TAB, hasModifierKey, ENTER } from '@angular/cdk/keycodes';
2import * as i0 from '@angular/core';
3import { InjectionToken, Directive, EventEmitter, Optional, Inject, Attribute, ContentChild, Input, Output, Component, ViewEncapsulation, ChangeDetectionStrategy, Self, ContentChildren, NgModule } from '@angular/core';
4import * as i3 from '@angular/material/core';
5import { mixinTabIndex, mixinColor, mixinDisableRipple, RippleRenderer, MAT_RIPPLE_GLOBAL_OPTIONS, mixinErrorState, MatCommonModule, ErrorStateMatcher } from '@angular/material/core';
6import { coerceBooleanProperty } from '@angular/cdk/coercion';
7import * as i1 from '@angular/cdk/platform';
8import { DOCUMENT } from '@angular/common';
9import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
10import { Subject, merge } from 'rxjs';
11import { take, takeUntil, startWith } from 'rxjs/operators';
12import { FocusKeyManager } from '@angular/cdk/a11y';
13import * as i1$1 from '@angular/cdk/bidi';
14import { SelectionModel } from '@angular/cdk/collections';
15import * as i2 from '@angular/forms';
16import { Validators } from '@angular/forms';
17import { MatFormFieldControl } from '@angular/material/form-field';
18
19/** Event object emitted by MatChip when selected or deselected. */
20class MatChipSelectionChange {
21 constructor(
22 /** Reference to the chip that emitted the event. */
23 source,
24 /** Whether the chip that emitted the event is selected. */
25 selected,
26 /** Whether the selection change was a result of a user interaction. */
27 isUserInput = false) {
28 this.source = source;
29 this.selected = selected;
30 this.isUserInput = isUserInput;
31 }
32}
33/**
34 * Injection token that can be used to reference instances of `MatChipRemove`. It serves as
35 * alternative token to the actual `MatChipRemove` class which could cause unnecessary
36 * retention of the class and its directive metadata.
37 */
38const MAT_CHIP_REMOVE = new InjectionToken('MatChipRemove');
39/**
40 * Injection token that can be used to reference instances of `MatChipAvatar`. It serves as
41 * alternative token to the actual `MatChipAvatar` class which could cause unnecessary
42 * retention of the class and its directive metadata.
43 */
44const MAT_CHIP_AVATAR = new InjectionToken('MatChipAvatar');
45/**
46 * Injection token that can be used to reference instances of `MatChipTrailingIcon`. It serves as
47 * alternative token to the actual `MatChipTrailingIcon` class which could cause unnecessary
48 * retention of the class and its directive metadata.
49 */
50const MAT_CHIP_TRAILING_ICON = new InjectionToken('MatChipTrailingIcon');
51// Boilerplate for applying mixins to MatChip.
52/** @docs-private */
53class MatChipBase {
54 constructor(_elementRef) {
55 this._elementRef = _elementRef;
56 }
57}
58const _MatChipMixinBase = mixinTabIndex(mixinColor(mixinDisableRipple(MatChipBase), 'primary'), -1);
59/**
60 * Dummy directive to add CSS class to chip avatar.
61 * @docs-private
62 */
63class MatChipAvatar {
64}
65MatChipAvatar.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipAvatar, deps: [], target: i0.ɵɵFactoryTarget.Directive });
66MatChipAvatar.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: MatChipAvatar, selector: "mat-chip-avatar, [matChipAvatar]", host: { classAttribute: "mat-chip-avatar" }, providers: [{ provide: MAT_CHIP_AVATAR, useExisting: MatChipAvatar }], ngImport: i0 });
67i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipAvatar, decorators: [{
68 type: Directive,
69 args: [{
70 selector: 'mat-chip-avatar, [matChipAvatar]',
71 host: { 'class': 'mat-chip-avatar' },
72 providers: [{ provide: MAT_CHIP_AVATAR, useExisting: MatChipAvatar }],
73 }]
74 }] });
75/**
76 * Dummy directive to add CSS class to chip trailing icon.
77 * @docs-private
78 */
79class MatChipTrailingIcon {
80}
81MatChipTrailingIcon.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipTrailingIcon, deps: [], target: i0.ɵɵFactoryTarget.Directive });
82MatChipTrailingIcon.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: MatChipTrailingIcon, selector: "mat-chip-trailing-icon, [matChipTrailingIcon]", host: { classAttribute: "mat-chip-trailing-icon" }, providers: [{ provide: MAT_CHIP_TRAILING_ICON, useExisting: MatChipTrailingIcon }], ngImport: i0 });
83i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipTrailingIcon, decorators: [{
84 type: Directive,
85 args: [{
86 selector: 'mat-chip-trailing-icon, [matChipTrailingIcon]',
87 host: { 'class': 'mat-chip-trailing-icon' },
88 providers: [{ provide: MAT_CHIP_TRAILING_ICON, useExisting: MatChipTrailingIcon }],
89 }]
90 }] });
91/** Material Design styled chip directive. Used inside the MatChipList component. */
92class MatChip extends _MatChipMixinBase {
93 constructor(elementRef, _ngZone, platform, globalRippleOptions, _changeDetectorRef, _document, animationMode, tabIndex) {
94 super(elementRef);
95 this._ngZone = _ngZone;
96 this._changeDetectorRef = _changeDetectorRef;
97 /** Whether the chip has focus. */
98 this._hasFocus = false;
99 /** Whether the chip list is selectable */
100 this.chipListSelectable = true;
101 /** Whether the chip list is in multi-selection mode. */
102 this._chipListMultiple = false;
103 /** Whether the chip list as a whole is disabled. */
104 this._chipListDisabled = false;
105 /** ARIA role that should be applied to the chip. */
106 this.role = 'option';
107 this._selected = false;
108 this._selectable = true;
109 this._disabled = false;
110 this._removable = true;
111 /** Emits when the chip is focused. */
112 this._onFocus = new Subject();
113 /** Emits when the chip is blured. */
114 this._onBlur = new Subject();
115 /** Emitted when the chip is selected or deselected. */
116 this.selectionChange = new EventEmitter();
117 /** Emitted when the chip is destroyed. */
118 this.destroyed = new EventEmitter();
119 /** Emitted when a chip is to be removed. */
120 this.removed = new EventEmitter();
121 this._addHostClassName();
122 // Dynamically create the ripple target, append it within the chip, and use it as the
123 // chip's ripple target. Adding the class '.mat-chip-ripple' ensures that it will have
124 // the proper styles.
125 this._chipRippleTarget = _document.createElement('div');
126 this._chipRippleTarget.classList.add('mat-chip-ripple');
127 this._elementRef.nativeElement.appendChild(this._chipRippleTarget);
128 this._chipRipple = new RippleRenderer(this, _ngZone, this._chipRippleTarget, platform);
129 this._chipRipple.setupTriggerEvents(elementRef);
130 this.rippleConfig = globalRippleOptions || {};
131 this._animationsDisabled = animationMode === 'NoopAnimations';
132 this.tabIndex = tabIndex != null ? parseInt(tabIndex) || -1 : -1;
133 }
134 /**
135 * Whether ripples are disabled on interaction
136 * @docs-private
137 */
138 get rippleDisabled() {
139 return (this.disabled ||
140 this.disableRipple ||
141 this._animationsDisabled ||
142 !!this.rippleConfig.disabled);
143 }
144 /** Whether the chip is selected. */
145 get selected() {
146 return this._selected;
147 }
148 set selected(value) {
149 const coercedValue = coerceBooleanProperty(value);
150 if (coercedValue !== this._selected) {
151 this._selected = coercedValue;
152 this._dispatchSelectionChange();
153 }
154 }
155 /** The value of the chip. Defaults to the content inside `<mat-chip>` tags. */
156 get value() {
157 return this._value !== undefined ? this._value : this._elementRef.nativeElement.textContent;
158 }
159 set value(value) {
160 this._value = value;
161 }
162 /**
163 * Whether or not the chip is selectable. When a chip is not selectable,
164 * changes to its selected state are always ignored. By default a chip is
165 * selectable, and it becomes non-selectable if its parent chip list is
166 * not selectable.
167 */
168 get selectable() {
169 return this._selectable && this.chipListSelectable;
170 }
171 set selectable(value) {
172 this._selectable = coerceBooleanProperty(value);
173 }
174 /** Whether the chip is disabled. */
175 get disabled() {
176 return this._chipListDisabled || this._disabled;
177 }
178 set disabled(value) {
179 this._disabled = coerceBooleanProperty(value);
180 }
181 /**
182 * Determines whether or not the chip displays the remove styling and emits (removed) events.
183 */
184 get removable() {
185 return this._removable;
186 }
187 set removable(value) {
188 this._removable = coerceBooleanProperty(value);
189 }
190 /** The ARIA selected applied to the chip. */
191 get ariaSelected() {
192 // Remove the `aria-selected` when the chip is deselected in single-selection mode, because
193 // it adds noise to NVDA users where "not selected" will be read out for each chip.
194 return this.selectable && (this._chipListMultiple || this.selected)
195 ? this.selected.toString()
196 : null;
197 }
198 _addHostClassName() {
199 const basicChipAttrName = 'mat-basic-chip';
200 const element = this._elementRef.nativeElement;
201 if (element.hasAttribute(basicChipAttrName) ||
202 element.tagName.toLowerCase() === basicChipAttrName) {
203 element.classList.add(basicChipAttrName);
204 return;
205 }
206 else {
207 element.classList.add('mat-standard-chip');
208 }
209 }
210 ngOnDestroy() {
211 this.destroyed.emit({ chip: this });
212 this._chipRipple._removeTriggerEvents();
213 }
214 /** Selects the chip. */
215 select() {
216 if (!this._selected) {
217 this._selected = true;
218 this._dispatchSelectionChange();
219 this._changeDetectorRef.markForCheck();
220 }
221 }
222 /** Deselects the chip. */
223 deselect() {
224 if (this._selected) {
225 this._selected = false;
226 this._dispatchSelectionChange();
227 this._changeDetectorRef.markForCheck();
228 }
229 }
230 /** Select this chip and emit selected event */
231 selectViaInteraction() {
232 if (!this._selected) {
233 this._selected = true;
234 this._dispatchSelectionChange(true);
235 this._changeDetectorRef.markForCheck();
236 }
237 }
238 /** Toggles the current selected state of this chip. */
239 toggleSelected(isUserInput = false) {
240 this._selected = !this.selected;
241 this._dispatchSelectionChange(isUserInput);
242 this._changeDetectorRef.markForCheck();
243 return this.selected;
244 }
245 /** Allows for programmatic focusing of the chip. */
246 focus() {
247 if (!this._hasFocus) {
248 this._elementRef.nativeElement.focus();
249 this._onFocus.next({ chip: this });
250 }
251 this._hasFocus = true;
252 }
253 /**
254 * Allows for programmatic removal of the chip. Called by the MatChipList when the DELETE or
255 * BACKSPACE keys are pressed.
256 *
257 * Informs any listeners of the removal request. Does not remove the chip from the DOM.
258 */
259 remove() {
260 if (this.removable) {
261 this.removed.emit({ chip: this });
262 }
263 }
264 /** Handles click events on the chip. */
265 _handleClick(event) {
266 if (this.disabled) {
267 event.preventDefault();
268 }
269 }
270 /** Handle custom key presses. */
271 _handleKeydown(event) {
272 if (this.disabled) {
273 return;
274 }
275 switch (event.keyCode) {
276 case DELETE:
277 case BACKSPACE:
278 // If we are removable, remove the focused chip
279 this.remove();
280 // Always prevent so page navigation does not occur
281 event.preventDefault();
282 break;
283 case SPACE:
284 // If we are selectable, toggle the focused chip
285 if (this.selectable) {
286 this.toggleSelected(true);
287 }
288 // Always prevent space from scrolling the page since the list has focus
289 event.preventDefault();
290 break;
291 }
292 }
293 _blur() {
294 // When animations are enabled, Angular may end up removing the chip from the DOM a little
295 // earlier than usual, causing it to be blurred and throwing off the logic in the chip list
296 // that moves focus not the next item. To work around the issue, we defer marking the chip
297 // as not focused until the next time the zone stabilizes.
298 this._ngZone.onStable.pipe(take(1)).subscribe(() => {
299 this._ngZone.run(() => {
300 this._hasFocus = false;
301 this._onBlur.next({ chip: this });
302 });
303 });
304 }
305 _dispatchSelectionChange(isUserInput = false) {
306 this.selectionChange.emit({
307 source: this,
308 isUserInput,
309 selected: this._selected,
310 });
311 }
312}
313MatChip.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChip, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: i1.Platform }, { token: MAT_RIPPLE_GLOBAL_OPTIONS, optional: true }, { token: i0.ChangeDetectorRef }, { token: DOCUMENT }, { token: ANIMATION_MODULE_TYPE, optional: true }, { token: 'tabindex', attribute: true }], target: i0.ɵɵFactoryTarget.Directive });
314MatChip.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: MatChip, selector: "mat-basic-chip, [mat-basic-chip], mat-chip, [mat-chip]", inputs: { color: "color", disableRipple: "disableRipple", tabIndex: "tabIndex", role: "role", selected: "selected", value: "value", selectable: "selectable", disabled: "disabled", removable: "removable" }, outputs: { selectionChange: "selectionChange", destroyed: "destroyed", removed: "removed" }, host: { listeners: { "click": "_handleClick($event)", "keydown": "_handleKeydown($event)", "focus": "focus()", "blur": "_blur()" }, properties: { "attr.tabindex": "disabled ? null : tabIndex", "attr.role": "role", "class.mat-chip-selected": "selected", "class.mat-chip-with-avatar": "avatar", "class.mat-chip-with-trailing-icon": "trailingIcon || removeIcon", "class.mat-chip-disabled": "disabled", "class._mat-animation-noopable": "_animationsDisabled", "attr.disabled": "disabled || null", "attr.aria-disabled": "disabled.toString()", "attr.aria-selected": "ariaSelected" }, classAttribute: "mat-chip mat-focus-indicator" }, queries: [{ propertyName: "avatar", first: true, predicate: MAT_CHIP_AVATAR, descendants: true }, { propertyName: "trailingIcon", first: true, predicate: MAT_CHIP_TRAILING_ICON, descendants: true }, { propertyName: "removeIcon", first: true, predicate: MAT_CHIP_REMOVE, descendants: true }], exportAs: ["matChip"], usesInheritance: true, ngImport: i0 });
315i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChip, decorators: [{
316 type: Directive,
317 args: [{
318 selector: `mat-basic-chip, [mat-basic-chip], mat-chip, [mat-chip]`,
319 inputs: ['color', 'disableRipple', 'tabIndex'],
320 exportAs: 'matChip',
321 host: {
322 'class': 'mat-chip mat-focus-indicator',
323 '[attr.tabindex]': 'disabled ? null : tabIndex',
324 '[attr.role]': 'role',
325 '[class.mat-chip-selected]': 'selected',
326 '[class.mat-chip-with-avatar]': 'avatar',
327 '[class.mat-chip-with-trailing-icon]': 'trailingIcon || removeIcon',
328 '[class.mat-chip-disabled]': 'disabled',
329 '[class._mat-animation-noopable]': '_animationsDisabled',
330 '[attr.disabled]': 'disabled || null',
331 '[attr.aria-disabled]': 'disabled.toString()',
332 '[attr.aria-selected]': 'ariaSelected',
333 '(click)': '_handleClick($event)',
334 '(keydown)': '_handleKeydown($event)',
335 '(focus)': 'focus()',
336 '(blur)': '_blur()',
337 },
338 }]
339 }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: i1.Platform }, { type: undefined, decorators: [{
340 type: Optional
341 }, {
342 type: Inject,
343 args: [MAT_RIPPLE_GLOBAL_OPTIONS]
344 }] }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
345 type: Inject,
346 args: [DOCUMENT]
347 }] }, { type: undefined, decorators: [{
348 type: Optional
349 }, {
350 type: Inject,
351 args: [ANIMATION_MODULE_TYPE]
352 }] }, { type: undefined, decorators: [{
353 type: Attribute,
354 args: ['tabindex']
355 }] }]; }, propDecorators: { avatar: [{
356 type: ContentChild,
357 args: [MAT_CHIP_AVATAR]
358 }], trailingIcon: [{
359 type: ContentChild,
360 args: [MAT_CHIP_TRAILING_ICON]
361 }], removeIcon: [{
362 type: ContentChild,
363 args: [MAT_CHIP_REMOVE]
364 }], role: [{
365 type: Input
366 }], selected: [{
367 type: Input
368 }], value: [{
369 type: Input
370 }], selectable: [{
371 type: Input
372 }], disabled: [{
373 type: Input
374 }], removable: [{
375 type: Input
376 }], selectionChange: [{
377 type: Output
378 }], destroyed: [{
379 type: Output
380 }], removed: [{
381 type: Output
382 }] } });
383/**
384 * Applies proper (click) support and adds styling for use with the Material Design "cancel" icon
385 * available at https://material.io/icons/#ic_cancel.
386 *
387 * Example:
388 *
389 * `<mat-chip>
390 * <mat-icon matChipRemove>cancel</mat-icon>
391 * </mat-chip>`
392 *
393 * You *may* use a custom icon, but you may need to override the `mat-chip-remove` positioning
394 * styles to properly center the icon within the chip.
395 */
396class MatChipRemove {
397 constructor(_parentChip, elementRef) {
398 this._parentChip = _parentChip;
399 if (elementRef.nativeElement.nodeName === 'BUTTON') {
400 elementRef.nativeElement.setAttribute('type', 'button');
401 }
402 }
403 /** Calls the parent chip's public `remove()` method if applicable. */
404 _handleClick(event) {
405 const parentChip = this._parentChip;
406 if (parentChip.removable && !parentChip.disabled) {
407 parentChip.remove();
408 }
409 // We need to stop event propagation because otherwise the event will bubble up to the
410 // form field and cause the `onContainerClick` method to be invoked. This method would then
411 // reset the focused chip that has been focused after chip removal. Usually the parent
412 // the parent click listener of the `MatChip` would prevent propagation, but it can happen
413 // that the chip is being removed before the event bubbles up.
414 event.stopPropagation();
415 event.preventDefault();
416 }
417}
418MatChipRemove.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipRemove, deps: [{ token: MatChip }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
419MatChipRemove.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: MatChipRemove, selector: "[matChipRemove]", host: { listeners: { "click": "_handleClick($event)" }, classAttribute: "mat-chip-remove mat-chip-trailing-icon" }, providers: [{ provide: MAT_CHIP_REMOVE, useExisting: MatChipRemove }], ngImport: i0 });
420i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipRemove, decorators: [{
421 type: Directive,
422 args: [{
423 selector: '[matChipRemove]',
424 host: {
425 'class': 'mat-chip-remove mat-chip-trailing-icon',
426 '(click)': '_handleClick($event)',
427 },
428 providers: [{ provide: MAT_CHIP_REMOVE, useExisting: MatChipRemove }],
429 }]
430 }], ctorParameters: function () { return [{ type: MatChip }, { type: i0.ElementRef }]; } });
431
432/**
433 * @license
434 * Copyright Google LLC All Rights Reserved.
435 *
436 * Use of this source code is governed by an MIT-style license that can be
437 * found in the LICENSE file at https://angular.io/license
438 */
439/** Injection token to be used to override the default options for the chips module. */
440const MAT_CHIPS_DEFAULT_OPTIONS = new InjectionToken('mat-chips-default-options');
441
442/**
443 * @license
444 * Copyright Google LLC All Rights Reserved.
445 *
446 * Use of this source code is governed by an MIT-style license that can be
447 * found in the LICENSE file at https://angular.io/license
448 */
449// Boilerplate for applying mixins to MatChipList.
450/** @docs-private */
451const _MatChipListBase = mixinErrorState(class {
452 constructor(_defaultErrorStateMatcher, _parentForm, _parentFormGroup,
453 /**
454 * Form control bound to the component.
455 * Implemented as part of `MatFormFieldControl`.
456 * @docs-private
457 */
458 ngControl) {
459 this._defaultErrorStateMatcher = _defaultErrorStateMatcher;
460 this._parentForm = _parentForm;
461 this._parentFormGroup = _parentFormGroup;
462 this.ngControl = ngControl;
463 /**
464 * Emits whenever the component state changes and should cause the parent
465 * form-field to update. Implemented as part of `MatFormFieldControl`.
466 * @docs-private
467 */
468 this.stateChanges = new Subject();
469 }
470});
471// Increasing integer for generating unique ids for chip-list components.
472let nextUniqueId$1 = 0;
473/** Change event object that is emitted when the chip list value has changed. */
474class MatChipListChange {
475 constructor(
476 /** Chip list that emitted the event. */
477 source,
478 /** Value of the chip list when the event was emitted. */
479 value) {
480 this.source = source;
481 this.value = value;
482 }
483}
484/**
485 * A material design chips component (named ChipList for its similarity to the List component).
486 */
487class MatChipList extends _MatChipListBase {
488 constructor(_elementRef, _changeDetectorRef, _dir, _parentForm, _parentFormGroup, _defaultErrorStateMatcher, ngControl) {
489 super(_defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl);
490 this._elementRef = _elementRef;
491 this._changeDetectorRef = _changeDetectorRef;
492 this._dir = _dir;
493 /**
494 * Implemented as part of MatFormFieldControl.
495 * @docs-private
496 */
497 this.controlType = 'mat-chip-list';
498 /**
499 * When a chip is destroyed, we store the index of the destroyed chip until the chips
500 * query list notifies about the update. This is necessary because we cannot determine an
501 * appropriate chip that should receive focus until the array of chips updated completely.
502 */
503 this._lastDestroyedChipIndex = null;
504 /** Subject that emits when the component has been destroyed. */
505 this._destroyed = new Subject();
506 /** Uid of the chip list */
507 this._uid = `mat-chip-list-${nextUniqueId$1++}`;
508 /** Tab index for the chip list. */
509 this._tabIndex = 0;
510 /**
511 * User defined tab index.
512 * When it is not null, use user defined tab index. Otherwise use _tabIndex
513 */
514 this._userTabIndex = null;
515 /** Function when touched */
516 this._onTouched = () => { };
517 /** Function when changed */
518 this._onChange = () => { };
519 this._multiple = false;
520 this._compareWith = (o1, o2) => o1 === o2;
521 this._disabled = false;
522 /** Orientation of the chip list. */
523 this.ariaOrientation = 'horizontal';
524 this._selectable = true;
525 /** Event emitted when the selected chip list value has been changed by the user. */
526 this.change = new EventEmitter();
527 /**
528 * Event that emits whenever the raw value of the chip-list changes. This is here primarily
529 * to facilitate the two-way binding for the `value` input.
530 * @docs-private
531 */
532 this.valueChange = new EventEmitter();
533 if (this.ngControl) {
534 this.ngControl.valueAccessor = this;
535 }
536 }
537 /** The array of selected chips inside chip list. */
538 get selected() {
539 return this.multiple ? this._selectionModel?.selected || [] : this._selectionModel?.selected[0];
540 }
541 /** The ARIA role applied to the chip list. */
542 get role() {
543 if (this._explicitRole) {
544 return this._explicitRole;
545 }
546 return this.empty ? null : 'listbox';
547 }
548 set role(role) {
549 this._explicitRole = role;
550 }
551 /** Whether the user should be allowed to select multiple chips. */
552 get multiple() {
553 return this._multiple;
554 }
555 set multiple(value) {
556 this._multiple = coerceBooleanProperty(value);
557 this._syncChipsState();
558 }
559 /**
560 * A function to compare the option values with the selected values. The first argument
561 * is a value from an option. The second is a value from the selection. A boolean
562 * should be returned.
563 */
564 get compareWith() {
565 return this._compareWith;
566 }
567 set compareWith(fn) {
568 this._compareWith = fn;
569 if (this._selectionModel) {
570 // A different comparator means the selection could change.
571 this._initializeSelection();
572 }
573 }
574 /**
575 * Implemented as part of MatFormFieldControl.
576 * @docs-private
577 */
578 get value() {
579 return this._value;
580 }
581 set value(value) {
582 this.writeValue(value);
583 this._value = value;
584 }
585 /**
586 * Implemented as part of MatFormFieldControl.
587 * @docs-private
588 */
589 get id() {
590 return this._chipInput ? this._chipInput.id : this._uid;
591 }
592 /**
593 * Implemented as part of MatFormFieldControl.
594 * @docs-private
595 */
596 get required() {
597 return this._required ?? this.ngControl?.control?.hasValidator(Validators.required) ?? false;
598 }
599 set required(value) {
600 this._required = coerceBooleanProperty(value);
601 this.stateChanges.next();
602 }
603 /**
604 * Implemented as part of MatFormFieldControl.
605 * @docs-private
606 */
607 get placeholder() {
608 return this._chipInput ? this._chipInput.placeholder : this._placeholder;
609 }
610 set placeholder(value) {
611 this._placeholder = value;
612 this.stateChanges.next();
613 }
614 /** Whether any chips or the matChipInput inside of this chip-list has focus. */
615 get focused() {
616 return (this._chipInput && this._chipInput.focused) || this._hasFocusedChip();
617 }
618 /**
619 * Implemented as part of MatFormFieldControl.
620 * @docs-private
621 */
622 get empty() {
623 return (!this._chipInput || this._chipInput.empty) && (!this.chips || this.chips.length === 0);
624 }
625 /**
626 * Implemented as part of MatFormFieldControl.
627 * @docs-private
628 */
629 get shouldLabelFloat() {
630 return !this.empty || this.focused;
631 }
632 /**
633 * Implemented as part of MatFormFieldControl.
634 * @docs-private
635 */
636 get disabled() {
637 return this.ngControl ? !!this.ngControl.disabled : this._disabled;
638 }
639 set disabled(value) {
640 this._disabled = coerceBooleanProperty(value);
641 this._syncChipsState();
642 }
643 /**
644 * Whether or not this chip list is selectable. When a chip list is not selectable,
645 * the selected states for all the chips inside the chip list are always ignored.
646 */
647 get selectable() {
648 return this._selectable;
649 }
650 set selectable(value) {
651 this._selectable = coerceBooleanProperty(value);
652 if (this.chips) {
653 this.chips.forEach(chip => (chip.chipListSelectable = this._selectable));
654 }
655 }
656 set tabIndex(value) {
657 this._userTabIndex = value;
658 this._tabIndex = value;
659 }
660 /** Combined stream of all of the child chips' selection change events. */
661 get chipSelectionChanges() {
662 return merge(...this.chips.map(chip => chip.selectionChange));
663 }
664 /** Combined stream of all of the child chips' focus change events. */
665 get chipFocusChanges() {
666 return merge(...this.chips.map(chip => chip._onFocus));
667 }
668 /** Combined stream of all of the child chips' blur change events. */
669 get chipBlurChanges() {
670 return merge(...this.chips.map(chip => chip._onBlur));
671 }
672 /** Combined stream of all of the child chips' remove change events. */
673 get chipRemoveChanges() {
674 return merge(...this.chips.map(chip => chip.destroyed));
675 }
676 ngAfterContentInit() {
677 this._keyManager = new FocusKeyManager(this.chips)
678 .withWrap()
679 .withVerticalOrientation()
680 .withHomeAndEnd()
681 .withHorizontalOrientation(this._dir ? this._dir.value : 'ltr');
682 if (this._dir) {
683 this._dir.change
684 .pipe(takeUntil(this._destroyed))
685 .subscribe(dir => this._keyManager.withHorizontalOrientation(dir));
686 }
687 this._keyManager.tabOut.pipe(takeUntil(this._destroyed)).subscribe(() => {
688 this._allowFocusEscape();
689 });
690 // When the list changes, re-subscribe
691 this.chips.changes.pipe(startWith(null), takeUntil(this._destroyed)).subscribe(() => {
692 if (this.disabled) {
693 // Since this happens after the content has been
694 // checked, we need to defer it to the next tick.
695 Promise.resolve().then(() => {
696 this._syncChipsState();
697 });
698 }
699 this._resetChips();
700 // Reset chips selected/deselected status
701 this._initializeSelection();
702 // Check to see if we need to update our tab index
703 this._updateTabIndex();
704 // Check to see if we have a destroyed chip and need to refocus
705 this._updateFocusForDestroyedChips();
706 this.stateChanges.next();
707 });
708 }
709 ngOnInit() {
710 this._selectionModel = new SelectionModel(this.multiple, undefined, false);
711 this.stateChanges.next();
712 }
713 ngDoCheck() {
714 if (this.ngControl) {
715 // We need to re-evaluate this on every change detection cycle, because there are some
716 // error triggers that we can't subscribe to (e.g. parent form submissions). This means
717 // that whatever logic is in here has to be super lean or we risk destroying the performance.
718 this.updateErrorState();
719 if (this.ngControl.disabled !== this._disabled) {
720 this.disabled = !!this.ngControl.disabled;
721 }
722 }
723 }
724 ngOnDestroy() {
725 this._destroyed.next();
726 this._destroyed.complete();
727 this.stateChanges.complete();
728 this._dropSubscriptions();
729 }
730 /** Associates an HTML input element with this chip list. */
731 registerInput(inputElement) {
732 this._chipInput = inputElement;
733 // We use this attribute to match the chip list to its input in test harnesses.
734 // Set the attribute directly here to avoid "changed after checked" errors.
735 this._elementRef.nativeElement.setAttribute('data-mat-chip-input', inputElement.id);
736 }
737 /**
738 * Implemented as part of MatFormFieldControl.
739 * @docs-private
740 */
741 setDescribedByIds(ids) {
742 if (ids.length) {
743 this._elementRef.nativeElement.setAttribute('aria-describedby', ids.join(' '));
744 }
745 else {
746 this._elementRef.nativeElement.removeAttribute('aria-describedby');
747 }
748 }
749 // Implemented as part of ControlValueAccessor.
750 writeValue(value) {
751 if (this.chips) {
752 this._setSelectionByValue(value, false);
753 }
754 }
755 // Implemented as part of ControlValueAccessor.
756 registerOnChange(fn) {
757 this._onChange = fn;
758 }
759 // Implemented as part of ControlValueAccessor.
760 registerOnTouched(fn) {
761 this._onTouched = fn;
762 }
763 // Implemented as part of ControlValueAccessor.
764 setDisabledState(isDisabled) {
765 this.disabled = isDisabled;
766 this.stateChanges.next();
767 }
768 /**
769 * Implemented as part of MatFormFieldControl.
770 * @docs-private
771 */
772 onContainerClick(event) {
773 if (!this._originatesFromChip(event)) {
774 this.focus();
775 }
776 }
777 /**
778 * Focuses the first non-disabled chip in this chip list, or the associated input when there
779 * are no eligible chips.
780 */
781 focus(options) {
782 if (this.disabled) {
783 return;
784 }
785 // TODO: ARIA says this should focus the first `selected` chip if any are selected.
786 // Focus on first element if there's no chipInput inside chip-list
787 if (this._chipInput && this._chipInput.focused) {
788 // do nothing
789 }
790 else if (this.chips.length > 0) {
791 this._keyManager.setFirstItemActive();
792 this.stateChanges.next();
793 }
794 else {
795 this._focusInput(options);
796 this.stateChanges.next();
797 }
798 }
799 /** Attempt to focus an input if we have one. */
800 _focusInput(options) {
801 if (this._chipInput) {
802 this._chipInput.focus(options);
803 }
804 }
805 /**
806 * Pass events to the keyboard manager. Available here for tests.
807 */
808 _keydown(event) {
809 const target = event.target;
810 if (target && target.classList.contains('mat-chip')) {
811 this._keyManager.onKeydown(event);
812 this.stateChanges.next();
813 }
814 }
815 /**
816 * Check the tab index as you should not be allowed to focus an empty list.
817 */
818 _updateTabIndex() {
819 // If we have 0 chips, we should not allow keyboard focus
820 this._tabIndex = this._userTabIndex || (this.chips.length === 0 ? -1 : 0);
821 }
822 /**
823 * If the amount of chips changed, we need to update the
824 * key manager state and focus the next closest chip.
825 */
826 _updateFocusForDestroyedChips() {
827 // Move focus to the closest chip. If no other chips remain, focus the chip-list itself.
828 if (this._lastDestroyedChipIndex != null) {
829 if (this.chips.length) {
830 const newChipIndex = Math.min(this._lastDestroyedChipIndex, this.chips.length - 1);
831 this._keyManager.setActiveItem(newChipIndex);
832 }
833 else {
834 this.focus();
835 }
836 }
837 this._lastDestroyedChipIndex = null;
838 }
839 /**
840 * Utility to ensure all indexes are valid.
841 *
842 * @param index The index to be checked.
843 * @returns True if the index is valid for our list of chips.
844 */
845 _isValidIndex(index) {
846 return index >= 0 && index < this.chips.length;
847 }
848 _setSelectionByValue(value, isUserInput = true) {
849 this._clearSelection();
850 this.chips.forEach(chip => chip.deselect());
851 if (Array.isArray(value)) {
852 value.forEach(currentValue => this._selectValue(currentValue, isUserInput));
853 this._sortValues();
854 }
855 else {
856 const correspondingChip = this._selectValue(value, isUserInput);
857 // Shift focus to the active item. Note that we shouldn't do this in multiple
858 // mode, because we don't know what chip the user interacted with last.
859 if (correspondingChip) {
860 if (isUserInput) {
861 this._keyManager.setActiveItem(correspondingChip);
862 }
863 }
864 }
865 }
866 /**
867 * Finds and selects the chip based on its value.
868 * @returns Chip that has the corresponding value.
869 */
870 _selectValue(value, isUserInput = true) {
871 const correspondingChip = this.chips.find(chip => {
872 return chip.value != null && this._compareWith(chip.value, value);
873 });
874 if (correspondingChip) {
875 isUserInput ? correspondingChip.selectViaInteraction() : correspondingChip.select();
876 this._selectionModel.select(correspondingChip);
877 }
878 return correspondingChip;
879 }
880 _initializeSelection() {
881 // Defer setting the value in order to avoid the "Expression
882 // has changed after it was checked" errors from Angular.
883 Promise.resolve().then(() => {
884 if (this.ngControl || this._value) {
885 this._setSelectionByValue(this.ngControl ? this.ngControl.value : this._value, false);
886 this.stateChanges.next();
887 }
888 });
889 }
890 /**
891 * Deselects every chip in the list.
892 * @param skip Chip that should not be deselected.
893 */
894 _clearSelection(skip) {
895 this._selectionModel.clear();
896 this.chips.forEach(chip => {
897 if (chip !== skip) {
898 chip.deselect();
899 }
900 });
901 this.stateChanges.next();
902 }
903 /**
904 * Sorts the model values, ensuring that they keep the same
905 * order that they have in the panel.
906 */
907 _sortValues() {
908 if (this._multiple) {
909 this._selectionModel.clear();
910 this.chips.forEach(chip => {
911 if (chip.selected) {
912 this._selectionModel.select(chip);
913 }
914 });
915 this.stateChanges.next();
916 }
917 }
918 /** Emits change event to set the model value. */
919 _propagateChanges(fallbackValue) {
920 let valueToEmit = null;
921 if (Array.isArray(this.selected)) {
922 valueToEmit = this.selected.map(chip => chip.value);
923 }
924 else {
925 valueToEmit = this.selected ? this.selected.value : fallbackValue;
926 }
927 this._value = valueToEmit;
928 this.change.emit(new MatChipListChange(this, valueToEmit));
929 this.valueChange.emit(valueToEmit);
930 this._onChange(valueToEmit);
931 this._changeDetectorRef.markForCheck();
932 }
933 /** When blurred, mark the field as touched when focus moved outside the chip list. */
934 _blur() {
935 if (!this._hasFocusedChip()) {
936 this._keyManager.setActiveItem(-1);
937 }
938 if (!this.disabled) {
939 if (this._chipInput) {
940 // If there's a chip input, we should check whether the focus moved to chip input.
941 // If the focus is not moved to chip input, mark the field as touched. If the focus moved
942 // to chip input, do nothing.
943 // Timeout is needed to wait for the focus() event trigger on chip input.
944 setTimeout(() => {
945 if (!this.focused) {
946 this._markAsTouched();
947 }
948 });
949 }
950 else {
951 // If there's no chip input, then mark the field as touched.
952 this._markAsTouched();
953 }
954 }
955 }
956 /** Mark the field as touched */
957 _markAsTouched() {
958 this._onTouched();
959 this._changeDetectorRef.markForCheck();
960 this.stateChanges.next();
961 }
962 /**
963 * Removes the `tabindex` from the chip list and resets it back afterwards, allowing the
964 * user to tab out of it. This prevents the list from capturing focus and redirecting
965 * it back to the first chip, creating a focus trap, if it user tries to tab away.
966 */
967 _allowFocusEscape() {
968 if (this._tabIndex !== -1) {
969 this._tabIndex = -1;
970 setTimeout(() => {
971 this._tabIndex = this._userTabIndex || 0;
972 this._changeDetectorRef.markForCheck();
973 });
974 }
975 }
976 _resetChips() {
977 this._dropSubscriptions();
978 this._listenToChipsFocus();
979 this._listenToChipsSelection();
980 this._listenToChipsRemoved();
981 }
982 _dropSubscriptions() {
983 if (this._chipFocusSubscription) {
984 this._chipFocusSubscription.unsubscribe();
985 this._chipFocusSubscription = null;
986 }
987 if (this._chipBlurSubscription) {
988 this._chipBlurSubscription.unsubscribe();
989 this._chipBlurSubscription = null;
990 }
991 if (this._chipSelectionSubscription) {
992 this._chipSelectionSubscription.unsubscribe();
993 this._chipSelectionSubscription = null;
994 }
995 if (this._chipRemoveSubscription) {
996 this._chipRemoveSubscription.unsubscribe();
997 this._chipRemoveSubscription = null;
998 }
999 }
1000 /** Listens to user-generated selection events on each chip. */
1001 _listenToChipsSelection() {
1002 this._chipSelectionSubscription = this.chipSelectionChanges.subscribe(event => {
1003 event.source.selected
1004 ? this._selectionModel.select(event.source)
1005 : this._selectionModel.deselect(event.source);
1006 // For single selection chip list, make sure the deselected value is unselected.
1007 if (!this.multiple) {
1008 this.chips.forEach(chip => {
1009 if (!this._selectionModel.isSelected(chip) && chip.selected) {
1010 chip.deselect();
1011 }
1012 });
1013 }
1014 if (event.isUserInput) {
1015 this._propagateChanges();
1016 }
1017 });
1018 }
1019 /** Listens to user-generated selection events on each chip. */
1020 _listenToChipsFocus() {
1021 this._chipFocusSubscription = this.chipFocusChanges.subscribe(event => {
1022 let chipIndex = this.chips.toArray().indexOf(event.chip);
1023 if (this._isValidIndex(chipIndex)) {
1024 this._keyManager.updateActiveItem(chipIndex);
1025 }
1026 this.stateChanges.next();
1027 });
1028 this._chipBlurSubscription = this.chipBlurChanges.subscribe(() => {
1029 this._blur();
1030 this.stateChanges.next();
1031 });
1032 }
1033 _listenToChipsRemoved() {
1034 this._chipRemoveSubscription = this.chipRemoveChanges.subscribe(event => {
1035 const chip = event.chip;
1036 const chipIndex = this.chips.toArray().indexOf(event.chip);
1037 // In case the chip that will be removed is currently focused, we temporarily store
1038 // the index in order to be able to determine an appropriate sibling chip that will
1039 // receive focus.
1040 if (this._isValidIndex(chipIndex) && chip._hasFocus) {
1041 this._lastDestroyedChipIndex = chipIndex;
1042 }
1043 });
1044 }
1045 /** Checks whether an event comes from inside a chip element. */
1046 _originatesFromChip(event) {
1047 let currentElement = event.target;
1048 while (currentElement && currentElement !== this._elementRef.nativeElement) {
1049 if (currentElement.classList.contains('mat-chip')) {
1050 return true;
1051 }
1052 currentElement = currentElement.parentElement;
1053 }
1054 return false;
1055 }
1056 /** Checks whether any of the chips is focused. */
1057 _hasFocusedChip() {
1058 return this.chips && this.chips.some(chip => chip._hasFocus);
1059 }
1060 /** Syncs the list's state with the individual chips. */
1061 _syncChipsState() {
1062 if (this.chips) {
1063 this.chips.forEach(chip => {
1064 chip._chipListDisabled = this._disabled;
1065 chip._chipListMultiple = this.multiple;
1066 });
1067 }
1068 }
1069}
1070MatChipList.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipList, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i1$1.Directionality, optional: true }, { token: i2.NgForm, optional: true }, { token: i2.FormGroupDirective, optional: true }, { token: i3.ErrorStateMatcher }, { token: i2.NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Component });
1071MatChipList.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.1", type: MatChipList, selector: "mat-chip-list", inputs: { role: "role", userAriaDescribedBy: ["aria-describedby", "userAriaDescribedBy"], errorStateMatcher: "errorStateMatcher", multiple: "multiple", compareWith: "compareWith", value: "value", required: "required", placeholder: "placeholder", disabled: "disabled", ariaOrientation: ["aria-orientation", "ariaOrientation"], selectable: "selectable", tabIndex: "tabIndex" }, outputs: { change: "change", valueChange: "valueChange" }, host: { listeners: { "focus": "focus()", "blur": "_blur()", "keydown": "_keydown($event)" }, properties: { "attr.tabindex": "disabled ? null : _tabIndex", "attr.aria-required": "role ? required : null", "attr.aria-disabled": "disabled.toString()", "attr.aria-invalid": "errorState", "attr.aria-multiselectable": "multiple", "attr.role": "role", "class.mat-chip-list-disabled": "disabled", "class.mat-chip-list-invalid": "errorState", "class.mat-chip-list-required": "required", "attr.aria-orientation": "ariaOrientation", "id": "_uid" }, classAttribute: "mat-chip-list" }, providers: [{ provide: MatFormFieldControl, useExisting: MatChipList }], queries: [{ propertyName: "chips", predicate: MatChip, descendants: true }], exportAs: ["matChipList"], usesInheritance: true, ngImport: i0, template: `<div class="mat-chip-list-wrapper"><ng-content></ng-content></div>`, isInline: true, styles: [".mat-chip{position:relative;box-sizing:border-box;-webkit-tap-highlight-color:rgba(0,0,0,0);border:none;-webkit-appearance:none;-moz-appearance:none}.mat-standard-chip{transition:box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1);display:inline-flex;padding:7px 12px;border-radius:16px;align-items:center;cursor:default;min-height:32px;height:1px}.mat-standard-chip._mat-animation-noopable{transition:none !important;animation:none !important}.mat-standard-chip .mat-chip-remove{border:none;-webkit-appearance:none;-moz-appearance:none;padding:0;background:none}.mat-standard-chip .mat-chip-remove.mat-icon,.mat-standard-chip .mat-chip-remove .mat-icon{width:18px;height:18px;font-size:18px}.mat-standard-chip::after{top:0;left:0;right:0;bottom:0;position:absolute;border-radius:inherit;opacity:0;content:\"\";pointer-events:none;transition:opacity 200ms cubic-bezier(0.35, 0, 0.25, 1)}.mat-standard-chip:hover::after{opacity:.12}.mat-standard-chip:focus{outline:none}.mat-standard-chip:focus::after{opacity:.16}.cdk-high-contrast-active .mat-standard-chip{outline:solid 1px}.cdk-high-contrast-active .mat-standard-chip:focus{outline:dotted 2px}.cdk-high-contrast-active .mat-standard-chip.mat-chip-selected{outline-width:3px}.mat-standard-chip.mat-chip-disabled::after{opacity:0}.mat-standard-chip.mat-chip-disabled .mat-chip-remove,.mat-standard-chip.mat-chip-disabled .mat-chip-trailing-icon{cursor:default}.mat-standard-chip.mat-chip-with-trailing-icon.mat-chip-with-avatar,.mat-standard-chip.mat-chip-with-avatar{padding-top:0;padding-bottom:0}.mat-standard-chip.mat-chip-with-trailing-icon.mat-chip-with-avatar{padding-right:8px;padding-left:0}[dir=rtl] .mat-standard-chip.mat-chip-with-trailing-icon.mat-chip-with-avatar{padding-left:8px;padding-right:0}.mat-standard-chip.mat-chip-with-trailing-icon{padding-top:7px;padding-bottom:7px;padding-right:8px;padding-left:12px}[dir=rtl] .mat-standard-chip.mat-chip-with-trailing-icon{padding-left:8px;padding-right:12px}.mat-standard-chip.mat-chip-with-avatar{padding-left:0;padding-right:12px}[dir=rtl] .mat-standard-chip.mat-chip-with-avatar{padding-right:0;padding-left:12px}.mat-standard-chip .mat-chip-avatar{width:24px;height:24px;margin-right:8px;margin-left:4px}[dir=rtl] .mat-standard-chip .mat-chip-avatar{margin-left:8px;margin-right:4px}.mat-standard-chip .mat-chip-remove,.mat-standard-chip .mat-chip-trailing-icon{width:18px;height:18px;cursor:pointer}.mat-standard-chip .mat-chip-remove,.mat-standard-chip .mat-chip-trailing-icon{margin-left:8px;margin-right:0}[dir=rtl] .mat-standard-chip .mat-chip-remove,[dir=rtl] .mat-standard-chip .mat-chip-trailing-icon{margin-right:8px;margin-left:0}.mat-chip-ripple{top:0;left:0;right:0;bottom:0;position:absolute;pointer-events:none;border-radius:inherit;overflow:hidden;transform:translateZ(0)}.mat-chip-list-wrapper{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;margin:-4px}.mat-chip-list-wrapper input.mat-input-element,.mat-chip-list-wrapper .mat-standard-chip{margin:4px}.mat-chip-list-stacked .mat-chip-list-wrapper{flex-direction:column;align-items:flex-start}.mat-chip-list-stacked .mat-chip-list-wrapper .mat-standard-chip{width:100%}.mat-chip-avatar{border-radius:50%;justify-content:center;align-items:center;display:flex;overflow:hidden;object-fit:cover}input.mat-chip-input{width:150px;margin:4px;flex:1 0 150px}"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1072i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipList, decorators: [{
1073 type: Component,
1074 args: [{ selector: 'mat-chip-list', template: `<div class="mat-chip-list-wrapper"><ng-content></ng-content></div>`, exportAs: 'matChipList', host: {
1075 '[attr.tabindex]': 'disabled ? null : _tabIndex',
1076 '[attr.aria-required]': 'role ? required : null',
1077 '[attr.aria-disabled]': 'disabled.toString()',
1078 '[attr.aria-invalid]': 'errorState',
1079 '[attr.aria-multiselectable]': 'multiple',
1080 '[attr.role]': 'role',
1081 '[class.mat-chip-list-disabled]': 'disabled',
1082 '[class.mat-chip-list-invalid]': 'errorState',
1083 '[class.mat-chip-list-required]': 'required',
1084 '[attr.aria-orientation]': 'ariaOrientation',
1085 'class': 'mat-chip-list',
1086 '(focus)': 'focus()',
1087 '(blur)': '_blur()',
1088 '(keydown)': '_keydown($event)',
1089 '[id]': '_uid',
1090 }, providers: [{ provide: MatFormFieldControl, useExisting: MatChipList }], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, styles: [".mat-chip{position:relative;box-sizing:border-box;-webkit-tap-highlight-color:rgba(0,0,0,0);border:none;-webkit-appearance:none;-moz-appearance:none}.mat-standard-chip{transition:box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1);display:inline-flex;padding:7px 12px;border-radius:16px;align-items:center;cursor:default;min-height:32px;height:1px}.mat-standard-chip._mat-animation-noopable{transition:none !important;animation:none !important}.mat-standard-chip .mat-chip-remove{border:none;-webkit-appearance:none;-moz-appearance:none;padding:0;background:none}.mat-standard-chip .mat-chip-remove.mat-icon,.mat-standard-chip .mat-chip-remove .mat-icon{width:18px;height:18px;font-size:18px}.mat-standard-chip::after{top:0;left:0;right:0;bottom:0;position:absolute;border-radius:inherit;opacity:0;content:\"\";pointer-events:none;transition:opacity 200ms cubic-bezier(0.35, 0, 0.25, 1)}.mat-standard-chip:hover::after{opacity:.12}.mat-standard-chip:focus{outline:none}.mat-standard-chip:focus::after{opacity:.16}.cdk-high-contrast-active .mat-standard-chip{outline:solid 1px}.cdk-high-contrast-active .mat-standard-chip:focus{outline:dotted 2px}.cdk-high-contrast-active .mat-standard-chip.mat-chip-selected{outline-width:3px}.mat-standard-chip.mat-chip-disabled::after{opacity:0}.mat-standard-chip.mat-chip-disabled .mat-chip-remove,.mat-standard-chip.mat-chip-disabled .mat-chip-trailing-icon{cursor:default}.mat-standard-chip.mat-chip-with-trailing-icon.mat-chip-with-avatar,.mat-standard-chip.mat-chip-with-avatar{padding-top:0;padding-bottom:0}.mat-standard-chip.mat-chip-with-trailing-icon.mat-chip-with-avatar{padding-right:8px;padding-left:0}[dir=rtl] .mat-standard-chip.mat-chip-with-trailing-icon.mat-chip-with-avatar{padding-left:8px;padding-right:0}.mat-standard-chip.mat-chip-with-trailing-icon{padding-top:7px;padding-bottom:7px;padding-right:8px;padding-left:12px}[dir=rtl] .mat-standard-chip.mat-chip-with-trailing-icon{padding-left:8px;padding-right:12px}.mat-standard-chip.mat-chip-with-avatar{padding-left:0;padding-right:12px}[dir=rtl] .mat-standard-chip.mat-chip-with-avatar{padding-right:0;padding-left:12px}.mat-standard-chip .mat-chip-avatar{width:24px;height:24px;margin-right:8px;margin-left:4px}[dir=rtl] .mat-standard-chip .mat-chip-avatar{margin-left:8px;margin-right:4px}.mat-standard-chip .mat-chip-remove,.mat-standard-chip .mat-chip-trailing-icon{width:18px;height:18px;cursor:pointer}.mat-standard-chip .mat-chip-remove,.mat-standard-chip .mat-chip-trailing-icon{margin-left:8px;margin-right:0}[dir=rtl] .mat-standard-chip .mat-chip-remove,[dir=rtl] .mat-standard-chip .mat-chip-trailing-icon{margin-right:8px;margin-left:0}.mat-chip-ripple{top:0;left:0;right:0;bottom:0;position:absolute;pointer-events:none;border-radius:inherit;overflow:hidden;transform:translateZ(0)}.mat-chip-list-wrapper{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;margin:-4px}.mat-chip-list-wrapper input.mat-input-element,.mat-chip-list-wrapper .mat-standard-chip{margin:4px}.mat-chip-list-stacked .mat-chip-list-wrapper{flex-direction:column;align-items:flex-start}.mat-chip-list-stacked .mat-chip-list-wrapper .mat-standard-chip{width:100%}.mat-chip-avatar{border-radius:50%;justify-content:center;align-items:center;display:flex;overflow:hidden;object-fit:cover}input.mat-chip-input{width:150px;margin:4px;flex:1 0 150px}"] }]
1091 }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i1$1.Directionality, decorators: [{
1092 type: Optional
1093 }] }, { type: i2.NgForm, decorators: [{
1094 type: Optional
1095 }] }, { type: i2.FormGroupDirective, decorators: [{
1096 type: Optional
1097 }] }, { type: i3.ErrorStateMatcher }, { type: i2.NgControl, decorators: [{
1098 type: Optional
1099 }, {
1100 type: Self
1101 }] }]; }, propDecorators: { role: [{
1102 type: Input
1103 }], userAriaDescribedBy: [{
1104 type: Input,
1105 args: ['aria-describedby']
1106 }], errorStateMatcher: [{
1107 type: Input
1108 }], multiple: [{
1109 type: Input
1110 }], compareWith: [{
1111 type: Input
1112 }], value: [{
1113 type: Input
1114 }], required: [{
1115 type: Input
1116 }], placeholder: [{
1117 type: Input
1118 }], disabled: [{
1119 type: Input
1120 }], ariaOrientation: [{
1121 type: Input,
1122 args: ['aria-orientation']
1123 }], selectable: [{
1124 type: Input
1125 }], tabIndex: [{
1126 type: Input
1127 }], change: [{
1128 type: Output
1129 }], valueChange: [{
1130 type: Output
1131 }], chips: [{
1132 type: ContentChildren,
1133 args: [MatChip, {
1134 // We need to use `descendants: true`, because Ivy will no longer match
1135 // indirect descendants if it's left as false.
1136 descendants: true,
1137 }]
1138 }] } });
1139
1140/**
1141 * @license
1142 * Copyright Google LLC All Rights Reserved.
1143 *
1144 * Use of this source code is governed by an MIT-style license that can be
1145 * found in the LICENSE file at https://angular.io/license
1146 */
1147// Increasing integer for generating unique ids.
1148let nextUniqueId = 0;
1149/**
1150 * Directive that adds chip-specific behaviors to an input element inside `<mat-form-field>`.
1151 * May be placed inside or outside of an `<mat-chip-list>`.
1152 */
1153class MatChipInput {
1154 constructor(_elementRef, _defaultOptions) {
1155 this._elementRef = _elementRef;
1156 this._defaultOptions = _defaultOptions;
1157 /** Whether the control is focused. */
1158 this.focused = false;
1159 this._addOnBlur = false;
1160 /**
1161 * The list of key codes that will trigger a chipEnd event.
1162 *
1163 * Defaults to `[ENTER]`.
1164 */
1165 this.separatorKeyCodes = this._defaultOptions.separatorKeyCodes;
1166 /** Emitted when a chip is to be added. */
1167 this.chipEnd = new EventEmitter();
1168 /** The input's placeholder text. */
1169 this.placeholder = '';
1170 /** Unique id for the input. */
1171 this.id = `mat-chip-list-input-${nextUniqueId++}`;
1172 this._disabled = false;
1173 this.inputElement = this._elementRef.nativeElement;
1174 }
1175 /** Register input for chip list */
1176 set chipList(value) {
1177 if (value) {
1178 this._chipList = value;
1179 this._chipList.registerInput(this);
1180 }
1181 }
1182 /**
1183 * Whether or not the chipEnd event will be emitted when the input is blurred.
1184 */
1185 get addOnBlur() {
1186 return this._addOnBlur;
1187 }
1188 set addOnBlur(value) {
1189 this._addOnBlur = coerceBooleanProperty(value);
1190 }
1191 /** Whether the input is disabled. */
1192 get disabled() {
1193 return this._disabled || (this._chipList && this._chipList.disabled);
1194 }
1195 set disabled(value) {
1196 this._disabled = coerceBooleanProperty(value);
1197 }
1198 /** Whether the input is empty. */
1199 get empty() {
1200 return !this.inputElement.value;
1201 }
1202 ngOnChanges() {
1203 this._chipList.stateChanges.next();
1204 }
1205 ngOnDestroy() {
1206 this.chipEnd.complete();
1207 }
1208 ngAfterContentInit() {
1209 this._focusLastChipOnBackspace = this.empty;
1210 }
1211 /** Utility method to make host definition/tests more clear. */
1212 _keydown(event) {
1213 if (event) {
1214 // Allow the user's focus to escape when they're tabbing forward. Note that we don't
1215 // want to do this when going backwards, because focus should go back to the first chip.
1216 if (event.keyCode === TAB && !hasModifierKey(event, 'shiftKey')) {
1217 this._chipList._allowFocusEscape();
1218 }
1219 // To prevent the user from accidentally deleting chips when pressing BACKSPACE continuously,
1220 // We focus the last chip on backspace only after the user has released the backspace button,
1221 // and the input is empty (see behaviour in _keyup)
1222 if (event.keyCode === BACKSPACE && this._focusLastChipOnBackspace) {
1223 this._chipList._keyManager.setLastItemActive();
1224 event.preventDefault();
1225 return;
1226 }
1227 else {
1228 this._focusLastChipOnBackspace = false;
1229 }
1230 }
1231 this._emitChipEnd(event);
1232 }
1233 /**
1234 * Pass events to the keyboard manager. Available here for tests.
1235 */
1236 _keyup(event) {
1237 // Allow user to move focus to chips next time he presses backspace
1238 if (!this._focusLastChipOnBackspace && event.keyCode === BACKSPACE && this.empty) {
1239 this._focusLastChipOnBackspace = true;
1240 event.preventDefault();
1241 }
1242 }
1243 /** Checks to see if the blur should emit the (chipEnd) event. */
1244 _blur() {
1245 if (this.addOnBlur) {
1246 this._emitChipEnd();
1247 }
1248 this.focused = false;
1249 // Blur the chip list if it is not focused
1250 if (!this._chipList.focused) {
1251 this._chipList._blur();
1252 }
1253 this._chipList.stateChanges.next();
1254 }
1255 _focus() {
1256 this.focused = true;
1257 this._focusLastChipOnBackspace = this.empty;
1258 this._chipList.stateChanges.next();
1259 }
1260 /** Checks to see if the (chipEnd) event needs to be emitted. */
1261 _emitChipEnd(event) {
1262 if (!this.inputElement.value && !!event) {
1263 this._chipList._keydown(event);
1264 }
1265 if (!event || this._isSeparatorKey(event)) {
1266 this.chipEnd.emit({
1267 input: this.inputElement,
1268 value: this.inputElement.value,
1269 chipInput: this,
1270 });
1271 event?.preventDefault();
1272 }
1273 }
1274 _onInput() {
1275 // Let chip list know whenever the value changes.
1276 this._chipList.stateChanges.next();
1277 }
1278 /** Focuses the input. */
1279 focus(options) {
1280 this.inputElement.focus(options);
1281 }
1282 /** Clears the input */
1283 clear() {
1284 this.inputElement.value = '';
1285 this._focusLastChipOnBackspace = true;
1286 }
1287 /** Checks whether a keycode is one of the configured separators. */
1288 _isSeparatorKey(event) {
1289 return !hasModifierKey(event) && new Set(this.separatorKeyCodes).has(event.keyCode);
1290 }
1291}
1292MatChipInput.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipInput, deps: [{ token: i0.ElementRef }, { token: MAT_CHIPS_DEFAULT_OPTIONS }], target: i0.ɵɵFactoryTarget.Directive });
1293MatChipInput.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: MatChipInput, selector: "input[matChipInputFor]", inputs: { chipList: ["matChipInputFor", "chipList"], addOnBlur: ["matChipInputAddOnBlur", "addOnBlur"], separatorKeyCodes: ["matChipInputSeparatorKeyCodes", "separatorKeyCodes"], placeholder: "placeholder", id: "id", disabled: "disabled" }, outputs: { chipEnd: "matChipInputTokenEnd" }, host: { listeners: { "keydown": "_keydown($event)", "keyup": "_keyup($event)", "blur": "_blur()", "focus": "_focus()", "input": "_onInput()" }, properties: { "id": "id", "attr.disabled": "disabled || null", "attr.placeholder": "placeholder || null", "attr.aria-invalid": "_chipList && _chipList.ngControl ? _chipList.ngControl.invalid : null", "attr.aria-required": "_chipList && _chipList.required || null" }, classAttribute: "mat-chip-input mat-input-element" }, exportAs: ["matChipInput", "matChipInputFor"], usesOnChanges: true, ngImport: i0 });
1294i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipInput, decorators: [{
1295 type: Directive,
1296 args: [{
1297 selector: 'input[matChipInputFor]',
1298 exportAs: 'matChipInput, matChipInputFor',
1299 host: {
1300 'class': 'mat-chip-input mat-input-element',
1301 '(keydown)': '_keydown($event)',
1302 '(keyup)': '_keyup($event)',
1303 '(blur)': '_blur()',
1304 '(focus)': '_focus()',
1305 '(input)': '_onInput()',
1306 '[id]': 'id',
1307 '[attr.disabled]': 'disabled || null',
1308 '[attr.placeholder]': 'placeholder || null',
1309 '[attr.aria-invalid]': '_chipList && _chipList.ngControl ? _chipList.ngControl.invalid : null',
1310 '[attr.aria-required]': '_chipList && _chipList.required || null',
1311 },
1312 }]
1313 }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: undefined, decorators: [{
1314 type: Inject,
1315 args: [MAT_CHIPS_DEFAULT_OPTIONS]
1316 }] }]; }, propDecorators: { chipList: [{
1317 type: Input,
1318 args: ['matChipInputFor']
1319 }], addOnBlur: [{
1320 type: Input,
1321 args: ['matChipInputAddOnBlur']
1322 }], separatorKeyCodes: [{
1323 type: Input,
1324 args: ['matChipInputSeparatorKeyCodes']
1325 }], chipEnd: [{
1326 type: Output,
1327 args: ['matChipInputTokenEnd']
1328 }], placeholder: [{
1329 type: Input
1330 }], id: [{
1331 type: Input
1332 }], disabled: [{
1333 type: Input
1334 }] } });
1335
1336/**
1337 * @license
1338 * Copyright Google LLC All Rights Reserved.
1339 *
1340 * Use of this source code is governed by an MIT-style license that can be
1341 * found in the LICENSE file at https://angular.io/license
1342 */
1343const CHIP_DECLARATIONS = [
1344 MatChipList,
1345 MatChip,
1346 MatChipInput,
1347 MatChipRemove,
1348 MatChipAvatar,
1349 MatChipTrailingIcon,
1350];
1351class MatChipsModule {
1352}
1353MatChipsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1354MatChipsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, declarations: [MatChipList,
1355 MatChip,
1356 MatChipInput,
1357 MatChipRemove,
1358 MatChipAvatar,
1359 MatChipTrailingIcon], imports: [MatCommonModule], exports: [MatChipList,
1360 MatChip,
1361 MatChipInput,
1362 MatChipRemove,
1363 MatChipAvatar,
1364 MatChipTrailingIcon] });
1365MatChipsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, providers: [
1366 ErrorStateMatcher,
1367 {
1368 provide: MAT_CHIPS_DEFAULT_OPTIONS,
1369 useValue: {
1370 separatorKeyCodes: [ENTER],
1371 },
1372 },
1373 ], imports: [MatCommonModule] });
1374i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, decorators: [{
1375 type: NgModule,
1376 args: [{
1377 imports: [MatCommonModule],
1378 exports: CHIP_DECLARATIONS,
1379 declarations: CHIP_DECLARATIONS,
1380 providers: [
1381 ErrorStateMatcher,
1382 {
1383 provide: MAT_CHIPS_DEFAULT_OPTIONS,
1384 useValue: {
1385 separatorKeyCodes: [ENTER],
1386 },
1387 },
1388 ],
1389 }]
1390 }] });
1391
1392/**
1393 * @license
1394 * Copyright Google LLC All Rights Reserved.
1395 *
1396 * Use of this source code is governed by an MIT-style license that can be
1397 * found in the LICENSE file at https://angular.io/license
1398 */
1399
1400/**
1401 * @license
1402 * Copyright Google LLC All Rights Reserved.
1403 *
1404 * Use of this source code is governed by an MIT-style license that can be
1405 * found in the LICENSE file at https://angular.io/license
1406 */
1407
1408/**
1409 * Generated bundle index. Do not edit.
1410 */
1411
1412export { MAT_CHIPS_DEFAULT_OPTIONS, MAT_CHIP_AVATAR, MAT_CHIP_REMOVE, MAT_CHIP_TRAILING_ICON, MatChip, MatChipAvatar, MatChipInput, MatChipList, MatChipListChange, MatChipRemove, MatChipSelectionChange, MatChipTrailingIcon, MatChipsModule };
1413//# sourceMappingURL=chips.mjs.map