Skip to content

Commit

Permalink
Merge pull request #83 from dvenkatsagar/master
Browse files Browse the repository at this point in the history
fix: readOnly issue, special characters issue, drop event for partial selections
  • Loading branch information
nbfontana committed Apr 15, 2020
2 parents 3920bf0 + 177013b commit a7cc71e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 16 additions & 5 deletions src/currency-mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,42 +79,53 @@ export class CurrencyMaskDirective implements AfterViewInit, ControlValueAccesso
@HostListener("cut", ["$event"])
handleCut(event: any) {
if (!this.isChromeAndroid()) {
this.inputHandler.handleCut(event);
!this.isReadOnly() && this.inputHandler.handleCut(event);
}
}

@HostListener("input", ["$event"])
handleInput(event: any) {
if (this.isChromeAndroid()) {
this.inputHandler.handleInput(event);
!this.isReadOnly() && this.inputHandler.handleInput(event);
}
}

@HostListener("keydown", ["$event"])
handleKeydown(event: any) {
if (!this.isChromeAndroid()) {
this.inputHandler.handleKeydown(event);
!this.isReadOnly() && this.inputHandler.handleKeydown(event);
}
}

@HostListener("keypress", ["$event"])
handleKeypress(event: any) {
if (!this.isChromeAndroid()) {
this.inputHandler.handleKeypress(event);
!this.isReadOnly() && this.inputHandler.handleKeypress(event);
}
}

@HostListener("paste", ["$event"])
handlePaste(event: any) {
if (!this.isChromeAndroid()) {
this.inputHandler.handlePaste(event);
!this.isReadOnly() && this.inputHandler.handlePaste(event);
}
}

@HostListener("drop", ["$event"])
handleDrop(event: any) {
if (!this.isChromeAndroid()) {
event.preventDefault();
}
}

isChromeAndroid(): boolean {
return /chrome/i.test(navigator.userAgent) && /android/i.test(navigator.userAgent);
}

isReadOnly(): boolean {
return this.elementRef.nativeElement.hasAttribute('readonly')
}

registerOnChange(callbackFunction: Function): void {
this.inputHandler.setOnModelChange(callbackFunction);
}
Expand Down
8 changes: 3 additions & 5 deletions src/input.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class InputHandler {
}

this.inputService.addNumber(keyCode);
break;
}
}

Expand All @@ -57,7 +58,6 @@ export class InputHandler {

handleKeydown(event: any): void {
let keyCode = event.which || event.charCode || event.keyCode;

if (keyCode == 8 || keyCode == 46 || keyCode == 63272) {
event.preventDefault();
let selectionRangeLength = Math.abs(this.inputService.inputSelection.selectionEnd - this.inputService.inputSelection.selectionStart);
Expand All @@ -80,7 +80,7 @@ export class InputHandler {

handleKeypress(event: any): void {
let keyCode = event.which || event.charCode || event.keyCode;

event.preventDefault();
if (keyCode === 97 && event.ctrlKey) {
return;
}
Expand All @@ -89,8 +89,6 @@ export class InputHandler {
case undefined:
case 9:
case 13:
case 37:
case 39:
return;
case 43:
this.inputService.changeToPositive();
Expand All @@ -108,9 +106,9 @@ export class InputHandler {

this.inputService.addNumber(keyCode);
}
break;
}

event.preventDefault();
this.onModelChange(this.inputService.value);
}

Expand Down

0 comments on commit a7cc71e

Please sign in to comment.