Skip to content
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
2 changes: 2 additions & 0 deletions components/tree/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
InjectionKey,
PropType,
Ref,
Slots,
} from 'vue';
import { extractPropsDefaultValue } from '../_util/utils';
import type { ExtractPublicPropTypes } from '../_util/interface';
Expand Down Expand Up @@ -121,6 +122,7 @@ export type TreeProps = ExtractPublicPropTypes<typeof treeProps>;

export interface TreeInst {
props: TreeProps;
slots: Slots;
selectNode: (value: TreeNodeKey, event: Event) => void;
expandNode: (value: TreeNodeKey, event: Event) => void;
checkNode: (value: TreeNodeKey, event: Event) => void;
Expand Down
31 changes: 16 additions & 15 deletions components/tree/tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default defineComponent({
'dragend',
'drop',
],
setup(props, { emit, expose }) {
setup(props, { emit, expose, slots }) {
useTheme();
const { nodeList, allKeys } = useData({
props,
Expand Down Expand Up @@ -123,6 +123,7 @@ export default defineComponent({

provide(TREE_PROVIDE_KEY, {
props,
slots,
selectNode,
expandNode,
checkNode,
Expand Down Expand Up @@ -188,22 +189,22 @@ export default defineComponent({
return () =>
props.virtualList && !props.inline
? (
<VirtualList
dataSources={currentData.value}
dataKey={(source: TreeNodeKey) => {
return source;
}}
estimateSize={32}
keeps={14}
observeResize={false}
class={prefixCls}
v-slots={{ default: renderDefault }}
/>
<VirtualList
dataSources={currentData.value}
dataKey={(source: TreeNodeKey) => {
return source;
}}
estimateSize={32}
keeps={14}
observeResize={false}
class={prefixCls}
v-slots={{ default: renderDefault }}
/>
)
: (
<div class={prefixCls} role="tree">
{renderChildren(currentData.value)}
</div>
<div class={prefixCls} role="tree">
{renderChildren(currentData.value)}
</div>
);
},
});
24 changes: 16 additions & 8 deletions components/tree/treeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import FEllipsis from '../ellipsis';
import TextHightlight from '../text-highlight';
import { COMPONENT_NAME, INDENT } from './const';
import useTreeNode from './useTreeNode';
import type { TreeOption } from './interface';

const prefixCls = getPrefixCls('tree-node');

Expand All @@ -27,7 +28,7 @@ const treeNodeProps = {
required: true,
},
label: {
type: [String, Function] as PropType<string | (() => VNodeChild)>,
type: [String, Function] as PropType<string | ((node: TreeOption) => VNodeChild)>,
required: true,
},
disabled: {
Expand Down Expand Up @@ -191,9 +192,9 @@ export default defineComponent({
const icon = isLoading.value
? <LoadingOutlined />
: (
<CaretDownOutlined
class={[`${prefixCls}-switcher-icon`, isExpanded.value ? 'is-expanded' : '']}
/>
<CaretDownOutlined
class={[`${prefixCls}-switcher-icon`, isExpanded.value ? 'is-expanded' : '']}
/>
);

return (
Expand Down Expand Up @@ -256,10 +257,17 @@ export default defineComponent({
};

const renderLabel = () => {
const node = root.nodeList.get(props.value);
if (isFunction(props.label)) {
return (
<span class={`${prefixCls}-content-label`}>
{props.label()}
{props.label(node)}
</span>
);
} else if (isFunction(root.slots.label)) {
return (
<span class={`${prefixCls}-content-label`}>
{root.slots.label(node)}
</span>
);
}
Expand All @@ -269,9 +277,9 @@ export default defineComponent({
>
{root.props.filterTextHighlight && root.props.filterText
? (
<TextHightlight strict searchValues={[root.props.filterText]}>
{props.label}
</TextHightlight>
<TextHightlight strict searchValues={[root.props.filterText]}>
{props.label}
</TextHightlight>
)
: props.label
}
Expand Down
6 changes: 6 additions & 0 deletions docs/.vitepress/components/tree/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ app.use(FTree);
| expandNode | 展开树节点 | (value) |
| checkNode | check 节点 | (value) |

## Tree Slots

| 名称 | 说明 |
| ------- | ------------------------------ |
| label | treeOption 优先级比这个高 |

## TreeOption props

| 属性 | 说明 | 类型 | 默认值 |
Expand Down