Skip to content

Commit 6071065

Browse files
authored
Merge pull request #4669 from DSpace/backport-4664-to-dspace-7_x
[Port dspace-7_x] Inspect event key characters, not keyCodes on tag keyUp for dynamic tag input
2 parents f531415 + 86a18f3 commit 6071065

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
@@ -22,10 +22,10 @@ import {
2222
mockDynamicFormValidationService
2323
} from '../../../../../testing/dynamic-form-mock-services';
2424

25-
function createKeyUpEvent(key: number) {
25+
function createKeyUpEvent(key: string) {
2626
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
2727
const event = {
28-
keyCode: key, preventDefault: () => {
28+
key: key, preventDefault: () => {
2929
}, stopPropagation: () => {
3030
}
3131
};
@@ -256,8 +256,8 @@ describe('DsDynamicTagComponent test suite', () => {
256256
expect(tagComp.chips.getChipsItems()).toEqual(chips.getChipsItems());
257257
});
258258

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

263263
tagFixture.detectChanges();
@@ -268,7 +268,7 @@ describe('DsDynamicTagComponent test suite', () => {
268268
expect(tagComp.model.value).toEqual(['test value']);
269269
expect(tagComp.currentValue).toBeNull();
270270

271-
event = createKeyUpEvent(188);
271+
event = createKeyUpEvent(',');
272272
tagComp.currentValue = 'test value';
273273

274274
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
@@ -180,13 +180,15 @@ export class DsDynamicTagComponent extends DsDynamicVocabularyComponent implemen
180180
}
181181

182182
/**
183-
* Add a new tag with typed text when typing 'Enter' or ',' or ';'
183+
* Add a new tag with typed text when typing 'Enter' or ','
184+
* Tests the key rather than keyCode as keyCodes can vary
185+
* based on keyboard layout (and do not consider Shift mod)
184186
* @param event the keyUp event
185187
*/
186188
onKeyUp(event) {
187-
if (event.keyCode === 13 || event.keyCode === 188) {
189+
if (event.key === 'Enter' || event.key === ',') {
188190
event.preventDefault();
189-
// Key: 'Enter' or ',' or ';'
191+
// Key: 'Enter' or ','
190192
this.addTagsToChips();
191193
event.stopPropagation();
192194
}

0 commit comments

Comments
 (0)