From 082ea246a1004daa52d9722b8339d0211312051e Mon Sep 17 00:00:00 2001 From: mertsincan Date: Mon, 17 Apr 2023 14:59:33 +0300 Subject: [PATCH] Refactor #3832 Refactor #3833 - For Tree and TreeSelect --- components/lib/tree/TreeNode.vue | 6 +++++- components/lib/treeselect/TreeSelect.vue | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/lib/tree/TreeNode.vue b/components/lib/tree/TreeNode.vue index 91aaac164..13b71afb8 100755 --- a/components/lib/tree/TreeNode.vue +++ b/components/lib/tree/TreeNode.vue @@ -88,6 +88,7 @@ export default { } }, nodeTouched: false, + toggleClicked: false, mounted() { const hasTreeSelectParent = this.$refs.currentNode.closest('.p-treeselect-items-wrapper'); @@ -98,6 +99,7 @@ export default { methods: { toggle() { this.$emit('node-toggle', this.node); + this.toggleClicked = true; }, label(node) { return typeof node.label === 'function' ? node.label() : node.label; @@ -106,7 +108,9 @@ export default { this.$emit('node-toggle', node); }, onClick(event) { - if (DomHandler.hasClass(event.target, 'p-tree-toggler') || DomHandler.hasClass(event.target.parentElement, 'p-tree-toggler')) { + if (this.toggleClicked || DomHandler.hasClass(event.target, 'p-tree-toggler') || DomHandler.hasClass(event.target.parentElement, 'p-tree-toggler')) { + this.toggleClicked = false; + return; } diff --git a/components/lib/treeselect/TreeSelect.vue b/components/lib/treeselect/TreeSelect.vue index a91e4afb5..e01d31f4f 100644 --- a/components/lib/treeselect/TreeSelect.vue +++ b/components/lib/treeselect/TreeSelect.vue @@ -197,6 +197,7 @@ export default { scrollHandler: null, overlay: null, selfChange: false, + selfClick: false, beforeUnmount() { this.unbindOutsideClickListener(); this.unbindResizeListener(); @@ -337,8 +338,10 @@ export default { bindOutsideClickListener() { if (!this.outsideClickListener) { this.outsideClickListener = (event) => { - if (this.overlayVisible && this.isOutsideClicked(event)) { + if (this.overlayVisible && !this.selfClick && this.isOutsideClicked(event)) { this.hide(); + + this.selfClick = false; } }; @@ -395,6 +398,8 @@ export default { originalEvent: event, target: this.$el }); + + this.selfClick = true; }, onOverlayKeydown(event) { if (event.code === 'Escape') this.hide();