UNPKG

68 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 { DOCUMENT } from '@angular/common';
8import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
9import { Subject, merge } from 'rxjs';
10import { take, takeUntil, startWith } from 'rxjs/operators';
11import * as i1 from '@angular/cdk/platform';
12import { FocusKeyManager } from '@angular/cdk/a11y';
13import { SelectionModel } from '@angular/cdk/collections';
14import * as i2 from '@angular/forms';
15import { Validators } from '@angular/forms';
16import { MatFormFieldControl } from '@angular/material/form-field';
17import * as i1$1 from '@angular/cdk/bidi';
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 () {
340 return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: i1.Platform }, { type: undefined, decorators: [{
341 type: Optional
342 }, {
343 type: Inject,
344 args: [MAT_RIPPLE_GLOBAL_OPTIONS]
345 }] }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
346 type: Inject,
347 args: [DOCUMENT]
348 }] }, { type: undefined, decorators: [{
349 type: Optional
350 }, {
351 type: Inject,
352 args: [ANIMATION_MODULE_TYPE]
353 }] }, { type: undefined, decorators: [{
354 type: Attribute,
355 args: ['tabindex']
356 }] }];
357 }, propDecorators: { avatar: [{
358 type: ContentChild,
359 args: [MAT_CHIP_AVATAR]
360 }], trailingIcon: [{
361 type: ContentChild,
362 args: [MAT_CHIP_TRAILING_ICON]
363 }], removeIcon: [{
364 type: ContentChild,
365 args: [MAT_CHIP_REMOVE]
366 }], role: [{
367 type: Input
368 }], selected: [{
369 type: Input
370 }], value: [{
371 type: Input
372 }], selectable: [{
373 type: Input
374 }], disabled: [{
375 type: Input
376 }], removable: [{
377 type: Input
378 }], selectionChange: [{
379 type: Output
380 }], destroyed: [{
381 type: Output
382 }], removed: [{
383 type: Output
384 }] } });
385/**
386 * Applies proper (click) support and adds styling for use with the Material Design "cancel" icon
387 * available at https://material.io/icons/#ic_cancel.
388 *
389 * Example:
390 *
391 * `<mat-chip>
392 * <mat-icon matChipRemove>cancel</mat-icon>
393 * </mat-chip>`
394 *
395 * You *may* use a custom icon, but you may need to override the `mat-chip-remove` positioning
396 * styles to properly center the icon within the chip.
397 */
398class MatChipRemove {
399 constructor(_parentChip, elementRef) {
400 this._parentChip = _parentChip;
401 if (elementRef.nativeElement.nodeName === 'BUTTON') {
402 elementRef.nativeElement.setAttribute('type', 'button');
403 }
404 }
405 /** Calls the parent chip's public `remove()` method if applicable. */
406 _handleClick(event) {
407 const parentChip = this._parentChip;
408 if (parentChip.removable && !parentChip.disabled) {
409 parentChip.remove();
410 }
411 // We need to stop event propagation because otherwise the event will bubble up to the
412 // form field and cause the `onContainerClick` method to be invoked. This method would then
413 // reset the focused chip that has been focused after chip removal. Usually the parent
414 // the parent click listener of the `MatChip` would prevent propagation, but it can happen
415 // that the chip is being removed before the event bubbles up.
416 event.stopPropagation();
417 event.preventDefault();
418 }
419}
420MatChipRemove.ɵ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 });
421MatChipRemove.ɵ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 });
422i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipRemove, decorators: [{
423 type: Directive,
424 args: [{
425 selector: '[matChipRemove]',
426 host: {
427 'class': 'mat-chip-remove mat-chip-trailing-icon',
428 '(click)': '_handleClick($event)',
429 },
430 providers: [{ provide: MAT_CHIP_REMOVE, useExisting: MatChipRemove }],
431 }]
432 }], ctorParameters: function () { return [{ type: MatChip }, { type: i0.ElementRef }]; } });
433
434/**
435 * @license
436 * Copyright Google LLC All Rights Reserved.
437 *
438 * Use of this source code is governed by an MIT-style license that can be
439 * found in the LICENSE file at https://angular.io/license
440 */
441/** Injection token to be used to override the default options for the chips module. */
442const MAT_CHIPS_DEFAULT_OPTIONS = new InjectionToken('mat-chips-default-options');
443
444/**
445 * @license
446 * Copyright Google LLC All Rights Reserved.
447 *
448 * Use of this source code is governed by an MIT-style license that can be
449 * found in the LICENSE file at https://angular.io/license
450 */
451// Increasing integer for generating unique ids.
452let nextUniqueId$1 = 0;
453/**
454 * Directive that adds chip-specific behaviors to an input element inside `<mat-form-field>`.
455 * May be placed inside or outside of an `<mat-chip-list>`.
456 */
457class MatChipInput {
458 constructor(_elementRef, _defaultOptions) {
459 this._elementRef = _elementRef;
460 this._defaultOptions = _defaultOptions;
461 /** Whether the control is focused. */
462 this.focused = false;
463 this._addOnBlur = false;
464 /**
465 * The list of key codes that will trigger a chipEnd event.
466 *
467 * Defaults to `[ENTER]`.
468 */
469 this.separatorKeyCodes = this._defaultOptions.separatorKeyCodes;
470 /** Emitted when a chip is to be added. */
471 this.chipEnd = new EventEmitter();
472 /** The input's placeholder text. */
473 this.placeholder = '';
474 /** Unique id for the input. */
475 this.id = `mat-chip-list-input-${nextUniqueId$1++}`;
476 this._disabled = false;
477 this.inputElement = this._elementRef.nativeElement;
478 }
479 /** Register input for chip list */
480 set chipList(value) {
481 if (value) {
482 this._chipList = value;
483 this._chipList.registerInput(this);
484 }
485 }
486 /**
487 * Whether or not the chipEnd event will be emitted when the input is blurred.
488 */
489 get addOnBlur() {
490 return this._addOnBlur;
491 }
492 set addOnBlur(value) {
493 this._addOnBlur = coerceBooleanProperty(value);
494 }
495 /** Whether the input is disabled. */
496 get disabled() {
497 return this._disabled || (this._chipList && this._chipList.disabled);
498 }
499 set disabled(value) {
500 this._disabled = coerceBooleanProperty(value);
501 }
502 /** Whether the input is empty. */
503 get empty() {
504 return !this.inputElement.value;
505 }
506 ngOnChanges() {
507 this._chipList.stateChanges.next();
508 }
509 ngOnDestroy() {
510 this.chipEnd.complete();
511 }
512 ngAfterContentInit() {
513 this._focusLastChipOnBackspace = this.empty;
514 }
515 /** Utility method to make host definition/tests more clear. */
516 _keydown(event) {
517 if (event) {
518 // Allow the user's focus to escape when they're tabbing forward. Note that we don't
519 // want to do this when going backwards, because focus should go back to the first chip.
520 if (event.keyCode === TAB && !hasModifierKey(event, 'shiftKey')) {
521 this._chipList._allowFocusEscape();
522 }
523 // To prevent the user from accidentally deleting chips when pressing BACKSPACE continuously,
524 // We focus the last chip on backspace only after the user has released the backspace button,
525 // and the input is empty (see behaviour in _keyup)
526 if (event.keyCode === BACKSPACE && this._focusLastChipOnBackspace) {
527 this._chipList._keyManager.setLastItemActive();
528 event.preventDefault();
529 return;
530 }
531 else {
532 this._focusLastChipOnBackspace = false;
533 }
534 }
535 this._emitChipEnd(event);
536 }
537 /**
538 * Pass events to the keyboard manager. Available here for tests.
539 */
540 _keyup(event) {
541 // Allow user to move focus to chips next time he presses backspace
542 if (!this._focusLastChipOnBackspace && event.keyCode === BACKSPACE && this.empty) {
543 this._focusLastChipOnBackspace = true;
544 event.preventDefault();
545 }
546 }
547 /** Checks to see if the blur should emit the (chipEnd) event. */
548 _blur() {
549 if (this.addOnBlur) {
550 this._emitChipEnd();
551 }
552 this.focused = false;
553 // Blur the chip list if it is not focused
554 if (!this._chipList.focused) {
555 this._chipList._blur();
556 }
557 this._chipList.stateChanges.next();
558 }
559 _focus() {
560 this.focused = true;
561 this._focusLastChipOnBackspace = this.empty;
562 this._chipList.stateChanges.next();
563 }
564 /** Checks to see if the (chipEnd) event needs to be emitted. */
565 _emitChipEnd(event) {
566 if (!this.inputElement.value && !!event) {
567 this._chipList._keydown(event);
568 }
569 if (!event || this._isSeparatorKey(event)) {
570 this.chipEnd.emit({
571 input: this.inputElement,
572 value: this.inputElement.value,
573 chipInput: this,
574 });
575 event === null || event === void 0 ? void 0 : event.preventDefault();
576 }
577 }
578 _onInput() {
579 // Let chip list know whenever the value changes.
580 this._chipList.stateChanges.next();
581 }
582 /** Focuses the input. */
583 focus(options) {
584 this.inputElement.focus(options);
585 }
586 /** Clears the input */
587 clear() {
588 this.inputElement.value = '';
589 this._focusLastChipOnBackspace = true;
590 }
591 /** Checks whether a keycode is one of the configured separators. */
592 _isSeparatorKey(event) {
593 return !hasModifierKey(event) && new Set(this.separatorKeyCodes).has(event.keyCode);
594 }
595}
596MatChipInput.ɵ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 });
597MatChipInput.ɵ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 });
598i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipInput, decorators: [{
599 type: Directive,
600 args: [{
601 selector: 'input[matChipInputFor]',
602 exportAs: 'matChipInput, matChipInputFor',
603 host: {
604 'class': 'mat-chip-input mat-input-element',
605 '(keydown)': '_keydown($event)',
606 '(keyup)': '_keyup($event)',
607 '(blur)': '_blur()',
608 '(focus)': '_focus()',
609 '(input)': '_onInput()',
610 '[id]': 'id',
611 '[attr.disabled]': 'disabled || null',
612 '[attr.placeholder]': 'placeholder || null',
613 '[attr.aria-invalid]': '_chipList && _chipList.ngControl ? _chipList.ngControl.invalid : null',
614 '[attr.aria-required]': '_chipList && _chipList.required || null',
615 },
616 }]
617 }], ctorParameters: function () {
618 return [{ type: i0.ElementRef }, { type: undefined, decorators: [{
619 type: Inject,
620 args: [MAT_CHIPS_DEFAULT_OPTIONS]
621 }] }];
622 }, propDecorators: { chipList: [{
623 type: Input,
624 args: ['matChipInputFor']
625 }], addOnBlur: [{
626 type: Input,
627 args: ['matChipInputAddOnBlur']
628 }], separatorKeyCodes: [{
629 type: Input,
630 args: ['matChipInputSeparatorKeyCodes']
631 }], chipEnd: [{
632 type: Output,
633 args: ['matChipInputTokenEnd']
634 }], placeholder: [{
635 type: Input
636 }], id: [{
637 type: Input
638 }], disabled: [{
639 type: Input
640 }] } });
641
642/**
643 * @license
644 * Copyright Google LLC All Rights Reserved.
645 *
646 * Use of this source code is governed by an MIT-style license that can be
647 * found in the LICENSE file at https://angular.io/license
648 */
649// Boilerplate for applying mixins to MatChipList.
650/** @docs-private */
651const _MatChipListBase = mixinErrorState(class {
652 constructor(_defaultErrorStateMatcher, _parentForm, _parentFormGroup,
653 /**
654 * Form control bound to the component.
655 * Implemented as part of `MatFormFieldControl`.
656 * @docs-private
657 */
658 ngControl) {
659 this._defaultErrorStateMatcher = _defaultErrorStateMatcher;
660 this._parentForm = _parentForm;
661 this._parentFormGroup = _parentFormGroup;
662 this.ngControl = ngControl;
663 /**
664 * Emits whenever the component state changes and should cause the parent
665 * form-field to update. Implemented as part of `MatFormFieldControl`.
666 * @docs-private
667 */
668 this.stateChanges = new Subject();
669 }
670});
671// Increasing integer for generating unique ids for chip-list components.
672let nextUniqueId = 0;
673/** Change event object that is emitted when the chip list value has changed. */
674class MatChipListChange {
675 constructor(
676 /** Chip list that emitted the event. */
677 source,
678 /** Value of the chip list when the event was emitted. */
679 value) {
680 this.source = source;
681 this.value = value;
682 }
683}
684/**
685 * A material design chips component (named ChipList for its similarity to the List component).
686 */
687class MatChipList extends _MatChipListBase {
688 constructor(_elementRef, _changeDetectorRef, _dir, _parentForm, _parentFormGroup, _defaultErrorStateMatcher, ngControl) {
689 super(_defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl);
690 this._elementRef = _elementRef;
691 this._changeDetectorRef = _changeDetectorRef;
692 this._dir = _dir;
693 /**
694 * Implemented as part of MatFormFieldControl.
695 * @docs-private
696 */
697 this.controlType = 'mat-chip-list';
698 /**
699 * When a chip is destroyed, we store the index of the destroyed chip until the chips
700 * query list notifies about the update. This is necessary because we cannot determine an
701 * appropriate chip that should receive focus until the array of chips updated completely.
702 */
703 this._lastDestroyedChipIndex = null;
704 /** Subject that emits when the component has been destroyed. */
705 this._destroyed = new Subject();
706 /** Uid of the chip list */
707 this._uid = `mat-chip-list-${nextUniqueId++}`;
708 /** Tab index for the chip list. */
709 this._tabIndex = 0;
710 /**
711 * User defined tab index.
712 * When it is not null, use user defined tab index. Otherwise use _tabIndex
713 */
714 this._userTabIndex = null;
715 /** Function when touched */
716 this._onTouched = () => { };
717 /** Function when changed */
718 this._onChange = () => { };
719 this._multiple = false;
720 this._compareWith = (o1, o2) => o1 === o2;
721 this._disabled = false;
722 /** Orientation of the chip list. */
723 this.ariaOrientation = 'horizontal';
724 this._selectable = true;
725 /** Event emitted when the selected chip list value has been changed by the user. */
726 this.change = new EventEmitter();
727 /**
728 * Event that emits whenever the raw value of the chip-list changes. This is here primarily
729 * to facilitate the two-way binding for the `value` input.
730 * @docs-private
731 */
732 this.valueChange = new EventEmitter();
733 if (this.ngControl) {
734 this.ngControl.valueAccessor = this;
735 }
736 }
737 /** The array of selected chips inside chip list. */
738 get selected() {
739 var _a, _b;
740 return this.multiple ? ((_a = this._selectionModel) === null || _a === void 0 ? void 0 : _a.selected) || [] : (_b = this._selectionModel) === null || _b === void 0 ? void 0 : _b.selected[0];
741 }
742 /** The ARIA role applied to the chip list. */
743 get role() {
744 if (this._explicitRole) {
745 return this._explicitRole;
746 }
747 return this.empty ? null : 'listbox';
748 }
749 set role(role) {
750 this._explicitRole = role;
751 }
752 /** Whether the user should be allowed to select multiple chips. */
753 get multiple() {
754 return this._multiple;
755 }
756 set multiple(value) {
757 this._multiple = coerceBooleanProperty(value);
758 this._syncChipsState();
759 }
760 /**
761 * A function to compare the option values with the selected values. The first argument
762 * is a value from an option. The second is a value from the selection. A boolean
763 * should be returned.
764 */
765 get compareWith() {
766 return this._compareWith;
767 }
768 set compareWith(fn) {
769 this._compareWith = fn;
770 if (this._selectionModel) {
771 // A different comparator means the selection could change.
772 this._initializeSelection();
773 }
774 }
775 /**
776 * Implemented as part of MatFormFieldControl.
777 * @docs-private
778 */
779 get value() {
780 return this._value;
781 }
782 set value(value) {
783 this.writeValue(value);
784 this._value = value;
785 }
786 /**
787 * Implemented as part of MatFormFieldControl.
788 * @docs-private
789 */
790 get id() {
791 return this._chipInput ? this._chipInput.id : this._uid;
792 }
793 /**
794 * Implemented as part of MatFormFieldControl.
795 * @docs-private
796 */
797 get required() {
798 var _a, _b, _c, _d;
799 return (_d = (_a = this._required) !== null && _a !== void 0 ? _a : (_c = (_b = this.ngControl) === null || _b === void 0 ? void 0 : _b.control) === null || _c === void 0 ? void 0 : _c.hasValidator(Validators.required)) !== null && _d !== void 0 ? _d : false;
800 }
801 set required(value) {
802 this._required = coerceBooleanProperty(value);
803 this.stateChanges.next();
804 }
805 /**
806 * Implemented as part of MatFormFieldControl.
807 * @docs-private
808 */
809 get placeholder() {
810 return this._chipInput ? this._chipInput.placeholder : this._placeholder;
811 }
812 set placeholder(value) {
813 this._placeholder = value;
814 this.stateChanges.next();
815 }
816 /** Whether any chips or the matChipInput inside of this chip-list has focus. */
817 get focused() {
818 return (this._chipInput && this._chipInput.focused) || this._hasFocusedChip();
819 }
820 /**
821 * Implemented as part of MatFormFieldControl.
822 * @docs-private
823 */
824 get empty() {
825 return (!this._chipInput || this._chipInput.empty) && (!this.chips || this.chips.length === 0);
826 }
827 /**
828 * Implemented as part of MatFormFieldControl.
829 * @docs-private
830 */
831 get shouldLabelFloat() {
832 return !this.empty || this.focused;
833 }
834 /**
835 * Implemented as part of MatFormFieldControl.
836 * @docs-private
837 */
838 get disabled() {
839 return this.ngControl ? !!this.ngControl.disabled : this._disabled;
840 }
841 set disabled(value) {
842 this._disabled = coerceBooleanProperty(value);
843 this._syncChipsState();
844 }
845 /**
846 * Whether or not this chip list is selectable. When a chip list is not selectable,
847 * the selected states for all the chips inside the chip list are always ignored.
848 */
849 get selectable() {
850 return this._selectable;
851 }
852 set selectable(value) {
853 this._selectable = coerceBooleanProperty(value);
854 if (this.chips) {
855 this.chips.forEach(chip => (chip.chipListSelectable = this._selectable));
856 }
857 }
858 set tabIndex(value) {
859 this._userTabIndex = value;
860 this._tabIndex = value;
861 }
862 /** Combined stream of all of the child chips' selection change events. */
863 get chipSelectionChanges() {
864 return merge(...this.chips.map(chip => chip.selectionChange));
865 }
866 /** Combined stream of all of the child chips' focus change events. */
867 get chipFocusChanges() {
868 return merge(...this.chips.map(chip => chip._onFocus));
869 }
870 /** Combined stream of all of the child chips' blur change events. */
871 get chipBlurChanges() {
872 return merge(...this.chips.map(chip => chip._onBlur));
873 }
874 /** Combined stream of all of the child chips' remove change events. */
875 get chipRemoveChanges() {
876 return merge(...this.chips.map(chip => chip.destroyed));
877 }
878 ngAfterContentInit() {
879 this._keyManager = new FocusKeyManager(this.chips)
880 .withWrap()
881 .withVerticalOrientation()
882 .withHomeAndEnd()
883 .withHorizontalOrientation(this._dir ? this._dir.value : 'ltr');
884 if (this._dir) {
885 this._dir.change
886 .pipe(takeUntil(this._destroyed))
887 .subscribe(dir => this._keyManager.withHorizontalOrientation(dir));
888 }
889 this._keyManager.tabOut.pipe(takeUntil(this._destroyed)).subscribe(() => {
890 this._allowFocusEscape();
891 });
892 // When the list changes, re-subscribe
893 this.chips.changes.pipe(startWith(null), takeUntil(this._destroyed)).subscribe(() => {
894 if (this.disabled) {
895 // Since this happens after the content has been
896 // checked, we need to defer it to the next tick.
897 Promise.resolve().then(() => {
898 this._syncChipsState();
899 });
900 }
901 this._resetChips();
902 // Reset chips selected/deselected status
903 this._initializeSelection();
904 // Check to see if we need to update our tab index
905 this._updateTabIndex();
906 // Check to see if we have a destroyed chip and need to refocus
907 this._updateFocusForDestroyedChips();
908 this.stateChanges.next();
909 });
910 }
911 ngOnInit() {
912 this._selectionModel = new SelectionModel(this.multiple, undefined, false);
913 this.stateChanges.next();
914 }
915 ngDoCheck() {
916 if (this.ngControl) {
917 // We need to re-evaluate this on every change detection cycle, because there are some
918 // error triggers that we can't subscribe to (e.g. parent form submissions). This means
919 // that whatever logic is in here has to be super lean or we risk destroying the performance.
920 this.updateErrorState();
921 if (this.ngControl.disabled !== this._disabled) {
922 this.disabled = !!this.ngControl.disabled;
923 }
924 }
925 }
926 ngOnDestroy() {
927 this._destroyed.next();
928 this._destroyed.complete();
929 this.stateChanges.complete();
930 this._dropSubscriptions();
931 }
932 /** Associates an HTML input element with this chip list. */
933 registerInput(inputElement) {
934 this._chipInput = inputElement;
935 // We use this attribute to match the chip list to its input in test harnesses.
936 // Set the attribute directly here to avoid "changed after checked" errors.
937 this._elementRef.nativeElement.setAttribute('data-mat-chip-input', inputElement.id);
938 }
939 /**
940 * Implemented as part of MatFormFieldControl.
941 * @docs-private
942 */
943 setDescribedByIds(ids) {
944 if (ids.length) {
945 this._elementRef.nativeElement.setAttribute('aria-describedby', ids.join(' '));
946 }
947 else {
948 this._elementRef.nativeElement.removeAttribute('aria-describedby');
949 }
950 }
951 // Implemented as part of ControlValueAccessor.
952 writeValue(value) {
953 if (this.chips) {
954 this._setSelectionByValue(value, false);
955 }
956 }
957 // Implemented as part of ControlValueAccessor.
958 registerOnChange(fn) {
959 this._onChange = fn;
960 }
961 // Implemented as part of ControlValueAccessor.
962 registerOnTouched(fn) {
963 this._onTouched = fn;
964 }
965 // Implemented as part of ControlValueAccessor.
966 setDisabledState(isDisabled) {
967 this.disabled = isDisabled;
968 this.stateChanges.next();
969 }
970 /**
971 * Implemented as part of MatFormFieldControl.
972 * @docs-private
973 */
974 onContainerClick(event) {
975 if (!this._originatesFromChip(event)) {
976 this.focus();
977 }
978 }
979 /**
980 * Focuses the first non-disabled chip in this chip list, or the associated input when there
981 * are no eligible chips.
982 */
983 focus(options) {
984 if (this.disabled) {
985 return;
986 }
987 // TODO: ARIA says this should focus the first `selected` chip if any are selected.
988 // Focus on first element if there's no chipInput inside chip-list
989 if (this._chipInput && this._chipInput.focused) {
990 // do nothing
991 }
992 else if (this.chips.length > 0) {
993 this._keyManager.setFirstItemActive();
994 this.stateChanges.next();
995 }
996 else {
997 this._focusInput(options);
998 this.stateChanges.next();
999 }
1000 }
1001 /** Attempt to focus an input if we have one. */
1002 _focusInput(options) {
1003 if (this._chipInput) {
1004 this._chipInput.focus(options);
1005 }
1006 }
1007 /**
1008 * Pass events to the keyboard manager. Available here for tests.
1009 */
1010 _keydown(event) {
1011 const target = event.target;
1012 if (target && target.classList.contains('mat-chip')) {
1013 this._keyManager.onKeydown(event);
1014 this.stateChanges.next();
1015 }
1016 }
1017 /**
1018 * Check the tab index as you should not be allowed to focus an empty list.
1019 */
1020 _updateTabIndex() {
1021 // If we have 0 chips, we should not allow keyboard focus
1022 this._tabIndex = this._userTabIndex || (this.chips.length === 0 ? -1 : 0);
1023 }
1024 /**
1025 * If the amount of chips changed, we need to update the
1026 * key manager state and focus the next closest chip.
1027 */
1028 _updateFocusForDestroyedChips() {
1029 // Move focus to the closest chip. If no other chips remain, focus the chip-list itself.
1030 if (this._lastDestroyedChipIndex != null) {
1031 if (this.chips.length) {
1032 const newChipIndex = Math.min(this._lastDestroyedChipIndex, this.chips.length - 1);
1033 this._keyManager.setActiveItem(newChipIndex);
1034 }
1035 else {
1036 this.focus();
1037 }
1038 }
1039 this._lastDestroyedChipIndex = null;
1040 }
1041 /**
1042 * Utility to ensure all indexes are valid.
1043 *
1044 * @param index The index to be checked.
1045 * @returns True if the index is valid for our list of chips.
1046 */
1047 _isValidIndex(index) {
1048 return index >= 0 && index < this.chips.length;
1049 }
1050 _setSelectionByValue(value, isUserInput = true) {
1051 this._clearSelection();
1052 this.chips.forEach(chip => chip.deselect());
1053 if (Array.isArray(value)) {
1054 value.forEach(currentValue => this._selectValue(currentValue, isUserInput));
1055 this._sortValues();
1056 }
1057 else {
1058 const correspondingChip = this._selectValue(value, isUserInput);
1059 // Shift focus to the active item. Note that we shouldn't do this in multiple
1060 // mode, because we don't know what chip the user interacted with last.
1061 if (correspondingChip) {
1062 if (isUserInput) {
1063 this._keyManager.setActiveItem(correspondingChip);
1064 }
1065 }
1066 }
1067 }
1068 /**
1069 * Finds and selects the chip based on its value.
1070 * @returns Chip that has the corresponding value.
1071 */
1072 _selectValue(value, isUserInput = true) {
1073 const correspondingChip = this.chips.find(chip => {
1074 return chip.value != null && this._compareWith(chip.value, value);
1075 });
1076 if (correspondingChip) {
1077 isUserInput ? correspondingChip.selectViaInteraction() : correspondingChip.select();
1078 this._selectionModel.select(correspondingChip);
1079 }
1080 return correspondingChip;
1081 }
1082 _initializeSelection() {
1083 // Defer setting the value in order to avoid the "Expression
1084 // has changed after it was checked" errors from Angular.
1085 Promise.resolve().then(() => {
1086 if (this.ngControl || this._value) {
1087 this._setSelectionByValue(this.ngControl ? this.ngControl.value : this._value, false);
1088 this.stateChanges.next();
1089 }
1090 });
1091 }
1092 /**
1093 * Deselects every chip in the list.
1094 * @param skip Chip that should not be deselected.
1095 */
1096 _clearSelection(skip) {
1097 this._selectionModel.clear();
1098 this.chips.forEach(chip => {
1099 if (chip !== skip) {
1100 chip.deselect();
1101 }
1102 });
1103 this.stateChanges.next();
1104 }
1105 /**
1106 * Sorts the model values, ensuring that they keep the same
1107 * order that they have in the panel.
1108 */
1109 _sortValues() {
1110 if (this._multiple) {
1111 this._selectionModel.clear();
1112 this.chips.forEach(chip => {
1113 if (chip.selected) {
1114 this._selectionModel.select(chip);
1115 }
1116 });
1117 this.stateChanges.next();
1118 }
1119 }
1120 /** Emits change event to set the model value. */
1121 _propagateChanges(fallbackValue) {
1122 let valueToEmit = null;
1123 if (Array.isArray(this.selected)) {
1124 valueToEmit = this.selected.map(chip => chip.value);
1125 }
1126 else {
1127 valueToEmit = this.selected ? this.selected.value : fallbackValue;
1128 }
1129 this._value = valueToEmit;
1130 this.change.emit(new MatChipListChange(this, valueToEmit));
1131 this.valueChange.emit(valueToEmit);
1132 this._onChange(valueToEmit);
1133 this._changeDetectorRef.markForCheck();
1134 }
1135 /** When blurred, mark the field as touched when focus moved outside the chip list. */
1136 _blur() {
1137 if (!this._hasFocusedChip()) {
1138 this._keyManager.setActiveItem(-1);
1139 }
1140 if (!this.disabled) {
1141 if (this._chipInput) {
1142 // If there's a chip input, we should check whether the focus moved to chip input.
1143 // If the focus is not moved to chip input, mark the field as touched. If the focus moved
1144 // to chip input, do nothing.
1145 // Timeout is needed to wait for the focus() event trigger on chip input.
1146 setTimeout(() => {
1147 if (!this.focused) {
1148 this._markAsTouched();
1149 }
1150 });
1151 }
1152 else {
1153 // If there's no chip input, then mark the field as touched.
1154 this._markAsTouched();
1155 }
1156 }
1157 }
1158 /** Mark the field as touched */
1159 _markAsTouched() {
1160 this._onTouched();
1161 this._changeDetectorRef.markForCheck();
1162 this.stateChanges.next();
1163 }
1164 /**
1165 * Removes the `tabindex` from the chip list and resets it back afterwards, allowing the
1166 * user to tab out of it. This prevents the list from capturing focus and redirecting
1167 * it back to the first chip, creating a focus trap, if it user tries to tab away.
1168 */
1169 _allowFocusEscape() {
1170 if (this._tabIndex !== -1) {
1171 this._tabIndex = -1;
1172 setTimeout(() => {
1173 this._tabIndex = this._userTabIndex || 0;
1174 this._changeDetectorRef.markForCheck();
1175 });
1176 }
1177 }
1178 _resetChips() {
1179 this._dropSubscriptions();
1180 this._listenToChipsFocus();
1181 this._listenToChipsSelection();
1182 this._listenToChipsRemoved();
1183 }
1184 _dropSubscriptions() {
1185 if (this._chipFocusSubscription) {
1186 this._chipFocusSubscription.unsubscribe();
1187 this._chipFocusSubscription = null;
1188 }
1189 if (this._chipBlurSubscription) {
1190 this._chipBlurSubscription.unsubscribe();
1191 this._chipBlurSubscription = null;
1192 }
1193 if (this._chipSelectionSubscription) {
1194 this._chipSelectionSubscription.unsubscribe();
1195 this._chipSelectionSubscription = null;
1196 }
1197 if (this._chipRemoveSubscription) {
1198 this._chipRemoveSubscription.unsubscribe();
1199 this._chipRemoveSubscription = null;
1200 }
1201 }
1202 /** Listens to user-generated selection events on each chip. */
1203 _listenToChipsSelection() {
1204 this._chipSelectionSubscription = this.chipSelectionChanges.subscribe(event => {
1205 event.source.selected
1206 ? this._selectionModel.select(event.source)
1207 : this._selectionModel.deselect(event.source);
1208 // For single selection chip list, make sure the deselected value is unselected.
1209 if (!this.multiple) {
1210 this.chips.forEach(chip => {
1211 if (!this._selectionModel.isSelected(chip) && chip.selected) {
1212 chip.deselect();
1213 }
1214 });
1215 }
1216 if (event.isUserInput) {
1217 this._propagateChanges();
1218 }
1219 });
1220 }
1221 /** Listens to user-generated selection events on each chip. */
1222 _listenToChipsFocus() {
1223 this._chipFocusSubscription = this.chipFocusChanges.subscribe(event => {
1224 let chipIndex = this.chips.toArray().indexOf(event.chip);
1225 if (this._isValidIndex(chipIndex)) {
1226 this._keyManager.updateActiveItem(chipIndex);
1227 }
1228 this.stateChanges.next();
1229 });
1230 this._chipBlurSubscription = this.chipBlurChanges.subscribe(() => {
1231 this._blur();
1232 this.stateChanges.next();
1233 });
1234 }
1235 _listenToChipsRemoved() {
1236 this._chipRemoveSubscription = this.chipRemoveChanges.subscribe(event => {
1237 const chip = event.chip;
1238 const chipIndex = this.chips.toArray().indexOf(event.chip);
1239 // In case the chip that will be removed is currently focused, we temporarily store
1240 // the index in order to be able to determine an appropriate sibling chip that will
1241 // receive focus.
1242 if (this._isValidIndex(chipIndex) && chip._hasFocus) {
1243 this._lastDestroyedChipIndex = chipIndex;
1244 }
1245 });
1246 }
1247 /** Checks whether an event comes from inside a chip element. */
1248 _originatesFromChip(event) {
1249 let currentElement = event.target;
1250 while (currentElement && currentElement !== this._elementRef.nativeElement) {
1251 if (currentElement.classList.contains('mat-chip')) {
1252 return true;
1253 }
1254 currentElement = currentElement.parentElement;
1255 }
1256 return false;
1257 }
1258 /** Checks whether any of the chips is focused. */
1259 _hasFocusedChip() {
1260 return this.chips && this.chips.some(chip => chip._hasFocus);
1261 }
1262 /** Syncs the list's state with the individual chips. */
1263 _syncChipsState() {
1264 if (this.chips) {
1265 this.chips.forEach(chip => {
1266 chip._chipListDisabled = this._disabled;
1267 chip._chipListMultiple = this.multiple;
1268 });
1269 }
1270 }
1271}
1272MatChipList.ɵ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 });
1273MatChipList.ɵ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 });
1274i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipList, decorators: [{
1275 type: Component,
1276 args: [{ selector: 'mat-chip-list', template: `<div class="mat-chip-list-wrapper"><ng-content></ng-content></div>`, exportAs: 'matChipList', host: {
1277 '[attr.tabindex]': 'disabled ? null : _tabIndex',
1278 '[attr.aria-required]': 'role ? required : null',
1279 '[attr.aria-disabled]': 'disabled.toString()',
1280 '[attr.aria-invalid]': 'errorState',
1281 '[attr.aria-multiselectable]': 'multiple',
1282 '[attr.role]': 'role',
1283 '[class.mat-chip-list-disabled]': 'disabled',
1284 '[class.mat-chip-list-invalid]': 'errorState',
1285 '[class.mat-chip-list-required]': 'required',
1286 '[attr.aria-orientation]': 'ariaOrientation',
1287 'class': 'mat-chip-list',
1288 '(focus)': 'focus()',
1289 '(blur)': '_blur()',
1290 '(keydown)': '_keydown($event)',
1291 '[id]': '_uid',
1292 }, 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}"] }]
1293 }], ctorParameters: function () {
1294 return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i1$1.Directionality, decorators: [{
1295 type: Optional
1296 }] }, { type: i2.NgForm, decorators: [{
1297 type: Optional
1298 }] }, { type: i2.FormGroupDirective, decorators: [{
1299 type: Optional
1300 }] }, { type: i3.ErrorStateMatcher }, { type: i2.NgControl, decorators: [{
1301 type: Optional
1302 }, {
1303 type: Self
1304 }] }];
1305 }, propDecorators: { role: [{
1306 type: Input
1307 }], userAriaDescribedBy: [{
1308 type: Input,
1309 args: ['aria-describedby']
1310 }], errorStateMatcher: [{
1311 type: Input
1312 }], multiple: [{
1313 type: Input
1314 }], compareWith: [{
1315 type: Input
1316 }], value: [{
1317 type: Input
1318 }], required: [{
1319 type: Input
1320 }], placeholder: [{
1321 type: Input
1322 }], disabled: [{
1323 type: Input
1324 }], ariaOrientation: [{
1325 type: Input,
1326 args: ['aria-orientation']
1327 }], selectable: [{
1328 type: Input
1329 }], tabIndex: [{
1330 type: Input
1331 }], change: [{
1332 type: Output
1333 }], valueChange: [{
1334 type: Output
1335 }], chips: [{
1336 type: ContentChildren,
1337 args: [MatChip, {
1338 // We need to use `descendants: true`, because Ivy will no longer match
1339 // indirect descendants if it's left as false.
1340 descendants: true,
1341 }]
1342 }] } });
1343
1344/**
1345 * @license
1346 * Copyright Google LLC All Rights Reserved.
1347 *
1348 * Use of this source code is governed by an MIT-style license that can be
1349 * found in the LICENSE file at https://angular.io/license
1350 */
1351const CHIP_DECLARATIONS = [
1352 MatChipList,
1353 MatChip,
1354 MatChipInput,
1355 MatChipRemove,
1356 MatChipAvatar,
1357 MatChipTrailingIcon,
1358];
1359class MatChipsModule {
1360}
1361MatChipsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1362MatChipsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, declarations: [MatChipList,
1363 MatChip,
1364 MatChipInput,
1365 MatChipRemove,
1366 MatChipAvatar,
1367 MatChipTrailingIcon], imports: [MatCommonModule], exports: [MatChipList,
1368 MatChip,
1369 MatChipInput,
1370 MatChipRemove,
1371 MatChipAvatar,
1372 MatChipTrailingIcon] });
1373MatChipsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, providers: [
1374 ErrorStateMatcher,
1375 {
1376 provide: MAT_CHIPS_DEFAULT_OPTIONS,
1377 useValue: {
1378 separatorKeyCodes: [ENTER],
1379 },
1380 },
1381 ], imports: [MatCommonModule] });
1382i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatChipsModule, decorators: [{
1383 type: NgModule,
1384 args: [{
1385 imports: [MatCommonModule],
1386 exports: CHIP_DECLARATIONS,
1387 declarations: CHIP_DECLARATIONS,
1388 providers: [
1389 ErrorStateMatcher,
1390 {
1391 provide: MAT_CHIPS_DEFAULT_OPTIONS,
1392 useValue: {
1393 separatorKeyCodes: [ENTER],
1394 },
1395 },
1396 ],
1397 }]
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 * @license
1410 * Copyright Google LLC All Rights Reserved.
1411 *
1412 * Use of this source code is governed by an MIT-style license that can be
1413 * found in the LICENSE file at https://angular.io/license
1414 */
1415
1416/**
1417 * Generated bundle index. Do not edit.
1418 */
1419
1420export { MAT_CHIPS_DEFAULT_OPTIONS, MAT_CHIP_AVATAR, MAT_CHIP_REMOVE, MAT_CHIP_TRAILING_ICON, MatChip, MatChipAvatar, MatChipInput, MatChipList, MatChipListChange, MatChipRemove, MatChipSelectionChange, MatChipTrailingIcon, MatChipsModule };
1421//# sourceMappingURL=chips.mjs.map