MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / createItemProps

Function createItemProps

app/hooks/useVirtualTree.ts:696–721  ·  view source on GitHub ↗
(
  item: TreeNodeItem<T>,
  virtualItem: VirtualItem,
  state: TreeState<T>,
  dispatch: Dispatch<TreeAction>
)

Source from the content-addressed store, hash-verified

694}
695
696function createItemProps<T extends { id: string; children?: T[] }>(
697 item: TreeNodeItem<T>,
698 virtualItem: VirtualItem,
699 state: TreeState<T>,
700 dispatch: Dispatch<TreeAction>
701): () => React.HTMLAttributes<HTMLElement> {
702 const { depth, pos, size, node, isCollapsed } = item;
703
704 return () => ({
705 "aria-expanded": node.children && node.children.length > 0 && !isCollapsed,
706 "aria-level": depth + 1,
707 "aria-posinset": pos,
708 "aria-setsize": size,
709 role: "treeitem",
710 tabIndex: node.id === state.focusedNodeId ? -1 : undefined,
711 onClick: (e) => {
712 if (e.defaultPrevented) {
713 return; // Do nothing if the event was already processed
714 }
715
716 if (node.id !== state.focusedNodeId) {
717 dispatch({ type: "FOCUS_NODE", id: node.id });
718 }
719 },
720 });
721}
722
723// Finds the node in the list of nodes or recursively in the children
724function findNodeInTreeById<T extends { id: string; children?: T[] }>(

Callers 1

useVirtualTreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected