Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add expandedKeys, update emit event in TreeSelect #6501

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading