diff --git a/src/TreeView/index.tsx b/src/TreeView/index.tsx index b493243..6ae6761 100644 --- a/src/TreeView/index.tsx +++ b/src/TreeView/index.tsx @@ -554,7 +554,8 @@ export interface ITreeViewProps { focusedId?: NodeId; } -function TreeViewInner( +const TreeView = React.forwardRef( +function TreeView( { data, selectedIds, @@ -670,12 +671,9 @@ function TreeViewInner( ))} ) - } + }) - const TreeView = React.forwardRef(TreeViewInner) as ( - props: ITreeViewProps & React.RefAttributes - ) => ReturnType; @@ -981,7 +979,7 @@ const handleKeyDown = ({ } }; -//@ts-expect-error type assertion for ts + TreeView.propTypes = { /** Tree data*/ data: PropTypes.array.isRequired, diff --git a/src/TreeView/node.tsx b/src/TreeView/node.tsx index 6d825a3..a4f3f1b 100644 --- a/src/TreeView/node.tsx +++ b/src/TreeView/node.tsx @@ -26,7 +26,7 @@ import { } from "./utils"; import { baseClassNames, clickActions, treeTypes } from "./constants"; -export interface INodeProps { +export interface INodeProps { element: INode; dispatch: React.Dispatch; data: INode[]; @@ -54,7 +54,7 @@ export interface INodeProps { propagateSelectUpwards: boolean; } -export interface INodeGroupProps +export interface INodeGroupProps extends Omit, "setsize" | "posinset"> { getClasses: (className: string) => string; /** don't send this. The NodeGroup render function, determines it for you */ @@ -66,7 +66,7 @@ export interface INodeGroupProps /** * It's convenient to pass props down to the child, but we don't want to pass everything since it would create incorrect values for setsize and posinset */ -const removeIrrelevantGroupProps = ( +const removeIrrelevantGroupProps = ( nodeProps: INodeProps ): Omit, "getClasses"> => { // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -74,7 +74,7 @@ const removeIrrelevantGroupProps = ( return rest; }; -export const Node = (props: INodeProps) => { +export const Node = (props: INodeProps) => { const { element, dispatch, @@ -330,7 +330,7 @@ export const NodeGroup = ({ expandedIds={expandedIds} baseClassNames={baseClassNames} key={`${x}-${typeof x}`} - element={getTreeNode(data, x) as INode} + element={getTreeNode(data, x)} setsize={element.children.length} posinset={index + 1} level={level + 1} diff --git a/src/TreeView/types.ts b/src/TreeView/types.ts index 22ff668..bea0c94 100644 --- a/src/TreeView/types.ts +++ b/src/TreeView/types.ts @@ -33,7 +33,7 @@ export type EventCallback = ( metadata?: M; } - export interface INodeRendererProps { + export interface INodeRendererProps { /** The object that represents the rendered node */ element: INode; /** A function which gives back the props to pass to the node */ diff --git a/src/TreeView/utils.ts b/src/TreeView/utils.ts index 1375860..a7b53c2 100644 --- a/src/TreeView/utils.ts +++ b/src/TreeView/utils.ts @@ -307,7 +307,7 @@ export type IFlatMetadata = Record< string | number | boolean | undefined | null >; -interface ITreeNode { +interface ITreeNode { id?: NodeId; name: string; isBranch?: boolean; @@ -315,7 +315,7 @@ interface ITreeNode { metadata?: M; } -export const flattenTree = ( +export const flattenTree = ( tree: ITreeNode ): INode[] => { let internalCount = 0; @@ -515,8 +515,8 @@ export const getOnSelectTreeAction = ( return treeTypes.toggleSelect; }; -export const getTreeParent = (data: INode[]): INode => { - const parentNode: INode | undefined = data.find( +export const getTreeParent = (data: INode[]): INode => { + const parentNode: INode | undefined = data.find( (node) => node.parent === null ); @@ -527,7 +527,7 @@ export const getTreeParent = (data: INode[]): INode => { return parentNode; }; -export const getTreeNode = (data: INode[], id: NodeId): INode => { +export const getTreeNode = (data: INode[], id: NodeId): INode => { const treeNode = data.find((node) => node.id === id); if (treeNode == null) {