ComponentsIconsGuidesExamplesGetting started
ComponentsIconsGuidesExamplesGetting started
GitHub repository

Tree

Hierarchical tree view with expansion, selection, checkboxes and lazy loading.

c2-tree

Hierarchical tree view with expansion, selection and lazy loading.

It can be authored two ways, and both produce the same DOM and the same events. Nest the rows in markup:

<c2-tree expanded-items="src">
  <c2-tree-item value="src" label="src">
    <c2-tree-item value="app.ts" label="app.ts"></c2-tree-item>
  </c2-tree-item>
</c2-tree>

…or hand it data, which it renders into the same c2-tree-item elements:

tree.items = [{ value: 'src', label: 'src', children: [{ value: 'app.ts', label: 'app.ts' }] }]

The tree owns all state. value holds the selected rows, expanded-items the expanded ones, and every row's expanded, selected, indeterminate, level and roving tabindex are written from here on each sync — so drive those two arrays rather than the rows.

In the data-driven mode renderItem takes over a row's whole content, or renderIcon, renderLabel and renderActions replace one part each. They are handed to Lit, so they return a Lit template or a DOM node — not framework markup such as JSX.

children-outline draws a vertical rule per level of depth, the way a file explorer marks which branch each row belongs to. It is off by default; --c2-tree-item__guide--color and --c2-tree-item__guide--width style the rules once it is on.

Only expanded rows render their children slot, which keeps a collapsed subtree out of both layout and the accessibility tree — though the child elements are still created. Reach for virtualization rather than this component once a tree runs to many thousands of rows.

Keyboard

Arrow Up and Down walk the visible rows. Arrow Right expands a collapsed branch, then moves to its first child; Arrow Left collapses an expanded one, then moves to its parent. Home and End jump to the ends, Enter and Space select, * expands every sibling of the focused row, and typing a few letters jumps to the matching row. With selection="multiple", Shift extends a range and Ctrl or Cmd toggles a single row.

Attributes

NameTypeDefaultDescription
itemsTreeNode[][]Nodes to render. Leave empty and nest c2-tree-item elements instead to author the tree in markup.
valuestring[][]Values of the selected rows. Reflected as a ;-separated attribute.
expanded-itemsstring[][]Values of the expanded rows. Reflected as a ;-separated attribute.
selectionTreeSelectionModesingleHow many rows may be selected at once.
checkbox-selectionbooleanfalseShows a checkbox on every row. Implies selection="multiple".
selection-propagationTreeSelectionPropagationbothHow a checkbox tick travels between a row and its relatives.
children-outlinebooleanfalseDraws a vertical rule per level of depth, marking which branch each row belongs to.
disabledbooleanfalseFreezes the whole tree.
expand-on-clickbooleanfalseExpands a branch when its row is clicked — or activated with Enter or Space — not only when its toggle is.

Slots

NameDescription
(default)The root c2-tree-item rows, when authoring in markup.
emptyShown instead of the rows when the tree holds nothing.

Events

NameTypeDescription
expansion-changeCustomEvent<TreeExpansionChangeEventDetail>Fired after a row is expanded or collapsed. Does not bubble.
item-load-errorCustomEvent<TreeItemLoadErrorEventDetail>Fired when loadChildren rejects.
selection-changeCustomEvent<TreeSelectionChangeEventDetail>Fired after the user changes the selection. Does not bubble: several components fire selection-change, so a listener belongs on the element itself.
item-clickCustomEvent<TreeItemClickEventDetail>Fired when a row is clicked, selected or not.
item-expandCustomEvent<TreeItemExpandEventDetail>Fired when a row expands. Call preventDefault() to keep it closed. This is where a consumer authoring in markup appends children for a lazily loaded branch.

CSS parts

Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.

NameDescription
treeThe scrolling container holding the rows.

CSS custom properties

Grouped by semantic target and state from --c2-component__target__state--property. Click a group to collapse it; click a name to copy it.

NameTypeDefaultDescription
c2-tree
--c2-tree--backgroundcolor#ffffffBackground of the tree.
--c2-tree--padding-toppadding4pxSpace above the first row.
--c2-tree--padding-rightpadding0pxSpace right of the rows.
--c2-tree--padding-bottompadding4pxSpace below the last row.
--c2-tree--padding-leftpadding0pxSpace left of the rows.
--c2-tree--border-topborder—Top border.
--c2-tree--border-rightborder—Right border.
--c2-tree--border-bottomborder—Bottom border.
--c2-tree--border-leftborder—Left border.
--c2-tree--border-top-left-radiusborder-radius8pxTop-left corner radius.
--c2-tree--border-top-right-radiusborder-radius8pxTop-right corner radius.
--c2-tree--border-bottom-left-radiusborder-radius8pxBottom-left corner radius.
--c2-tree--border-bottom-right-radiusborder-radius8pxBottom-right corner radius.
--c2-tree--max-heightpixel—Height at which the tree starts scrolling.
--c2-tree--font-sizefont-size14pxBase font size, inherited by the rows.
--c2-tree--font-familyfont-family—Base font family, inherited by the rows.
c2-tree > disabled
--c2-tree__disabled--opacityopacity0.38Opacity of a disabled tree.
c2-tree > empty
--c2-tree__empty--colorcolor#71717aColour of the empty message.
--c2-tree__empty--paddingpadding18pxSpace around the empty message.

