@angular/material 17.3.9 → 17.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -390,7 +390,9 @@ class MatChip {
390
390
  }
391
391
  /** Handles keyboard events on the chip. */
392
392
  _handleKeydown(event) {
393
- if (event.keyCode === BACKSPACE || event.keyCode === DELETE) {
393
+ // Ignore backspace events where the user is holding down the key
394
+ // so that we don't accidentally remove too many chips.
395
+ if ((event.keyCode === BACKSPACE && !event.repeat) || event.keyCode === DELETE) {
394
396
  event.preventDefault();
395
397
  this.remove();
396
398
  }
@@ -2005,35 +2007,19 @@ class MatChipInput {
2005
2007
  ngOnDestroy() {
2006
2008
  this.chipEnd.complete();
2007
2009
  }
2008
- ngAfterContentInit() {
2009
- this._focusLastChipOnBackspace = this.empty;
2010
- }
2011
2010
  /** Utility method to make host definition/tests more clear. */
2012
2011
  _keydown(event) {
2013
- if (event) {
2014
- // To prevent the user from accidentally deleting chips when pressing BACKSPACE continuously,
2015
- // We focus the last chip on backspace only after the user has released the backspace button,
2016
- // And the input is empty (see behaviour in _keyup)
2017
- if (event.keyCode === BACKSPACE && this._focusLastChipOnBackspace) {
2012
+ if (this.empty && event.keyCode === BACKSPACE) {
2013
+ // Ignore events where the user is holding down backspace
2014
+ // so that we don't accidentally remove too many chips.
2015
+ if (!event.repeat) {
2018
2016
  this._chipGrid._focusLastChip();
2019
- event.preventDefault();
2020
- return;
2021
2017
  }
2022
- else {
2023
- this._focusLastChipOnBackspace = false;
2024
- }
2025
- }
2026
- this._emitChipEnd(event);
2027
- }
2028
- /**
2029
- * Pass events to the keyboard manager. Available here for tests.
2030
- */
2031
- _keyup(event) {
2032
- // Allow user to move focus to chips next time he presses backspace
2033
- if (!this._focusLastChipOnBackspace && event.keyCode === BACKSPACE && this.empty) {
2034
- this._focusLastChipOnBackspace = true;
2035
2018
  event.preventDefault();
2036
2019
  }
2020
+ else {
2021
+ this._emitChipEnd(event);
2022
+ }
2037
2023
  }
2038
2024
  /** Checks to see if the blur should emit the (chipEnd) event. */
2039
2025
  _blur() {
@@ -2049,7 +2035,6 @@ class MatChipInput {
2049
2035
  }
2050
2036
  _focus() {
2051
2037
  this.focused = true;
2052
- this._focusLastChipOnBackspace = this.empty;
2053
2038
  this._chipGrid.stateChanges.next();
2054
2039
  }
2055
2040
  /** Checks to see if the (chipEnd) event needs to be emitted. */
@@ -2074,7 +2059,6 @@ class MatChipInput {
2074
2059
  /** Clears the input */
2075
2060
  clear() {
2076
2061
  this.inputElement.value = '';
2077
- this._focusLastChipOnBackspace = true;
2078
2062
  }
2079
2063
  setDescribedByIds(ids) {
2080
2064
  const element = this._elementRef.nativeElement;
@@ -2092,7 +2076,7 @@ class MatChipInput {
2092
2076
  return !hasModifierKey(event) && new Set(this.separatorKeyCodes).has(event.keyCode);
2093
2077
  }
2094
2078
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.0", ngImport: i0, type: MatChipInput, deps: [{ token: i0.ElementRef }, { token: MAT_CHIPS_DEFAULT_OPTIONS }, { token: MAT_FORM_FIELD, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
2095
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "17.2.0", type: MatChipInput, isStandalone: true, selector: "input[matChipInputFor]", inputs: { chipGrid: ["matChipInputFor", "chipGrid"], addOnBlur: ["matChipInputAddOnBlur", "addOnBlur", booleanAttribute], separatorKeyCodes: ["matChipInputSeparatorKeyCodes", "separatorKeyCodes"], placeholder: "placeholder", id: "id", disabled: ["disabled", "disabled", booleanAttribute] }, 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 }); }
2079
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "17.2.0", type: MatChipInput, isStandalone: true, selector: "input[matChipInputFor]", inputs: { chipGrid: ["matChipInputFor", "chipGrid"], addOnBlur: ["matChipInputAddOnBlur", "addOnBlur", booleanAttribute], separatorKeyCodes: ["matChipInputSeparatorKeyCodes", "separatorKeyCodes"], placeholder: "placeholder", id: "id", disabled: ["disabled", "disabled", booleanAttribute] }, outputs: { chipEnd: "matChipInputTokenEnd" }, host: { listeners: { "keydown": "_keydown($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 }); }
2096
2080
  }
2097
2081
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.0", ngImport: i0, type: MatChipInput, decorators: [{
2098
2082
  type: Directive,
@@ -2105,7 +2089,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.0", ngImpor
2105
2089
  // the MDC chips were landed initially with it.
2106
2090
  'class': 'mat-mdc-chip-input mat-mdc-input-element mdc-text-field__input mat-input-element',
2107
2091
  '(keydown)': '_keydown($event)',
2108
- '(keyup)': '_keyup($event)',
2109
2092
  '(blur)': '_blur()',
2110
2093
  '(focus)': '_focus()',
2111
2094
  '(input)': '_onInput()',