Skip to content

Commit f8a7170

Browse files
authored
Merge pull request DSpace#4670 from DSpace/backport-4664-to-dspace-8_x
[Port dspace-8_x] Inspect event key characters, not keyCodes on tag keyUp for dynamic tag input
2 parents 9c0b8cf + fb66397 commit f8a7170

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
@@ -220,13 +220,15 @@ export class DsDynamicTagComponent extends DsDynamicVocabularyComponent implemen
220220
}
221221

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

0 commit comments

Comments
 (0)