c2-tree-item

One row of a https://github.com/code2nguyen/web-components | c2-tree.

Nest items to build the hierarchy — a branch's children are its own c2-tree-item element children:

<c2-tree>
  <c2-tree-item value="src" label="src">
    <c2-tree-item value="app.ts" label="app.ts"></c2-tree-item>
  </c2-tree-item>
</c2-tree>

The item draws a row and nothing else: expanded, selected, indeterminate, level and the roving tabindex are all written by the parent c2-tree, which owns the tree's state. Setting them by hand works but is overwritten on the tree's next sync — drive the tree's value and expanded-items instead.

The children slot is only rendered while the row is expanded, so a collapsed subtree is not laid out and stays out of the accessibility tree. The child elements themselves still exist in the DOM.

Attributes

NameTypeDefaultDescription
valuestring—Identity of the row. Selection and expansion are tracked by this value, so it must be unique in the tree.
labelstring—Text of the row. Ignored when the label slot is filled; falls back to value when empty.
disabledbooleanfalseBlocks selection and expansion, and takes the row out of checkbox propagation.
has-childrenbooleanfalseMarks a branch whose children load on demand: the toggle shows before any child exists.
hrefstring—Turns the row into a link. The whole row becomes the click target; the toggle still only expands.
targetstring | undefined—Browsing context for href, e.g. _blank. A _blank row gets rel="noopener noreferrer".
expandedbooleanfalseWhether the children are shown. Written by the parent c2-tree.
selectedbooleanfalseWhether the row is selected. Written by the parent c2-tree.
indeterminatebooleanfalseWhether only part of the subtree is selected. Derived and written by the parent c2-tree.
loadingbooleanfalseWhether the children are being fetched. Written by the parent c2-tree.
children-outlinebooleanfalseWhether to draw the indent guides. Written by the parent c2-tree, and reflected because the rules are drawn in CSS and the stylesheet has to see it.

Slots

NameDescription
(default)The nested c2-tree-item children of this row.
labelRich label content, replacing the label attribute.
iconIcon shown between the disclosure toggle and the label.
actionsTrailing content, revealed on hover and focus by default.
toggle-iconReplaces the default chevron. It is rotated by the component, so supply the collapsed orientation.

CSS parts

Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.

NameDescription
rowThe clickable row, excluding any nested children.
toggleThe disclosure toggle.
labelText box containing the label slot or label-property fallback.
actionsTrailing box wrapping the assigned actions slot.
groupThe container holding the nested children.
checkboxThe selection checkbox rendered when checkbox selection is enabled.

CSS custom properties

Grouped by semantic target and state from --c2-component__target__state--property. Click a group to collapse it; click a name to copy it.

