Skip to content

Commit

Permalink
test(time-picker): fix failing tests, #6471
Browse files Browse the repository at this point in the history
  • Loading branch information
wnvko committed Feb 24, 2020
1 parent 98989e9 commit 21ccad2
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,15 @@ export class IgxTimePickerComponent implements
* @hidden
*/
@ViewChild('input', { read: ElementRef })
private input: ElementRef;
private inputElementRef: ElementRef;

@ViewChild(IgxInputDirective, { read: IgxInputDirective})
private _inputDirective: IgxInputDirective;

/** @hidden @internal */
@ContentChild(IgxInputDirective)
protected input: IgxInputDirective;

/**
* @hidden
*/
Expand Down Expand Up @@ -894,8 +898,8 @@ export class IgxTimePickerComponent implements
* @hidden
*/
public ngAfterViewInit(): void {
if (this.mode === InteractionMode.DropDown && this.input) {
fromEvent(this.input.nativeElement, 'keydown').pipe(
if (this.mode === InteractionMode.DropDown && this.inputElementRef) {
fromEvent(this.inputElementRef.nativeElement, 'keydown').pipe(
throttle(() => interval(0, animationFrameScheduler)),
takeUntil(this._destroy$)
).subscribe((event: KeyboardEvent) => {
Expand Down Expand Up @@ -1383,11 +1387,11 @@ export class IgxTimePickerComponent implements
}

private _getCursorPosition(): number {
return this.input.nativeElement.selectionStart;
return this.inputElementRef.nativeElement.selectionStart;
}

private _setCursorPosition(start: number, end: number = start): void {
this.input.nativeElement.setSelectionRange(start, end);
this.inputElementRef.nativeElement.setSelectionRange(start, end);
}

private _updateEditableInput(): void {
Expand Down Expand Up @@ -2090,7 +2094,7 @@ export class IgxTimePickerComponent implements

// minor hack for preventing cursor jumping in IE
this._displayValue = this.inputFormat.transform(displayVal);
this.input.nativeElement.value = this._displayValue;
this.inputElementRef.nativeElement.value = this._displayValue;
this._setCursorPosition(cursor);

requestAnimationFrame(() => {
Expand Down Expand Up @@ -2125,10 +2129,11 @@ export class IgxTimePickerComponent implements

private updateValidity() {
this._onTouchedCallback();
const inputDirective = this._inputDirective || this.input;
if (this._ngControl && !this._ngControl.valid) {
this._inputDirective.valid = IgxInputState.INVALID;
inputDirective.valid = IgxInputState.INVALID;
} else {
this._inputDirective.valid = IgxInputState.INITIAL;
inputDirective.valid = IgxInputState.INITIAL;
}
}
}
Expand Down

0 comments on commit 21ccad2

Please sign in to comment.