Skip to content
Star

PxTree

A recursive tree component for browsing hierarchical catalogs (e.g. document template folders). Supports expand/collapse, node selection, and inline add/edit-child flows via the newChild* props.

Usage

Demo
Engineering
Frontend Engineering
Backend Engineering
Design

Props

PropTypeDefaultDescription
nodesrequiredTreeNode[]Array of root tree nodes. Each node can have a children array for nested nodes.
expandedKeysrequiredRecord<string, boolean>Map of node key to expanded state. Use with v-model:expanded-keys.
selectedKeystring | nullnullCurrently selected node key.
selectablebooleantrueHighlights the selected node.
disabledbooleanfalseDisables inline add/edit interactions.
levelnumber1Nesting depth, used internally for indentation on recursive calls.
newChildNamestring | nullnullv-model for the name input shown while adding a child node.
newChildTypeboolean | string | nullnullv-model for the type selector shown while adding a child node.
newChildTypeOptionsRecord<string, unknown>[] | nullnullOptions for the new-child type selector.
catalogItemIdstring | nullnullv-model for the catalog item selector, shown when newChildType is template or form.
catalogOptionsRecord<string, unknown>[] | nullnullOptions for the catalog item selector.
newChildRequieredbooleanfalseWhether the new child name is required.

TreeNode Interface

ts
interface TreeNode {
  key: string
  label: string
  children?: TreeNode[]
  has_children?: boolean
  type?: string          // 'folder' | 'template' | 'placeholder' | 'form' | ...
  isEditing?: boolean     // renders the inline add/edit row instead of the label
  isAddButton?: boolean   // renders an "add child" button instead of the label
  [key: string]: unknown
}

Emits

EventPayloadDescription
node-clickTreeNodeEmitted when a non-editing node is clicked.
update:expandedKeysRecord<string, boolean>Emitted when a node is expanded or collapsed.
start-add-childTreeNodeEmitted when the add-child button is clicked.
confirm-add-childTreeNodeEmitted to confirm adding a new child node.
cancel-add-childEmitted to cancel adding a new child node.
confirm-edit-nodeTreeNodeEmitted to confirm editing an existing node.
cancel-edit-nodeEmitted to cancel editing an existing node.

Slots

SlotScopeDescription
actions{ node: TreeNode }Action buttons rendered on the right side of each non-editing node.

Built with VitePress