Skip to content

Commit b980a6b

Browse files
authored
Do not emit selectedTags if there are no tags to paste (#806)
1 parent 97e665e commit b980a6b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/mixins/multipleSelection.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,15 @@ export default {
537537
}
538538

539539
this.setFilterInput(input.trim());
540-
if (this.allSelectedTagsAreActive) {
541-
this.setSelectedTags(tags);
542-
} else {
543-
this.updateSelectedTags(tags);
540+
541+
if (tags.length) {
542+
if (this.allSelectedTagsAreActive) {
543+
this.setSelectedTags(tags);
544+
} else {
545+
this.updateSelectedTags(tags);
546+
}
544547
}
548+
545549
this.resetActiveTags();
546550
},
547551
/**

tests/unit/components/Filter/FilterInput.spec.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,20 @@ describe('FilterInput', () => {
414414
// assert the input and tags are emitted
415415
expect(wrapper.emitted('input')).toHaveLength(1);
416416
expect(wrapper.emitted('input')[0]).toEqual(['Title']);
417-
expect(wrapper.emitted('update:selectedTags')).toHaveLength(1);
418-
expect(wrapper.emitted('update:selectedTags')[0]).toEqual([[]]);
417+
});
418+
419+
it('on paste, do not emit selectedTags if there are no tags to paste', () => {
420+
clipboardData.getData = jest.fn((param) => {
421+
if (param === 'text/plain') return 'Title';
422+
return prepareDataForHTMLClipboard({
423+
input: 'baz',
424+
tags: [],
425+
});
426+
});
427+
clipboardData.types.push('text/html');
428+
429+
input.trigger('paste', { clipboardData });
430+
expect(wrapper.emitted('update:selectedTags')).toBeFalsy();
419431
});
420432

421433
it('on paste, reads directly from plain text, if json is not available', () => {
@@ -428,8 +440,6 @@ describe('FilterInput', () => {
428440
// assert the input and tags are emitted
429441
expect(wrapper.emitted('input')).toHaveLength(1);
430442
expect(wrapper.emitted('input')[0]).toEqual(['[tag1][tag2] string']);
431-
expect(wrapper.emitted('update:selectedTags')).toHaveLength(1);
432-
expect(wrapper.emitted('update:selectedTags')[0]).toEqual([[]]);
433443
});
434444

435445
it('on paste, overwrites all the tags if they are selected', () => {

0 commit comments

Comments
 (0)