NameTypeDefaultDescription
c2-tree-item
--c2-tree-item--colorcolor#18181bLabel colour.
--c2-tree-item--backgroundcolortransparentRow background at rest.
--c2-tree-item--font-sizefont-size14pxLabel size.
--c2-tree-item--font-weightfont-weight—Label weight.
--c2-tree-item--font-familyfont-family—Label family.
--c2-tree-item--line-heightpixel20pxLabel line height.
c2-tree-item > row
--c2-tree-item__row--min-heightpixel28pxHeight of a row.
--c2-tree-item__row--indentpixel16pxExtra inset added per level of depth.
--c2-tree-item__row--padding-toppadding0pxSpace above the row's content. row--min-height is a floor, so this only grows the row once content plus padding passes it.
--c2-tree-item__row--padding-bottompadding0pxSpace below the row's content. See row--padding-top for how it interacts with row--min-height.
--c2-tree-item__row--padding-inline-startpadding8pxInset of a root-level row.
--c2-tree-item__row--padding-inline-endpadding8pxSpace after the trailing actions.
--c2-tree-item__row--gappixel6pxSpace between toggle, checkbox, icon, label and actions.
--c2-tree-item__row--border-radiusborder-radius4pxCorner radius of the row highlight. Set 0 for edge-to-edge bands.
c2-tree-item > hover
--c2-tree-item__hover--colorcolor—Label colour while hovered. Defaults to the resting colour.
--c2-tree-item__hover--backgroundcolor#f4f4f5Row background while hovered.
c2-tree-item > selected
--c2-tree-item__selected--colorcolorrgb(2, 101, 220)Label colour while selected.
--c2-tree-item__selected--backgroundcolor#edf1feRow background while selected.
c2-tree-item > selected > hover
--c2-tree-item__selected__hover--backgroundcolor#e2e9fdRow background while selected and hovered.
c2-tree-item > focus
--c2-tree-item__focus--outlineoutline2px solid rgba(2, 101, 220, 0.4)Focus ring.
--c2-tree-item__focus--outline-offsetpixel-2pxFocus ring inset.
c2-tree-item > disabled
--c2-tree-item__disabled--opacityopacity0.38Opacity of a disabled row.
c2-tree-item > toggle
--c2-tree-item__toggle--sizepixel16pxSize of the disclosure toggle.
--c2-tree-item__toggle--colorcolor#71717aColour of the disclosure toggle.
--c2-tree-item__toggle--rotateangle90degToggle rotation while expanded.
--c2-tree-item__toggle--rotate-collapsedangle0degToggle rotation while collapsed.
--c2-tree-item__toggle--transition-durationtime150msLength of the toggle rotation.
c2-tree-item > icon
--c2-tree-item__icon--sizepixel16pxSize of slotted icons.
--c2-tree-item__icon--colorcolor—Colour of slotted icons.
c2-tree-item > guide
--c2-tree-item__guide--colorcolor#e4e4e7Colour of the indent guides.
--c2-tree-item__guide--widthpixel1pxThickness of the indent guides.
c2-tree-item > actions
--c2-tree-item__actions--gappixel2pxSpace between trailing actions.
--c2-tree-item__actions--opacityopacity0Opacity of the trailing actions at rest. Set 1 to always show them.
c2-tree-item > actions > hover
--c2-tree-item__actions__hover--opacityopacity1Opacity of the trailing actions while the row is hovered or focused.
c2-tree-item > checkbox
--c2-tree-item__checkbox--margin-inline-endpixel2pxSpace after the selection checkbox.
escAccordionConnected, animated panels with shared borders and single or multiple expansion.LayoutArea chartA line chart with the region under each line filled — every line-chart attribute, plus a fill opacity.ChartAttachmentFile and image attachments with metadata, upload progress, failure states, and actions.Data displayAutocompleteSearchable combobox for local or remote items with customizable list rows.InputsAvatarImage, initials or icon for a person, with status dot and badge.Data displayBadgeTinted pill for status text, counts and dots, optionally pinned to a corner of another element.Data displayBar chartBars over categories or time buckets, with several series drawn side by side within each band.ChartBorder BeamA decorative beam that travels around the border of any positioned container.LayoutBreadcrumbNavigation trail of link buttons with separators, a current page and optional collapsing.NavigationButtonThemeable button with slots for text, prefix, suffix and running icons.ButtonsButton GroupJoined actions and polished segmented controls with single or multiple selection.ButtonsCandlestick chartAn ECharts OHLC chart for market sessions and other open-close ranges, with semantic positive and negative colours.ChartCardGroups related content and actions on a single bordered surface.LayoutCascaderSelect a value from related, multi-level data in one floating panel.InputsChat InputAuto-growing message composer with keyboard submission, toolbar actions and native form support.ChatChat MessageFlexible message row for conversations, assistant answers and activity updates.ChatCheckboxNative checkbox behaviour in a quiet, themeable box with an opt-in hover layer.InputsCode EditorEditable, syntax-highlighted source field on CodeMirror 6, themed entirely through CSS variables.InputsCode ViewerSyntax-highlighted code with line numbers, copy button and dark mode, powered by shiki.Data displayColor AreaTwo-dimensional area for picking saturation and value of a colour.InputsColor SelectColour swatch that opens a full picker built from area and slider.InputsColor SliderHorizontal slider for choosing a hue from 0 to 360.InputsCopy ButtonButton that copies text to the clipboard — the element it sits in, another element by id, or a literal string.ButtonsDashboardGrid of resizable panes, dragged by the edges they share.LayoutDate InputForm-associated single-date input with native picker, constraints, helper text and error states.InputsDate SelectorAccessible one- or two-month calendar for choosing a date range.InputsDetailsCollapsible disclosure built on native details and summary.LayoutGauge chartA focused radial KPI gauge drawn by ECharts, with a configurable scale, progress arc and pointer.ChartHeaderArranges brand, navigation, actions and a mobile trigger in a reusable site shell.LayoutIcon ButtonRound, hoverable button wrapping a slotted SVG icon.ButtonsKbdKeyboard key label for shortcuts and command hints, with the semantics of the native kbd element.Data displayLabelCaption that names and activates the control referenced by its for attribute, with a required marker.InputsLine chartA line chart over a time or numeric x axis, drawn on canvas by uPlot, with series declared as children.ChartLink ButtonText-styled control for link and navigation actions, rendered as a real anchor or a button.NavigationListVertical list container with single or multiple selection.Data displayList ItemSelectable row with icon slots, used on its own or as the option of list and select.Data displayMenuCommands, links, checkboxes and submenus in a popover anchored to a trigger.NavigationModalDialog built on the native dialog element: focus trap, backdrop, Escape, title, body and footer.FeedbackNavigation MenuSite navigation bar whose triggers open panels of links below the header.NavigationNumber InputForm-associated numeric input with native validation, step controls, adornments and helper states.InputsOverlayAnchored popup built on the browser Popover API, positioned with floating-ui.FeedbackPaginationPage navigation in three layouts: numbered pages, a simple page status, or a table-footer row with rows-per-page.NavigationPie chartA pie or donut chart drawn by ECharts, where one row is one slice and label-field names it.ChartProgressLinear progress bar, indeterminate or filling to a value, with an optional label and count.FeedbackQR CodeGenerate accessible, themeable QR codes locally as crisp SVG graphics.Data displayQuestionnaireA multi-step single- and multiple-choice flow with validation, shortcuts and form submission.InputsRadar chartCompare several profiles across the same set of normalized indicators.ChartRadioRadio options built on native inputs, grouped into one value with keyboard navigation.InputsRateAccessible star rating input with hover preview, keyboard control and optional half values.InputsReorder ListReorder a vertical queue with pointer or keyboard input while the application owns persistence.Data displayScatter chartAn ECharts scatter plot for finding relationships, clusters and outliers across two numeric measures.ChartSelectDropdown that pairs a themeable trigger with an anchored list of c2-list-item options.InputsSeperatorHorizontal or vertical rule with an optional label, for dividing content and toolbars.LayoutSheetDialog pinned to an edge of the screen, for content that complements the page rather than interrupting it.FeedbackSide NavResponsive navigation drawer beside the page: pushes the content on large screens, slides over it with a backdrop on small ones.NavigationSkeletonPlaceholder block standing in for content that has not arrived, in three shapes and three animations.FeedbackSliderRange input with a themeable track, thumb, step ticks and value bubble.InputsSparklineA chromeless trend line sized for a table cell, a list row or the trend slot of a c2-stat.ChartSpinnerCircular progress indicator, indeterminate or showing a value, with optional text.FeedbackStatDisplays a KPI with an optional icon, trend and supporting description.Data displayStatus PanelCommunicate empty states, operation outcomes and recoverable errors with clear next steps.FeedbackStepsA vertical trace of a task as it runs: statuses, durations, and stages that open while they work and close when they are done.Data displaySwitchOn/off toggle on a native switch input, with label, description and thumb icons.InputsTableVirtualized data grid with declarative columns, sorting, selection, pinning and resizing.Data displayTabsTab strip that shows one content panel at a time.NavigationText FieldSingle-line input with icon slots, clear button, helper and error text, and a character counter.InputsTextareaMultiline text input with resizing, helper and error text, and a character counter.InputsTheme SelectColour-theme switcher: click to step to the next mode, hover for the full menu.InputsToastNotification cards and a manager for stacked, queued notifications with independent lifetimes.FeedbackTooltipContextual hint shown when its target is hovered or focused, rendered in the top layer.FeedbackTreeHierarchical tree view with expansion, selection, checkboxes and lazy loading.Data displayUploadDrag-and-drop file selection with validation, upload progress, retry, cancellation, and attachment results.InputsVirtual ListWindowed list with built-in search, sorting, selection and an async data source.Data displayFeather Icons287 open-source Feather icons, one web component each.IconsMat Icon2,234 Material Icons ligatures rendered through a single element.IconsPhosphor Icons1,512 flexible icons in six weights, one web component each.IconsThemingTheme every c2n component from a handful of design tokens with @c2n/theme, or reach for any component variable directly.GuideFrameworksUse the components from React, Vue, Angular, Svelte, Lit or plain HTML — typed events, generated template types, and the one piece of configuration each framework needs.GuideUsing c2n in an applicationThe workflow behind every c2n app: load the theme once, use c2-* tags directly, and turn every repeated pattern into a small variant or composed component.GuideAI toolsGive Claude Code, Codex or Google Antigravity the c2n skill, live component APIs, examples and application conventions.Guide