Skip to content

Commit 5c23d97

Browse files
committed
doc: add tree-select demo
1 parent 95ce5f4 commit 5c23d97

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

components/tree-select/__tests__/__snapshots__/demo.test.js.snap

+11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ exports[`renders ./components/tree-select/demo/multiple.vue correctly 1`] = `
8888
</div>
8989
`;
9090
91+
exports[`renders ./components/tree-select/demo/replaceFields.vue correctly 1`] = `
92+
<div style="width: 100%;" class="ant-select ant-tree-select ant-select-single ant-select-allow-clear ant-select-show-arrow ant-select-show-search" customslots="[object Object]">
93+
<!---->
94+
<!---->
95+
<div class="ant-select-selector"><span class="ant-select-selection-search"><input id="rc_select_TEST_OR_SSR" autocomplete="off" class="ant-select-selection-search-input" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_TEST_OR_SSR_list" aria-autocomplete="list" aria-controls="rc_select_TEST_OR_SSR_list" type="search"></span>
96+
<!----><span class="ant-select-selection-placeholder">Please select</span>
97+
</div><span class="ant-select-arrow" style="user-select: none;" unselectable="on" aria-hidden="true"><span role="img" aria-label="down" class="anticon anticon-down ant-select-suffix"><svg focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></span></span>
98+
<!---->
99+
</div>
100+
`;
101+
91102
exports[`renders ./components/tree-select/demo/suffix.vue correctly 1`] = `
92103
<div class="ant-space ant-space-vertical" style="width: 100%;">
93104
<div class="ant-space-item" style="margin-bottom: 8px;">

components/tree-select/demo/index.vue

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<treeLineVue />
1111
<virtualScrollVue />
1212
<customTagRenderVue />
13+
<replaceFieldsVue />
1314
</demo-sort>
1415
</template>
1516
<script lang="ts">
@@ -23,6 +24,7 @@ import Highlight from './highlight.vue';
2324
import treeLineVue from './tree-line.vue';
2425
import virtualScrollVue from './virtual-scroll.vue';
2526
import customTagRenderVue from './custom-tag-render.vue';
27+
import replaceFieldsVue from './replaceFields.vue';
2628
import CN from '../index.zh-CN.md';
2729
import US from '../index.en-US.md';
2830
import { defineComponent } from 'vue';
@@ -41,6 +43,7 @@ export default defineComponent({
4143
treeLineVue,
4244
virtualScrollVue,
4345
customTagRenderVue,
46+
replaceFieldsVue,
4447
},
4548
setup() {
4649
return {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<docs>
2+
---
3+
order: 9
4+
title:
5+
zh-CN: 自定义字段
6+
en-US: ReplaceFields
7+
---
8+
9+
## zh-CN
10+
11+
fieldNames 替换 treeNode中 title,key,children 字段为treeData中对应的字段
12+
13+
## en-US
14+
15+
Replace the title,key and children fields in treeNode with the corresponding fields in treeData.
16+
17+
</docs>
18+
19+
<template>
20+
<a-tree-select
21+
v-model:value="value"
22+
show-search
23+
style="width: 100%"
24+
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
25+
placeholder="Please select"
26+
allow-clear
27+
tree-default-expand-all
28+
:tree-data="treeData"
29+
:field-names="{
30+
children: 'children',
31+
label: 'name',
32+
key: 'key',
33+
value: 'value',
34+
}"
35+
></a-tree-select>
36+
</template>
37+
<script lang="ts">
38+
import type { TreeSelectProps } from 'ant-design-vue';
39+
import { defineComponent, ref, watch } from 'vue';
40+
export default defineComponent({
41+
setup() {
42+
const value = ref<string>();
43+
const treeData = ref<TreeSelectProps['treeData']>([
44+
{
45+
name: 'parent 1',
46+
value: 'parent 1',
47+
children: [
48+
{
49+
name: 'parent 1-0',
50+
value: 'parent 1-0',
51+
children: [
52+
{
53+
name: 'my leaf',
54+
value: 'leaf1',
55+
},
56+
{
57+
name: 'your leaf',
58+
value: 'leaf2',
59+
},
60+
],
61+
},
62+
{
63+
name: 'parent 1-1',
64+
value: 'parent 1-1',
65+
},
66+
],
67+
},
68+
]);
69+
watch(value, () => {
70+
console.log(value.value);
71+
});
72+
return {
73+
value,
74+
treeData,
75+
};
76+
},
77+
});
78+
</script>

0 commit comments

Comments
 (0)