Skip to content

Commit 15e37c4

Browse files
refactor(igxMask): cleanup/streamline parsing and input handling
- input parsing go through one method - add drag and drop functionality - set default value on mask prop
1 parent d4c72f9 commit 15e37c4

File tree

11 files changed

+388
-538
lines changed

11 files changed

+388
-538
lines changed

projects/igniteui-angular/src/lib/core/utils.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,14 @@ export const enum KEYCODES {
139139
RIGHT_ARROW = 39,
140140
DOWN_ARROW = 40,
141141
F2 = 113,
142-
TAB = 9
142+
TAB = 9,
143+
CTRL = 17,
144+
Z = 90,
145+
Y = 89,
146+
X = 88,
147+
BACKSPACE = 8,
148+
DELETE = 46,
149+
INPUT_METHOD = 229
143150
}
144151

145152
/**

projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, ViewChild, ElementRef } from '@angular/core';
22
import { async, fakeAsync, TestBed, tick, flush, ComponentFixture } from '@angular/core/testing';
3-
import { FormsModule, FormGroup, FormBuilder, FormControl, ReactiveFormsModule} from '@angular/forms';
3+
import { FormsModule, FormGroup, FormBuilder, FormControl, ReactiveFormsModule } from '@angular/forms';
44
import { By } from '@angular/platform-browser';
55
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
66
import { IgxDatePickerComponent, IgxDatePickerModule } from './date-picker.component';
@@ -206,7 +206,7 @@ describe('IgxDatePicker', () => {
206206
expect(input).toEqual(document.activeElement);
207207
}));
208208

209-
it('When a modal datepicker is closed via outside click, the focus should remain on the input',
209+
it('When a modal datepicker is closed via outside click, the focus should remain on the input',
210210
fakeAsync(() => {
211211
const datePickerDom = fixture.debugElement.query(By.css('igx-date-picker'));
212212
let overlayToggle = document.getElementsByClassName('igx-overlay__wrapper--modal');
@@ -230,7 +230,7 @@ describe('IgxDatePicker', () => {
230230
expect(input).toEqual(document.activeElement);
231231
}));
232232

233-
it('When datepicker is closed upon selecting a date, the focus should remain on the input',
233+
it('When datepicker is closed upon selecting a date, the focus should remain on the input',
234234
fakeAsync(() => {
235235
const datePickerDom = fixture.debugElement.query(By.css('igx-date-picker'));
236236
let overlayToggle = document.getElementsByClassName('igx-overlay__wrapper--modal');
@@ -939,7 +939,6 @@ describe('IgxDatePicker', () => {
939939

940940
// initial input value is 20-10-11 / dd-MM-yy
941941
// focus the day part, position the caret at the beginning
942-
input.nativeElement.focus();
943942
input.nativeElement.setSelectionRange(0, 0);
944943

945944
// press arrow up
@@ -984,7 +983,6 @@ describe('IgxDatePicker', () => {
984983

985984
// initial input value is 20-10-11 / dd-MM-yy
986985
// focus the day part, position the caret at the beginning
987-
input.nativeElement.focus();
988986
input.nativeElement.setSelectionRange(0, 0);
989987

990988
// press arrow down
@@ -1036,7 +1034,6 @@ describe('IgxDatePicker', () => {
10361034

10371035
// initial input value is 20-10-11 / dd-MM-yy
10381036
// focus the day part, position the caret at the beginning
1039-
input.nativeElement.focus();
10401037
input.nativeElement.setSelectionRange(0, 0);
10411038

10421039
// up
@@ -1149,7 +1146,8 @@ describe('IgxDatePicker', () => {
11491146
expect(input).toBeDefined();
11501147
datePicker.isSpinLoop = false;
11511148

1152-
input.nativeElement.focus();
1149+
input.triggerEventHandler('focus', {});
1150+
fixture.detectChanges(); // bound transformedDate assign
11531151
UIInteractions.sendInput(input, '31-03-19');
11541152
expect(input.nativeElement.value).toBe('31-03-19');
11551153

projects/igniteui-angular/src/lib/date-picker/date-picker.pipes.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ export class DatePickerDisplayValuePipe implements PipeTransform {
3131
export class DatePickerInputValuePipe implements PipeTransform {
3232
constructor(@Inject(IGX_DATE_PICKER_COMPONENT) private _datePicker: IDatePicker) { }
3333
transform(value: any, args?: any): any {
34+
/**
35+
* TODO(D.P.): This plugs into the mask, but constantly received display strings it can't handle at all
36+
* Those are almost immediately overridden by the pickers onFocus handling anyway; Refactor ASAP
37+
*/
3438
if (this._datePicker.invalidDate !== '') {
3539
return this._datePicker.invalidDate;
3640
} else {
3741
if (this._datePicker.value === null || this._datePicker.value === undefined) {
3842
return DatePickerUtil.maskToPromptChars(this._datePicker.inputMask);
3943
} else {
40-
return DatePickerUtil.addPromptCharsEditMode(this._datePicker.dateFormatParts, this._datePicker.value, value);
44+
return (this._datePicker as any)._getEditorDate(this._datePicker.value);
45+
// return DatePickerUtil.addPromptCharsEditMode(this._datePicker.dateFormatParts, this._datePicker.value, value);
4146
}
4247
}
4348
}

0 commit comments

Comments
 (0)