mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix: Typescript - Tree component DirectoryTreeProps, missing Node Type (#36092)
* fix: edit DirectoryTreeProps * test: add DirectoryTree type test * fix: edit type Co-authored-by: JaylanChen <JaylanChen@126.com>
This commit is contained in:
parent
89717f1b0f
commit
f19cf66c88
@ -1,24 +1,32 @@
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import type RcTree from 'rc-tree';
|
||||
import { conductExpandParent } from 'rc-tree/lib/util';
|
||||
import type { EventDataNode, DataNode, Key } from 'rc-tree/lib/interface';
|
||||
import { convertDataToEntities, convertTreeToData } from 'rc-tree/lib/utils/treeUtil';
|
||||
import FileOutlined from '@ant-design/icons/FileOutlined';
|
||||
import FolderOpenOutlined from '@ant-design/icons/FolderOpenOutlined';
|
||||
import FolderOutlined from '@ant-design/icons/FolderOutlined';
|
||||
import classNames from 'classnames';
|
||||
import type RcTree from 'rc-tree';
|
||||
import type { BasicDataNode } from 'rc-tree';
|
||||
import type { DataNode, EventDataNode, Key } from 'rc-tree/lib/interface';
|
||||
import { conductExpandParent } from 'rc-tree/lib/util';
|
||||
import { convertDataToEntities, convertTreeToData } from 'rc-tree/lib/utils/treeUtil';
|
||||
import * as React from 'react';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
|
||||
import type { TreeProps, AntdTreeNodeAttribute } from './Tree';
|
||||
import type { AntdTreeNodeAttribute, TreeProps } from './Tree';
|
||||
import Tree from './Tree';
|
||||
import { calcRangeKeys, convertDirectoryKeysToNodes } from './utils/dictUtil';
|
||||
|
||||
export type ExpandAction = false | 'click' | 'doubleClick';
|
||||
|
||||
export interface DirectoryTreeProps extends TreeProps {
|
||||
export interface DirectoryTreeProps<T extends BasicDataNode = DataNode> extends TreeProps<T> {
|
||||
expandAction?: ExpandAction;
|
||||
}
|
||||
|
||||
type DirectoryTreeCompoundedComponent = (<T extends BasicDataNode | DataNode = DataNode>(
|
||||
props: React.PropsWithChildren<DirectoryTreeProps<T>> & { ref?: React.Ref<RcTree> },
|
||||
) => React.ReactElement) & {
|
||||
defaultProps: Partial<React.PropsWithChildren<DirectoryTreeProps<any>>>;
|
||||
displayName?: string;
|
||||
};
|
||||
|
||||
export interface DirectoryTreeState {
|
||||
expandedKeys?: Key[];
|
||||
selectedKeys?: Key[];
|
||||
@ -191,7 +199,10 @@ const DirectoryTree: React.ForwardRefRenderFunction<RcTree, DirectoryTreeProps>
|
||||
);
|
||||
};
|
||||
|
||||
const ForwardDirectoryTree = React.forwardRef(DirectoryTree);
|
||||
const ForwardDirectoryTree = React.forwardRef(
|
||||
DirectoryTree,
|
||||
) as unknown as DirectoryTreeCompoundedComponent;
|
||||
|
||||
ForwardDirectoryTree.displayName = 'DirectoryTree';
|
||||
|
||||
ForwardDirectoryTree.defaultProps = {
|
||||
|
@ -3,6 +3,8 @@ import * as React from 'react';
|
||||
import { render } from '../../../tests/utils';
|
||||
import Tree from '../index';
|
||||
|
||||
const { DirectoryTree } = Tree;
|
||||
|
||||
describe('Tree.TypeScript', () => {
|
||||
it('without generic', () => {
|
||||
const { container } = render(
|
||||
@ -48,4 +50,29 @@ describe('Tree.TypeScript', () => {
|
||||
|
||||
expect(container).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
it('directoryTree support generic', () => {
|
||||
interface MyDataNode extends BasicDataNode {
|
||||
bamboo: string;
|
||||
list?: MyDataNode[];
|
||||
}
|
||||
|
||||
const { container } = render(
|
||||
<DirectoryTree<MyDataNode>
|
||||
treeData={[
|
||||
{
|
||||
bamboo: 'good',
|
||||
list: [
|
||||
{
|
||||
bamboo: 'well',
|
||||
},
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user