From 254eacc074556c6f80181593c8a627d81941ec37 Mon Sep 17 00:00:00 2001 From: KumJungMin Date: Tue, 1 Oct 2024 00:10:46 +0900 Subject: [PATCH] feat: add expandedKeys, update emit event in TreeSelect --- .../src/treeselect/BaseTreeSelect.vue | 4 ++++ .../primevue/src/treeselect/TreeSelect.vue | 20 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/primevue/src/treeselect/BaseTreeSelect.vue b/packages/primevue/src/treeselect/BaseTreeSelect.vue index 06ab49b77..4285375c0 100644 --- a/packages/primevue/src/treeselect/BaseTreeSelect.vue +++ b/packages/primevue/src/treeselect/BaseTreeSelect.vue @@ -119,6 +119,10 @@ export default { ariaLabel: { type: String, default: null + }, + expandedKeys: { + type: null, + default: null } }, style: TreeSelectStyle, diff --git a/packages/primevue/src/treeselect/TreeSelect.vue b/packages/primevue/src/treeselect/TreeSelect.vue index d92c8acb0..b75e196da 100644 --- a/packages/primevue/src/treeselect/TreeSelect.vue +++ b/packages/primevue/src/treeselect/TreeSelect.vue @@ -73,7 +73,7 @@ :filterLocale="filterLocale" @update:selectionKeys="onSelectionChange" :selectionKeys="modelValue" - :expandedKeys="expandedKeys" + :expandedKeys="d_expandedKeys" @update:expandedKeys="onNodeToggle" :metaKeySelection="metaKeySelection" @node-expand="$emit('node-expand', $event)" @@ -133,7 +133,7 @@ export default { name: 'TreeSelect', extends: BaseTreeSelect, inheritAttrs: false, - emits: ['update:modelValue', 'before-show', 'before-hide', 'change', 'show', 'hide', 'node-select', 'node-unselect', 'node-expand', 'node-collapse', 'focus', 'blur'], + emits: ['update:modelValue', 'before-show', 'before-hide', 'change', 'show', 'hide', 'node-select', 'node-unselect', 'node-expand', 'node-collapse', 'focus', 'blur', 'update:expandedKeys'], inject: { $pcFluid: { default: null } }, @@ -142,7 +142,7 @@ export default { id: this.$attrs.id, focused: false, overlayVisible: false, - expandedKeys: {} + d_expandedKeys: this.expandedKeys || {} }; }, watch: { @@ -161,6 +161,9 @@ export default { }, options() { this.updateTreeState(); + }, + expandedKeys(value) { + this.d_expandedKeys = value; } }, outsideClickListener: null, @@ -233,7 +236,9 @@ export default { this.$emit('node-unselect', node); }, onNodeToggle(keys) { - this.expandedKeys = keys; + this.d_expandedKeys = keys; + + this.$emit('update:expandedKeys', this.d_expandedKeys); }, onFirstHiddenFocus(event) { const focusableEl = event.relatedTarget === this.$refs.focusInput ? getFirstFocusableElement(this.overlay, ':not([data-p-hidden-focusable="true"])') : this.$refs.focusInput; @@ -442,8 +447,6 @@ export default { updateTreeState() { let keys = { ...this.modelValue }; - this.expandedKeys = {}; - if (keys && this.options) { this.updateTreeBranchState(null, null, keys); } @@ -470,8 +473,11 @@ export default { expandPath(path) { if (path.length > 0) { for (let key of path) { - this.expandedKeys[key] = true; + this.d_expandedKeys[key] = true; } + + this.d_expandedKeys = { ...this.d_expandedKeys }; + this.$emit('update:expandedKeys', this.d_expandedKeys); } }, scrollValueInView() {