Skip to content

Commit db0b63c

Browse files
authored
fix(ui5-multi-combobox): pasting content should not be prevented (#8413)
FIXES: #8275
1 parent 8678dc0 commit db0b63c

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

packages/main/src/MultiComboBox.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ class MultiComboBox extends UI5Element {
724724
}
725725

726726
if (isInsertShift(e)) {
727-
this._handleInsertPaste();
727+
this._handleInsertPaste(e);
728728
return;
729729
}
730730

@@ -756,9 +756,22 @@ class MultiComboBox extends UI5Element {
756756
this._shouldAutocomplete = !this.noTypeahead && !(isBackSpace(e) || isDelete(e) || isEscape(e) || isEnter(e));
757757
}
758758

759-
_handlePaste(e:ClipboardEvent) {
760-
e.preventDefault();
759+
_selectItems(matchingItems: IMultiComboBoxItem[]) {
760+
this._previouslySelectedItems = this._getSelectedItems();
761761

762+
matchingItems.forEach(item => {
763+
item.selected = true;
764+
this.value = "";
765+
766+
const changePrevented = this.fireSelectionChange();
767+
768+
if (changePrevented) {
769+
this._revertSelection();
770+
}
771+
});
772+
}
773+
774+
_handlePaste(e: ClipboardEvent) {
762775
if (this.readonly || !e.clipboardData) {
763776
return;
764777
}
@@ -769,10 +782,20 @@ class MultiComboBox extends UI5Element {
769782
return;
770783
}
771784

772-
this._createTokenFromText(pastedText);
785+
this._handleTokenCreationUponPaste(pastedText, e);
786+
}
787+
788+
_handleTokenCreationUponPaste(pastedText: string, e: KeyboardEvent | ClipboardEvent) {
789+
const separatedText = pastedText.split(/\r\n|\r|\n|\t/g).filter(t => !!t);
790+
const matchingItems = this.items.filter(item => separatedText.includes(item.text) && !item.selected);
791+
792+
if (matchingItems.length > 1) {
793+
e.preventDefault();
794+
this._selectItems(matchingItems);
795+
}
773796
}
774797

775-
async _handleInsertPaste() {
798+
async _handleInsertPaste(e: KeyboardEvent) {
776799
if (this.readonly || isFirefox()) {
777800
return;
778801
}
@@ -783,29 +806,7 @@ class MultiComboBox extends UI5Element {
783806
return;
784807
}
785808

786-
this._createTokenFromText(pastedText);
787-
}
788-
789-
_createTokenFromText(pastedText: string) {
790-
const separatedText = pastedText.split(/\r\n|\r|\n|\t/g).filter(t => !!t);
791-
const matchingItems = this.items.filter(item => separatedText.indexOf(item.text) > -1 && !item.selected);
792-
793-
if (separatedText.length > 1) {
794-
this._previouslySelectedItems = this._getSelectedItems();
795-
matchingItems.forEach(item => {
796-
item.selected = true;
797-
this.value = "";
798-
799-
const changePrevented = this.fireSelectionChange();
800-
801-
if (changePrevented) {
802-
this._revertSelection();
803-
}
804-
});
805-
} else {
806-
this.value = pastedText;
807-
this.fireEvent("input");
808-
}
809+
this._handleTokenCreationUponPaste(pastedText, e);
809810
}
810811

811812
_handleShow(e: KeyboardEvent) {
@@ -1260,7 +1261,7 @@ class MultiComboBox extends UI5Element {
12601261
}
12611262

12621263
if (isInsertShift(e)) {
1263-
this._handleInsertPaste();
1264+
this._handleInsertPaste(e);
12641265
}
12651266

12661267
if (isHome(e)) {

packages/main/test/specs/MultiComboBox.spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,10 +1354,15 @@ describe("MultiComboBox general interaction", () => {
13541354
await input.click();
13551355
await input.keys(["Control", "v"]);
13561356

1357-
assert.equal(await mcb2.getProperty("value"), "Condensed", "Token is pasted into the second control");
1357+
assert.strictEqual(await mcb2.getProperty("value"), "Condensed", "Token is pasted into the second control");
1358+
assert.ok(await mcb2.getProperty("open"), "Condensed", "Popover should be open");
1359+
1360+
await input.keys(["Control", "v"]);
1361+
1362+
assert.equal(await mcb2.getProperty("value"), "CondensedCondensed", "Pasting second time should append the as text");
13581363
});
13591364

1360-
it ("should not be able to paste tokenwith CTRL+V in read only multi combo box", async () => {
1365+
it ("should not be able to paste token with CTRL+V in read only multi combo box", async () => {
13611366
await browser.url(`test/pages/MultiComboBox.html`);
13621367

13631368
const mcb = await browser.$("#multi1");

0 commit comments

Comments
 (0)