Skip to content

Commit c48c4ad

Browse files
authored
Merge pull request #4664 from kshepherd/split_dynamic_tags_on_keychars
Inspect event key characters, not keyCodes on tag keyUp for dynamic tag input
2 parents 7c8486a + 98fc76d commit c48c4ad

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ import { FormFieldMetadataValueObject } from '../../../models/form-field-metadat
4545
import { DsDynamicTagComponent } from './dynamic-tag.component';
4646
import { DynamicTagModel } from './dynamic-tag.model';
4747

48-
function createKeyUpEvent(key: number) {
48+
function createKeyUpEvent(key: string) {
4949
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
5050
const event = {
51-
keyCode: key, preventDefault: () => {
51+
key: key, preventDefault: () => {
5252
}, stopPropagation: () => {
5353
},
5454
};
@@ -278,8 +278,8 @@ describe('DsDynamicTagComponent test suite', () => {
278278
expect(tagComp.chips.getChipsItems()).toEqual(chips.getChipsItems());
279279
});
280280

281-
it('should add an item on ENTER or key press is \',\' or \';\'', fakeAsync(() => {
282-
let event = createKeyUpEvent(13);
281+
it('should add an item on ENTER or key press is \',\'', fakeAsync(() => {
282+
let event = createKeyUpEvent('Enter');
283283
tagComp.currentValue = 'test value';
284284

285285
tagFixture.detectChanges();
@@ -290,7 +290,7 @@ describe('DsDynamicTagComponent test suite', () => {
290290
expect(tagComp.model.value).toEqual(['test value']);
291291
expect(tagComp.currentValue).toBeNull();
292292

293-
event = createKeyUpEvent(188);
293+
event = createKeyUpEvent(',');
294294
tagComp.currentValue = 'test value';
295295

296296
tagFixture.detectChanges();

src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,15 @@ export class DsDynamicTagComponent extends DsDynamicVocabularyComponent implemen
219219
}
220220

221221
/**
222-
* Add a new tag with typed text when typing 'Enter' or ',' or ';'
222+
* Add a new tag with typed text when typing 'Enter' or ','
223+
* Tests the key rather than keyCode as keyCodes can vary
224+
* based on keyboard layout (and do not consider Shift mod)
223225
* @param event the keyUp event
224226
*/
225227
onKeyUp(event) {
226-
if (event.keyCode === 13 || event.keyCode === 188) {
228+
if (event.key === 'Enter' || event.key === ',') {
227229
event.preventDefault();
228-
// Key: 'Enter' or ',' or ';'
230+
// Key: 'Enter' or ','
229231
this.addTagsToChips();
230232
event.stopPropagation();
231233
}

0 commit comments

Comments
 (0)