Skip to content

Commit

Permalink
Merge pull request #6501 from KumJungMin/fix/issue-5967
Browse files Browse the repository at this point in the history
feat: add expandedKeys, update emit event in TreeSelect
  • Loading branch information
tugcekucukoglu authored Oct 2, 2024
2 parents f247f28 + 254eacc commit 461652c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/primevue/src/treeselect/BaseTreeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export default {
ariaLabel: {
type: String,
default: null
},
expandedKeys: {
type: null,
default: null
}
},
style: TreeSelectStyle,
Expand Down
20 changes: 13 additions & 7 deletions packages/primevue/src/treeselect/TreeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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 }
},
Expand All @@ -142,7 +142,7 @@ export default {
id: this.$attrs.id,
focused: false,
overlayVisible: false,
expandedKeys: {}
d_expandedKeys: this.expandedKeys || {}
};
},
watch: {
Expand All @@ -161,6 +161,9 @@ export default {
},
options() {
this.updateTreeState();
},
expandedKeys(value) {
this.d_expandedKeys = value;
}
},
outsideClickListener: null,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -442,8 +447,6 @@ export default {
updateTreeState() {
let keys = { ...this.modelValue };
this.expandedKeys = {};
if (keys && this.options) {
this.updateTreeBranchState(null, null, keys);
}
Expand All @@ -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() {
Expand Down

0 comments on commit 461652c

Please sign in to comment.