From a6c813b3463f55292c91cb34dabb88c4eb6fcc44 Mon Sep 17 00:00:00 2001 From: panoramix360 Date: Wed, 6 Nov 2024 00:53:46 -0300 Subject: [PATCH] feat: changes the separators when the user is typing --- .../chip-list-input/chip-list-input.component.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/ui/chip-list-input/chip-list-input.component.ts b/src/app/ui/chip-list-input/chip-list-input.component.ts index a48de2d94d5..6ff06eb33b4 100644 --- a/src/app/ui/chip-list-input/chip-list-input.component.ts +++ b/src/app/ui/chip-list-input/chip-list-input.component.ts @@ -20,6 +20,8 @@ import { map, startWith } from 'rxjs/operators'; import { COMMA, ENTER } from '@angular/cdk/keycodes'; import { T } from '../../t.const'; +const DEFAULT_SEPARATOR_KEY_CODES: number[] = [ENTER, COMMA]; + interface Suggestion { id: string; title: string; @@ -51,7 +53,7 @@ export class ChipListInputComponent implements OnDestroy { suggestionsIn: Suggestion[] = []; modelItems: Suggestion[] = []; inputCtrl: UntypedFormControl = new UntypedFormControl(); - separatorKeysCodes: number[] = [ENTER, COMMA]; + separatorKeysCodes: number[] = DEFAULT_SEPARATOR_KEY_CODES; isAutoFocus = false; @ViewChild('inputElRef', { static: true }) inputEl?: ElementRef; @ViewChild('autoElRef', { static: true }) matAutocomplete?: MatAutocomplete; @@ -133,6 +135,8 @@ export class ChipListInputComponent implements OnDestroy { } triggerCtrlEnterSubmit(ev: KeyboardEvent): void { + this._detectKeyboardLayout(ev); + if (ev.code === 'Enter' && ev.ctrlKey) { this.ctrlEnterSubmit.next(); } @@ -178,4 +182,14 @@ export class ChipListInputComponent implements OnDestroy { !this._modelIds.includes(suggestion.id), ); } + + private _detectKeyboardLayout(event: KeyboardEvent): void { + const isCyrillic = /^[А-яёЁ]$/.test(event.key); + + if (isCyrillic) { + this.separatorKeysCodes = [ENTER]; + } else { + this.separatorKeysCodes = DEFAULT_SEPARATOR_KEY_CODES; + } + } }