/** * @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 } from '@angular/cdk/keycodes'; import { Directive, ElementRef, EventEmitter, Inject, Input, Optional, Output, } from '@angular/core'; import { MatFormField, MAT_FORM_FIELD } from '@angular/material/form-field'; import { MAT_CHIPS_DEFAULT_OPTIONS } from './tokens'; import { MatChipGrid } from './chip-grid'; import * as i0 from "@angular/core"; import * as i1 from "@angular/material/form-field"; // 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 a ``. */ export class MatChipInput { /** Register input for chip list */ set chipGrid(value) { if (value) { this._chipGrid = value; this._chipGrid.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._chipGrid && this._chipGrid.disabled); } set disabled(value) { this._disabled = coerceBooleanProperty(value); } /** Whether the input is empty. */ get empty() { return !this.inputElement.value; } constructor(_elementRef, defaultOptions, formField) { 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-mdc-chip-list-input-${nextUniqueId++}`; this._disabled = false; this.inputElement = this._elementRef.nativeElement; this.separatorKeyCodes = defaultOptions.separatorKeyCodes; if (formField) { this.inputElement.classList.add('mat-mdc-form-field-input-control'); } } ngOnChanges() { this._chipGrid.stateChanges.next(); } ngOnDestroy() { this.chipEnd.complete(); } ngAfterContentInit() { this._focusLastChipOnBackspace = this.empty; } /** Utility method to make host definition/tests more clear. */ _keydown(event) { if (event) { // 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._chipGrid._focusLastChip(); 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._chipGrid.focused) { this._chipGrid._blur(); } this._chipGrid.stateChanges.next(); } _focus() { this.focused = true; this._focusLastChipOnBackspace = this.empty; this._chipGrid.stateChanges.next(); } /** Checks to see if the (chipEnd) event needs to be emitted. */ _emitChipEnd(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._chipGrid.stateChanges.next(); } /** Focuses the input. */ focus() { this.inputElement.focus(); } /** Clears the input */ clear() { this.inputElement.value = ''; this._focusLastChipOnBackspace = true; } setDescribedByIds(ids) { const element = this._elementRef.nativeElement; // Set the value directly in the DOM since this binding // is prone to "changed after checked" errors. if (ids.length) { element.setAttribute('aria-describedby', ids.join(' ')); } else { element.removeAttribute('aria-describedby'); } } /** 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: MatChipInput, deps: [{ token: i0.ElementRef }, { token: MAT_CHIPS_DEFAULT_OPTIONS }, { token: MAT_FORM_FIELD, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: MatChipInput, selector: "input[matChipInputFor]", inputs: { chipGrid: ["matChipInputFor", "chipGrid"], 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": "_chipGrid && _chipGrid.ngControl ? _chipGrid.ngControl.invalid : null", "attr.aria-required": "_chipGrid && _chipGrid.required || null", "attr.required": "_chipGrid && _chipGrid.required || null" }, classAttribute: "mat-mdc-chip-input mat-mdc-input-element mdc-text-field__input mat-input-element" }, exportAs: ["matChipInput", "matChipInputFor"], usesOnChanges: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatChipInput, decorators: [{ type: Directive, args: [{ selector: 'input[matChipInputFor]', exportAs: 'matChipInput, matChipInputFor', host: { // TODO: eventually we should remove `mat-input-element` from here since it comes from the // non-MDC version of the input. It's currently being kept for backwards compatibility, because // the MDC chips were landed initially with it. 'class': 'mat-mdc-chip-input mat-mdc-input-element mdc-text-field__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]': '_chipGrid && _chipGrid.ngControl ? _chipGrid.ngControl.invalid : null', '[attr.aria-required]': '_chipGrid && _chipGrid.required || null', '[attr.required]': '_chipGrid && _chipGrid.required || null', }, }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_CHIPS_DEFAULT_OPTIONS] }] }, { type: i1.MatFormField, decorators: [{ type: Optional }, { type: Inject, args: [MAT_FORM_FIELD] }] }]; }, propDecorators: { chipGrid: [{ 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: Input }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1pbnB1dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9jaGlwcy9jaGlwLWlucHV0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBZSxxQkFBcUIsRUFBQyxNQUFNLHVCQUF1QixDQUFDO0FBQzFFLE9BQU8sRUFBQyxTQUFTLEVBQUUsY0FBYyxFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFDaEUsT0FBTyxFQUVMLFNBQVMsRUFDVCxVQUFVLEVBQ1YsWUFBWSxFQUNaLE1BQU0sRUFDTixLQUFLLEVBR0wsUUFBUSxFQUNSLE1BQU0sR0FDUCxNQUFNLGVBQWUsQ0FBQztBQUN2QixPQUFPLEVBQUMsWUFBWSxFQUFFLGNBQWMsRUFBQyxNQUFNLDhCQUE4QixDQUFDO0FBQzFFLE9BQU8sRUFBeUIseUJBQXlCLEVBQUMsTUFBTSxVQUFVLENBQUM7QUFDM0UsT0FBTyxFQUFDLFdBQVcsRUFBQyxNQUFNLGFBQWEsQ0FBQzs7O0FBbUJ4QyxnREFBZ0Q7QUFDaEQsSUFBSSxZQUFZLEdBQUcsQ0FBQyxDQUFDO0FBRXJCOzs7R0FHRztBQXNCSCxNQUFNLE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