/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { BACKSPACE, hasModifierKey, TAB } from '@angular/cdk/keycodes'; import { Directive, ElementRef, EventEmitter, Inject, Input, Output, } from '@angular/core'; import { MAT_LEGACY_CHIPS_DEFAULT_OPTIONS, } from './chip-default-options'; import { MatLegacyChipList } from './chip-list'; import * as i0 from "@angular/core"; // Increasing integer for generating unique ids. let nextUniqueId = 0; /** * Directive that adds chip-specific behaviors to an input element inside ``. * May be placed inside or outside of an ``. * @deprecated Use `MatChipInput` from `@angular/material/chips` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. * @breaking-change 17.0.0 */ export class MatLegacyChipInput { /** Register input for chip list */ set chipList(value) { if (value) { this._chipList = value; this._chipList.registerInput(this); } } /** * Whether or not the chipEnd event will be emitted when the input is blurred. */ get addOnBlur() { return this._addOnBlur; } set addOnBlur(value) { this._addOnBlur = coerceBooleanProperty(value); } /** Whether the input is disabled. */ get disabled() { return this._disabled || (this._chipList && this._chipList.disabled); } set disabled(value) { this._disabled = coerceBooleanProperty(value); } /** Whether the input is empty. */ get empty() { return !this.inputElement.value; } constructor(_elementRef, defaultOptions) { this._elementRef = _elementRef; /** Whether the control is focused. */ this.focused = false; this._addOnBlur = false; /** Emitted when a chip is to be added. */ this.chipEnd = new EventEmitter(); /** The input's placeholder text. */ this.placeholder = ''; /** Unique id for the input. */ this.id = `mat-chip-list-input-${nextUniqueId++}`; this._disabled = false; this.inputElement = this._elementRef.nativeElement; this.separatorKeyCodes = defaultOptions.separatorKeyCodes; } ngOnChanges() { this._chipList.stateChanges.next(); } ngOnDestroy() { this.chipEnd.complete(); } ngAfterContentInit() { this._focusLastChipOnBackspace = this.empty; } /** Utility method to make host definition/tests more clear. */ _keydown(event) { if (event) { // Allow the user's focus to escape when they're tabbing forward. Note that we don't // want to do this when going backwards, because focus should go back to the first chip. if (event.keyCode === TAB && !hasModifierKey(event, 'shiftKey')) { this._chipList._allowFocusEscape(); } // To prevent the user from accidentally deleting chips when pressing BACKSPACE continuously, // We focus the last chip on backspace only after the user has released the backspace button, // and the input is empty (see behaviour in _keyup) if (event.keyCode === BACKSPACE && this._focusLastChipOnBackspace) { this._chipList._keyManager.setLastItemActive(); event.preventDefault(); return; } else { this._focusLastChipOnBackspace = false; } } this._emitChipEnd(event); } /** * Pass events to the keyboard manager. Available here for tests. */ _keyup(event) { // Allow user to move focus to chips next time he presses backspace if (!this._focusLastChipOnBackspace && event.keyCode === BACKSPACE && this.empty) { this._focusLastChipOnBackspace = true; event.preventDefault(); } } /** Checks to see if the blur should emit the (chipEnd) event. */ _blur() { if (this.addOnBlur) { this._emitChipEnd(); } this.focused = false; // Blur the chip list if it is not focused if (!this._chipList.focused) { this._chipList._blur(); } this._chipList.stateChanges.next(); } _focus() { this.focused = true; this._focusLastChipOnBackspace = this.empty; this._chipList.stateChanges.next(); } /** Checks to see if the (chipEnd) event needs to be emitted. */ _emitChipEnd(event) { if (!this.inputElement.value && !!event) { this._chipList._keydown(event); } if (!event || this._isSeparatorKey(event)) { this.chipEnd.emit({ input: this.inputElement, value: this.inputElement.value, chipInput: this, }); event?.preventDefault(); } } _onInput() { // Let chip list know whenever the value changes. this._chipList.stateChanges.next(); } /** Focuses the input. */ focus(options) { this.inputElement.focus(options); } /** Clears the input */ clear() { this.inputElement.value = ''; this._focusLastChipOnBackspace = true; } /** Checks whether a keycode is one of the configured separators. */ _isSeparatorKey(event) { return !hasModifierKey(event) && new Set(this.separatorKeyCodes).has(event.keyCode); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatLegacyChipInput, deps: [{ token: i0.ElementRef }, { token: MAT_LEGACY_CHIPS_DEFAULT_OPTIONS }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: MatLegacyChipInput, 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 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatLegacyChipInput, decorators: [{ type: Directive, args: [{ selector: 'input[matChipInputFor]', exportAs: 'matChipInput, matChipInputFor', host: { 'class': 'mat-chip-input mat-input-element', '(keydown)': '_keydown($event)', '(keyup)': '_keyup($event)', '(blur)': '_blur()', '(focus)': '_focus()', '(input)': '_onInput()', '[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', }, }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_LEGACY_CHIPS_DEFAULT_OPTIONS] }] }]; }, propDecorators: { chipList: [{ type: Input, args: ['matChipInputFor'] }], addOnBlur: [{ type: Input, args: ['matChipInputAddOnBlur'] }], separatorKeyCodes: [{ type: Input, args: ['matChipInputSeparatorKeyCodes'] }], chipEnd: [{ type: Output, args: ['matChipInputTokenEnd'] }], placeholder: [{ type: Input }], id: [{ type: Input }], disabled: [{ type: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