From 0f69f7bb3c57e278fc9d9655c40a1135c458445d Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Mon, 28 Oct 2024 12:23:08 +0000 Subject: [PATCH] allow meta characters for safari --- .../lib/ngx-mat-intl-tel-input.component.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/projects/ngx-mat-intl-tel-input/src/lib/ngx-mat-intl-tel-input.component.ts b/projects/ngx-mat-intl-tel-input/src/lib/ngx-mat-intl-tel-input.component.ts index 417b7b24d..fa7da83b9 100644 --- a/projects/ngx-mat-intl-tel-input/src/lib/ngx-mat-intl-tel-input.component.ts +++ b/projects/ngx-mat-intl-tel-input/src/lib/ngx-mat-intl-tel-input.component.ts @@ -281,6 +281,11 @@ export class NgxMatIntlTelInputComponent } public onInputKeyPress(event: KeyboardEvent): void { + // Allow keyboard shortcuts (Cmd/Ctrl + A/C/V/X) + if (event.metaKey || event.ctrlKey) { + return; + } + const pattern = /[0-9+\- ]/; if (!pattern.test(event.key)) { event.preventDefault(); @@ -361,14 +366,14 @@ export class NgxMatIntlTelInputComponent return !this.phoneNumber; } - @HostBinding('class.ngx-floating') + @HostBinding("class.ngx-floating") get shouldLabelFloat(): boolean { return this.focused || !this.empty; } @Input() get placeholder(): string { - return this._placeholder || ''; + return this._placeholder || ""; } set placeholder(value: string) { @@ -397,17 +402,17 @@ export class NgxMatIntlTelInputComponent } setDescribedByIds(ids: string[]) { - this.describedBy = ids.join(' '); + this.describedBy = ids.join(" "); } onContainerClick(event: MouseEvent): void { - if ((event.target as Element).tagName.toLowerCase() !== 'input') { - this.elRef.nativeElement.querySelector('input')!.focus(); + if ((event.target as Element).tagName.toLowerCase() !== "input") { + this.elRef.nativeElement.querySelector("input")!.focus(); } } reset(): void { - this.phoneNumber = ''; + this.phoneNumber = ""; this.propagateChange(null); this._changeDetectorRef.markForCheck(); @@ -421,12 +426,12 @@ export class NgxMatIntlTelInputComponent private get formattedPhoneNumber(): string { if (!this.numberInstance) { - return this.phoneNumber?.toString() || ''; + return this.phoneNumber?.toString() || ""; } switch (this.format) { - case 'national': + case "national": return this.numberInstance.formatNational(); - case 'international': + case "international": return this.numberInstance.formatInternational(); default: return this.numberInstance.nationalNumber.toString(); @@ -434,7 +439,7 @@ export class NgxMatIntlTelInputComponent } private formatAsYouTypeIfEnabled(): void { - if (this.format === 'default') { + if (this.format === "default") { return; } const asYouType: AsYouType = new AsYouType( @@ -444,7 +449,7 @@ export class NgxMatIntlTelInputComponent if ( this.phoneNumber ?.toString() - .startsWith(this.previousFormattedNumber || '') + .startsWith(this.previousFormattedNumber || "") ) { this.phoneNumber = asYouType.input(this.phoneNumber.toString()); }