Refactor #3832 Refactor #3833 - For Tree and TreeSelect

pull/3976/head
mertsincan 2023-04-17 14:59:33 +03:00
parent 99f9d351f9
commit 082ea246a1
2 changed files with 11 additions and 2 deletions

View File

@ -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;
}

View File

@ -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();