FIX: ensures popper's autocomplete instance is destroyed (#12476)

This commit is contained in:
Joffrey JAFFEUX 2021-03-22 16:19:36 +01:00 committed by GitHub
parent 129aeb8c2f
commit 4fb2d397a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import { iconHTML } from "discourse-common/lib/icon-library";
export const SKIP = "skip";
export const CANCELLED_STATUS = "__CANCELLED";
const allowedLettersRegex = /[\s\t\[\{\(\/]/;
let _autoCompletePopper;
const keys = {
backSpace: 8,
@ -112,6 +113,8 @@ export default function (options) {
let inputSelectedItems = [];
function closeAutocomplete() {
_autoCompletePopper && _autoCompletePopper.destroy();
if (div) {
div.hide().remove();
}
@ -119,6 +122,7 @@ export default function (options) {
completeStart = null;
autocompleteOptions = null;
prevTerm = null;
_autoCompletePopper = null;
}
function addInputSelectedItem(item, triggerChangeCallback) {
@ -315,7 +319,8 @@ export default function (options) {
}
if (isInput || options.treatAsTextarea) {
return createPopper(me[0], div[0], {
_autoCompletePopper && _autoCompletePopper.destroy();
_autoCompletePopper = createPopper(me[0], div[0], {
placement: "bottom-start",
strategy: "fixed",
modifiers: [
@ -327,6 +332,7 @@ export default function (options) {
},
],
});
return _autoCompletePopper;
}
let vOffset = 0;