/** * @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 { ENTER, SPACE } from '@angular/cdk/keycodes'; import { Directive, ElementRef, Inject, Input } from '@angular/core'; import { mixinTabIndex } from '@angular/material/core'; import { MAT_CHIP } from './tokens'; import * as i0 from "@angular/core"; class _MatChipActionBase { } const _MatChipActionMixinBase = mixinTabIndex(_MatChipActionBase, -1); /** * Section within a chip. * @docs-private */ export class MatChipAction extends _MatChipActionMixinBase { /** Whether the action is disabled. */ get disabled() { return this._disabled || this._parentChip.disabled; } set disabled(value) { this._disabled = coerceBooleanProperty(value); } /** * Determine the value of the disabled attribute for this chip action. */ _getDisabledAttribute() { // When this chip action is disabled and focusing disabled chips is not permitted, return empty // string to indicate that disabled attribute should be included. return this.disabled && !this._allowFocusWhenDisabled ? '' : null; } /** * Determine the value of the tabindex attribute for this chip action. */ _getTabindex() { return (this.disabled && !this._allowFocusWhenDisabled) || !this.isInteractive ? null : this.tabIndex.toString(); } constructor(_elementRef, _parentChip) { super(); this._elementRef = _elementRef; this._parentChip = _parentChip; /** Whether the action is interactive. */ this.isInteractive = true; /** Whether this is the primary action in the chip. */ this._isPrimary = true; this._disabled = false; /** * Private API to allow focusing this chip when it is disabled. */ this._allowFocusWhenDisabled = false; if (_elementRef.nativeElement.nodeName === 'BUTTON') { _elementRef.nativeElement.setAttribute('type', 'button'); } } focus() { this._elementRef.nativeElement.focus(); } _handleClick(event) { if (!this.disabled && this.isInteractive && this._isPrimary) { event.preventDefault(); this._parentChip._handlePrimaryActionInteraction(); } } _handleKeydown(event) { if ((event.keyCode === ENTER || event.keyCode === SPACE) && !this.disabled && this.isInteractive && this._isPrimary && !this._parentChip._isEditing) { event.preventDefault(); this._parentChip._handlePrimaryActionInteraction(); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatChipAction, deps: [{ token: i0.ElementRef }, { token: MAT_CHIP }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: MatChipAction, selector: "[matChipAction]", inputs: { disabled: "disabled", tabIndex: "tabIndex", isInteractive: "isInteractive", _allowFocusWhenDisabled: "_allowFocusWhenDisabled" }, host: { listeners: { "click": "_handleClick($event)", "keydown": "_handleKeydown($event)" }, properties: { "class.mdc-evolution-chip__action--primary": "_isPrimary", "class.mdc-evolution-chip__action--presentational": "!isInteractive", "class.mdc-evolution-chip__action--trailing": "!_isPrimary", "attr.tabindex": "_getTabindex()", "attr.disabled": "_getDisabledAttribute()", "attr.aria-disabled": "disabled" }, classAttribute: "mdc-evolution-chip__action mat-mdc-chip-action" }, usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatChipAction, decorators: [{ type: Directive, args: [{ selector: '[matChipAction]', inputs: ['disabled', 'tabIndex'], host: { 'class': 'mdc-evolution-chip__action mat-mdc-chip-action', '[class.mdc-evolution-chip__action--primary]': '_isPrimary', '[class.mdc-evolution-chip__action--presentational]': '!isInteractive', '[class.mdc-evolution-chip__action--trailing]': '!_isPrimary', '[attr.tabindex]': '_getTabindex()', '[attr.disabled]': '_getDisabledAttribute()', '[attr.aria-disabled]': 'disabled', '(click)': '_handleClick($event)', '(keydown)': '_handleKeydown($event)', }, }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_CHIP] }] }]; }, propDecorators: { isInteractive: [{ type: Input }], disabled: [{ type: Input }], _allowFocusWhenDisabled: [{ type: Input }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1hY3Rpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMv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