@angular/material 14.2.0-next.1 → 14.2.0-next.2

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.
@@ -7,7 +7,7 @@ import { ComponentPortal, TemplatePortal, PortalModule } from '@angular/cdk/port
7
7
  import * as i1 from '@angular/common';
8
8
  import { CommonModule } from '@angular/common';
9
9
  import * as i0 from '@angular/core';
10
- import { Injectable, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, Output, Optional, SkipSelf, InjectionToken, Inject, ViewChild, forwardRef, Directive, Attribute, ContentChild, InjectFlags, Self, TemplateRef, NgModule } from '@angular/core';
10
+ import { Injectable, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, Output, Optional, SkipSelf, InjectionToken, Inject, ViewChild, forwardRef, Directive, Attribute, ContentChild, inject, InjectFlags, Self, TemplateRef, NgModule } from '@angular/core';
11
11
  import * as i3 from '@angular/material/button';
12
12
  import { MatButtonModule } from '@angular/material/button';
13
13
  import { CdkScrollableModule } from '@angular/cdk/scrolling';
@@ -16,6 +16,7 @@ import { DateAdapter, MAT_DATE_FORMATS, mixinColor, mixinErrorState, MatCommonMo
16
16
  import { Subject, Subscription, merge, of } from 'rxjs';
17
17
  import { ESCAPE, hasModifierKey, SPACE, ENTER, PAGE_DOWN, PAGE_UP, END, HOME, DOWN_ARROW, UP_ARROW, RIGHT_ARROW, LEFT_ARROW, BACKSPACE } from '@angular/cdk/keycodes';
18
18
  import * as i2 from '@angular/cdk/bidi';
19
+ import { Directionality } from '@angular/cdk/bidi';
19
20
  import { take, startWith, filter } from 'rxjs/operators';
20
21
  import { coerceBooleanProperty, coerceStringArray } from '@angular/cdk/coercion';
21
22
  import { _getFocusedElementPierceShadowDom } from '@angular/cdk/platform';
@@ -3270,13 +3271,15 @@ const MAT_DATE_RANGE_INPUT_PARENT = new InjectionToken('MAT_DATE_RANGE_INPUT_PAR
3270
3271
  * Base class for the individual inputs that can be projected inside a `mat-date-range-input`.
3271
3272
  */
3272
3273
  class MatDateRangeInputPartBase extends MatDatepickerInputBase {
3273
- constructor(_rangeInput, elementRef, _defaultErrorStateMatcher, _injector, _parentForm, _parentFormGroup, dateAdapter, dateFormats) {
3274
- super(elementRef, dateAdapter, dateFormats);
3274
+ constructor(_rangeInput, _elementRef, _defaultErrorStateMatcher, _injector, _parentForm, _parentFormGroup, dateAdapter, dateFormats) {
3275
+ super(_elementRef, dateAdapter, dateFormats);
3275
3276
  this._rangeInput = _rangeInput;
3277
+ this._elementRef = _elementRef;
3276
3278
  this._defaultErrorStateMatcher = _defaultErrorStateMatcher;
3277
3279
  this._injector = _injector;
3278
3280
  this._parentForm = _parentForm;
3279
3281
  this._parentFormGroup = _parentFormGroup;
3282
+ this._dir = inject(Directionality, InjectFlags.Optional);
3280
3283
  }
3281
3284
  ngOnInit() {
3282
3285
  // We need the date input to provide itself as a `ControlValueAccessor` and a `Validator`, while
@@ -3411,6 +3414,23 @@ class MatStartDate extends _MatDateRangeInputBase {
3411
3414
  const value = element.value;
3412
3415
  return value.length > 0 ? value : element.placeholder;
3413
3416
  }
3417
+ _onKeydown(event) {
3418
+ const endInput = this._rangeInput._endInput;
3419
+ const element = this._elementRef.nativeElement;
3420
+ const isLtr = this._dir?.value !== 'rtl';
3421
+ // If the user hits RIGHT (LTR) when at the end of the input (and no
3422
+ // selection), move the cursor to the start of the end input.
3423
+ if (((event.keyCode === RIGHT_ARROW && isLtr) || (event.keyCode === LEFT_ARROW && !isLtr)) &&
3424
+ element.selectionStart === element.value.length &&
3425
+ element.selectionEnd === element.value.length) {
3426
+ event.preventDefault();
3427
+ endInput._elementRef.nativeElement.setSelectionRange(0, 0);
3428
+ endInput.focus();
3429
+ }
3430
+ else {
3431
+ super._onKeydown(event);
3432
+ }
3433
+ }
3414
3434
  }
3415
3435
  MatStartDate.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatStartDate, deps: [{ token: MAT_DATE_RANGE_INPUT_PARENT }, { token: i0.ElementRef }, { token: i1$1.ErrorStateMatcher }, { token: i0.Injector }, { token: i2$2.NgForm, optional: true }, { token: i2$2.FormGroupDirective, optional: true }, { token: i1$1.DateAdapter, optional: true }, { token: MAT_DATE_FORMATS, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
3416
3436
  MatStartDate.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: MatStartDate, selector: "input[matStartDate]", inputs: { errorStateMatcher: "errorStateMatcher" }, outputs: { dateChange: "dateChange", dateInput: "dateInput" }, host: { attributes: { "type": "text" }, listeners: { "input": "_onInput($event.target.value)", "change": "_onChange()", "keydown": "_onKeydown($event)", "blur": "_onBlur()" }, properties: { "disabled": "disabled", "attr.id": "_rangeInput.id", "attr.aria-haspopup": "_rangeInput.rangePicker ? \"dialog\" : null", "attr.aria-owns": "(_rangeInput.rangePicker?.opened && _rangeInput.rangePicker.id) || null", "attr.min": "_getMinDate() ? _dateAdapter.toIso8601(_getMinDate()) : null", "attr.max": "_getMaxDate() ? _dateAdapter.toIso8601(_getMaxDate()) : null" }, classAttribute: "mat-start-date mat-date-range-input-inner" }, providers: [
@@ -3494,11 +3514,26 @@ class MatEndDate extends _MatDateRangeInputBase {
3494
3514
  }
3495
3515
  }
3496
3516
  _onKeydown(event) {
3517
+ const startInput = this._rangeInput._startInput;
3518
+ const element = this._elementRef.nativeElement;
3519
+ const isLtr = this._dir?.value !== 'rtl';
3497
3520
  // If the user is pressing backspace on an empty end input, move focus back to the start.
3498
- if (event.keyCode === BACKSPACE && !this._elementRef.nativeElement.value) {
3499
- this._rangeInput._startInput.focus();
3521
+ if (event.keyCode === BACKSPACE && !element.value) {
3522
+ startInput.focus();
3523
+ }
3524
+ // If the user hits LEFT (LTR) when at the start of the input (and no
3525
+ // selection), move the cursor to the end of the start input.
3526
+ else if (((event.keyCode === LEFT_ARROW && isLtr) || (event.keyCode === RIGHT_ARROW && !isLtr)) &&
3527
+ element.selectionStart === 0 &&
3528
+ element.selectionEnd === 0) {
3529
+ event.preventDefault();
3530
+ const endPosition = startInput._elementRef.nativeElement.value.length;
3531
+ startInput._elementRef.nativeElement.setSelectionRange(endPosition, endPosition);
3532
+ startInput.focus();
3533
+ }
3534
+ else {
3535
+ super._onKeydown(event);
3500
3536
  }
3501
- super._onKeydown(event);
3502
3537
  }
3503
3538
  }
3504
3539
  MatEndDate.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatEndDate, deps: [{ token: MAT_DATE_RANGE_INPUT_PARENT }, { token: i0.ElementRef }, { token: i1$1.ErrorStateMatcher }, { token: i0.Injector }, { token: i2$2.NgForm, optional: true }, { token: i2$2.FormGroupDirective, optional: true }, { token: i1$1.DateAdapter, optional: true }, { token: MAT_DATE_FORMATS, optional: true }], target: i0.ɵɵFactoryTarget.Directive });