From 8cd82a3bb6be1984fafca45f27ee2158acc8cb78 Mon Sep 17 00:00:00 2001 From: Yair Even Or Date: Sat, 16 Mar 2024 20:59:45 +0100 Subject: [PATCH] minor code adjustment for `select` mode --- src/tagify.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tagify.js b/src/tagify.js index 496a8231..e2b315e6 100644 --- a/src/tagify.js +++ b/src/tagify.js @@ -493,8 +493,6 @@ Tagify.prototype = { tagElm = tagElm || this.getLastTag() opts = opts || {} - this.dropdown.hide() - var _s = this.settings, editableElm = this.getTagTextNode(tagElm), tagIdx = this.getNodeIndex(tagElm), @@ -502,6 +500,10 @@ Tagify.prototype = { _CB = this.events.callbacks, isValid = true + // select mode is a bit different as clicking the tagify's content once will get into edit-mode if a value + // is already selected, and there cannot be a dropdown already open at this point. + _s.mode != 'select' && this.dropdown.hide() + if( !editableElm ){ Tagify.logger.warn('Cannot find element in Tag template: .', _s.classNames.tagTextSelector); return; @@ -522,7 +524,6 @@ Tagify.prototype = { tagElm.classList.add( _s.classNames.tagEditing ) editableElm.addEventListener('click' , _CB.onEditTagClick.bind(this, tagElm)) - editableElm.addEventListener('focus' , _CB.onEditTagFocus.bind(this, tagElm)) editableElm.addEventListener('blur' , _CB.onEditTagBlur.bind(this, this.getTagTextNode(tagElm))) editableElm.addEventListener('input' , _CB.onEditTagInput.bind(this, editableElm)) editableElm.addEventListener('paste' , _CB.onEditTagPaste.bind(this, editableElm)) @@ -1642,7 +1643,7 @@ Tagify.prototype = { }, removeTagsFromDOM(){ - [].slice.call(this.getTagElms()).forEach(elm => elm.parentNode.removeChild(elm)) + this.getTagElms().forEach(node => node.remove()) }, /**