Skip to content

Types

All types are exported from react-simple-tree-menu.

import type {
TreeMenuProps,
TreeMenuHandle,
TreeMenuItem,
TreeMenuChildren,
TreeMenuClassNames,
TreeMenuLabels,
TreeNode,
TreeNodeObject,
TreeNodeInArray,
LocaleFunction,
MatchSearchFunction,
Item,
UnflattenResult,
} from 'react-simple-tree-menu';

Argument to LocaleFunction. The open index signature is how arbitrary user-attached fields (url, icon, …) flow through.

interface LocaleFunctionProps {
label: string;
[name: string]: unknown;
}

Object-format node. The enclosing object’s property name is the key; index orders siblings inside walk(). key is forbidden here (lives on the outer object). Extends LocaleFunctionProps so custom fields pass through.

interface TreeNode extends LocaleFunctionProps {
index: number;
key?: never;
nodes?: TreeNodeObject;
}

Object data format. Keys become node keys.

interface TreeNodeObject {
[name: string]: TreeNode;
}

Array-format node. Ordered by array position, so index is forbidden. Extends LocaleFunctionProps.

interface TreeNodeInArray extends LocaleFunctionProps {
key: string;
index?: never;
nodes?: TreeNodeInArray[];
}

See Item under TreeMenu.

See the classNames slot table.

interface TreeMenuLabels {
searchPlaceholder?: string;
searchAriaLabel?: string;
}
type LocaleFunction = (props: LocaleFunctionProps) => string;

Receives the entire node (not just the label) so a transformer can branch on custom fields. Pass a stable reference — the internal walk memo keys on identity.

interface MatchSearchFunctionProps extends LocaleFunctionProps {
searchTerm: string;
}
type MatchSearchFunction = (props: MatchSearchFunctionProps) => boolean;

Same shape as the locale argument with searchTerm added. Also should be a stable reference.

Return type of unflatten:

interface UnflattenResult<T> {
roots: T[];
childrenByParent: Map<string, T[]>;
}