Data JS behaviour

Tree view

A collapsible tree on the ARIA treeview pattern: one tab stop, arrows walking the visible rows (→/← expand and collapse, swapped in RTL), Enter selects and Space folds; parent rows carry their child count in your locale’s digits, and the selection leaves through wire:model or the nx-select event.

Real scenarios

The component as it is used in a product — not a specimen grid.

The repo, as the docs sidebar sees it

The whole tree is one tab stop: the arrows walk the visible rows, →/← expand and collapse (swapped in RTL), Home/End run to the ends, Enter picks and Space folds. The open file rides wire:model.live back to the server, and the fold — chevron, colour and group — is a single state change.

  • packages3 children
    • livewire2 children
      • tree-view.blade.php
      • alpine/blocks/tree-view.ts

The open file on the server (wire:model.live): —

Routing a ticket through the help center

This one is unwired: the nodes you hand in are the truth, they are never edited in place, and every pick bubbles as nx-select — here it only raises a toast. Folds stay client-side and speak through nx-expand ({ id, open }); parent rows carry their child count in your locale’s digits.

  • Getting started2 children
    • Install on your own server
    • Connect a WhatsApp number

The support team chart — folds only

With selectable="false" the rows only fold: aria-selected never lands and Enter does nothing, while the keyboard stays fully alive — the arrows still walk, Space folds a parent and the twist is the pointer affordance. Every fold reports back as nx-expand, which this scene toasts.

  • Nabu support2 children
    • Morning shiftIstanbul2 children
      • Emma Carterفارسی · English
      • عمر حدادالعربية · English

Important props

Important props
Prop Type Default What it does
nodes array [] Each node: ['id' => …, 'label' => …, 'meta' => …, 'icon' => …, 'tone' => accent|success|warning|danger|info|gold, 'children' => […]] — recursive; the nodes you pass are the truth and are never edited in place.
defaultExpanded array [] The parents that start open; folding is always client-side and every change bubbles as nx-expand ({ id, open }) from the component.
selected / wire:model string null The selected node’s id at the start; wire:model (through x-modelable on the root) binds that id, and every pick also dispatches nx-select.
selectable bool true With false the rows only fold: aria-selected never lands and Enter does nothing — an org chart, say.
label / locale string null The tree’s accessible name (“Tree view” from the core i18n by default) and the locale for the child-count digits and built-in words — fa/en/ar.

Snippet

<x-nx::tree-view label="فایل‌های پروژه" :default-expanded="['packages', 'livewire']"
    :selected="$state['file'] ?? 'tree-view.blade.php'" wire:model.live="state.file" :nodes="[
        ['id' => 'packages', 'label' => 'packages', 'icon' => 'folder', 'children' => [
            ['id' => 'livewire', 'label' => 'livewire', 'children' => [
                ['id' => 'tree-view.blade.php', 'label' => 'tree-view.blade.php', 'icon' => 'file', 'tone' => 'accent'],
            ]],
        ]],
        ['id' => 'docs', 'label' => 'docs', 'icon' => 'folder', 'meta' => '۲ رهنما'],
    ]" x-on:nx-expand="$wire.ping($event.detail.id)" />

{{-- بدون سیم‌کشی: انتخاب‌ها فقط رویداد می‌دهند --}}
<x-nx::tree-view label="دسته‌بندی راهنما" :default-expanded="['start']" :nodes="$categories"
    x-on:nx-select="$wire.ping($event.detail)" />

{{-- چارت سازمانی: فقط تا شدن، بدون انتخاب --}}
<x-nx::tree-view :selectable="false" :nodes="$org" x-on:nx-expand="track($event.detail.id)" />