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(SelectTree, SelectCascader): expandedKeys 支持 v-model #737

Merged
merged 1 commit into from
Apr 16, 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
25 changes: 16 additions & 9 deletions components/select-cascader/selectCascader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
<Cascader
v-show="!filterText"
ref="cascaderRef"
v-model:expandedKeys="expandedKeys"
:selectedKeys="selectedKeys"
:checkedKeys="checkedKeys"
:initLoadKeys="initLoadKeys"
:data="data"
:emptyText="listEmptyText"
:expandedKeys="expandedKeys"
:selectable="cascaderSelectable"
:checkable="cascaderCheckable"
:checkStrictly="checkStrictly"
Expand Down Expand Up @@ -161,6 +161,7 @@ export default defineComponent({
emits: [
UPDATE_MODEL_EVENT,
CHANGE_EVENT,
'update:expandedKeys',
'removeTag',
'visibleChange',
'focus',
Expand All @@ -173,6 +174,7 @@ export default defineComponent({
valueType: computed(() => (props.multiple ? 'array' : 'string')),
});
const isOpened = ref(false);

const [currentValue, updateCurrentValue] = props.multiple
? // 与 props 中 modelValue 类型保持一致
(useArrayModel(props, emit) as unknown as UseArrayModelReturn<
Expand Down Expand Up @@ -248,14 +250,19 @@ export default defineComponent({
}
return [];
});
const expandedKeys = computed(() => {
if (!props.multiple) {
return getExpandedKeysBySelectedKeys(
nodeList.value,
selectedKeys.value as CascaderNodeKey[],
);
}
return [];
const expandedKeys = computed({
get: () => {
if (!props.multiple) {
return getExpandedKeysBySelectedKeys(
nodeList.value,
selectedKeys.value as CascaderNodeKey[],
);
}
return [];
},
set: (nextValue) => {
emit('update:expandedKeys', nextValue);
},
});
const checkedKeys = computed(() => {
if (props.multiple) {
Expand Down
11 changes: 9 additions & 2 deletions components/select-tree/selectTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
<Tree
v-show="data.length"
ref="refTree"
v-model:expandedKeys="currentExpandedKeys"
:selectedKeys="selectedKeys"
:checkedKeys="checkedKeys"
:data="data"
:defaultExpandAll="defaultExpandAll"
:expandedKeys="expandedKeys"
:accordion="accordion"
:selectable="treeSelectable"
:checkable="treeCheckable"
Expand Down Expand Up @@ -83,11 +83,11 @@
<Tree
v-show="data.length"
ref="refTree"
v-model:expandedKeys="currentExpandedKeys"
:selectedKeys="selectedKeys"
:checkedKeys="checkedKeys"
:data="data"
:defaultExpandAll="defaultExpandAll"
:expandedKeys="expandedKeys"
:accordion="accordion"
:selectable="treeSelectable"
:checkable="treeCheckable"
Expand Down Expand Up @@ -194,6 +194,7 @@ export default defineComponent({
emits: [
UPDATE_MODEL_EVENT,
CHANGE_EVENT,
'update:expandedKeys',
'removeTag',
'visibleChange',
'focus',
Expand All @@ -206,12 +207,17 @@ export default defineComponent({
valueType: computed(() => (props.multiple ? 'array' : 'string')),
});
const isOpened = ref(false);

const [currentValue, updateCurrentValue] = props.multiple
? // 与 props 中 modelValue 类型保持一致
(useArrayModel(props, emit) as unknown as UseArrayModelReturn<
Array<TreeNodeKey> | Array<Array<TreeNodeKey>>
>)
: useNormalModel(props, emit);
const [currentExpandedKeys] = useNormalModel(props, emit, {
prop: 'expandedKeys',
});

const filterText = ref('');

const { t } = useLocale();
Expand Down Expand Up @@ -434,6 +440,7 @@ export default defineComponent({
prefixCls,
isOpened,
currentValue,
currentExpandedKeys,
handleRemove,
handleClear,
selectedOptions,
Expand Down
19 changes: 6 additions & 13 deletions docs/.vitepress/components/selectTree/common.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<FSelectTree :modelValue="'40'" :data="data"></FSelectTree>
<FSelectTree :modelValue="'40'" :data="data" />
</template>
<script>
<script setup>
import { ref, h } from 'vue';
// eslint-disable-next-line import/no-unresolved
import { PictureOutlined, PlusCircleOutlined } from '@fesjs/fes-design/icon';
Expand All @@ -27,17 +27,10 @@ function createLabel(level) {
if (level === 1) return '三生万物';
}

export default {
setup() {
const data = ref([]);
setTimeout(() => {
data.value = createData(4);
});
return {
data,
};
},
};
const data = ref([]);
setTimeout(() => {
data.value = createData(4);
});
</script>
<style scoped>
.fes-select-tree {
Expand Down