Merge pull request #6501 from KumJungMin/fix/issue-5967

feat: add expandedKeys, update emit event in TreeSelect
pull/6537/head
Tuğçe Küçükoğlu 2024-10-02 11:30:59 +03:00 committed by GitHub
commit 461652c39a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View File

@ -119,6 +119,10 @@ export default {
ariaLabel: { ariaLabel: {
type: String, type: String,
default: null default: null
},
expandedKeys: {
type: null,
default: null
} }
}, },
style: TreeSelectStyle, style: TreeSelectStyle,

View File

@ -73,7 +73,7 @@
:filterLocale="filterLocale" :filterLocale="filterLocale"
@update:selectionKeys="onSelectionChange" @update:selectionKeys="onSelectionChange"
:selectionKeys="modelValue" :selectionKeys="modelValue"
:expandedKeys="expandedKeys" :expandedKeys="d_expandedKeys"
@update:expandedKeys="onNodeToggle" @update:expandedKeys="onNodeToggle"
:metaKeySelection="metaKeySelection" :metaKeySelection="metaKeySelection"
@node-expand="$emit('node-expand', $event)" @node-expand="$emit('node-expand', $event)"
@ -133,7 +133,7 @@ export default {
name: 'TreeSelect', name: 'TreeSelect',
extends: BaseTreeSelect, extends: BaseTreeSelect,
inheritAttrs: false, 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: { inject: {
$pcFluid: { default: null } $pcFluid: { default: null }
}, },
@ -142,7 +142,7 @@ export default {
id: this.$attrs.id, id: this.$attrs.id,
focused: false, focused: false,
overlayVisible: false, overlayVisible: false,
expandedKeys: {} d_expandedKeys: this.expandedKeys || {}
}; };
}, },
watch: { watch: {
@ -161,6 +161,9 @@ export default {
}, },
options() { options() {
this.updateTreeState(); this.updateTreeState();
},
expandedKeys(value) {
this.d_expandedKeys = value;
} }
}, },
outsideClickListener: null, outsideClickListener: null,
@ -233,7 +236,9 @@ export default {
this.$emit('node-unselect', node); this.$emit('node-unselect', node);
}, },
onNodeToggle(keys) { onNodeToggle(keys) {
this.expandedKeys = keys; this.d_expandedKeys = keys;
this.$emit('update:expandedKeys', this.d_expandedKeys);
}, },
onFirstHiddenFocus(event) { onFirstHiddenFocus(event) {
const focusableEl = event.relatedTarget === this.$refs.focusInput ? getFirstFocusableElement(this.overlay, ':not([data-p-hidden-focusable="true"])') : this.$refs.focusInput; 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() { updateTreeState() {
let keys = { ...this.modelValue }; let keys = { ...this.modelValue };
this.expandedKeys = {};
if (keys && this.options) { if (keys && this.options) {
this.updateTreeBranchState(null, null, keys); this.updateTreeBranchState(null, null, keys);
} }
@ -470,8 +473,11 @@ export default {
expandPath(path) { expandPath(path) {
if (path.length > 0) { if (path.length > 0) {
for (let key of path) { 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() { scrollValueInView() {