Skip to main content
cngx-src documentation

CngxExpandable

DirectivePrimaryv0.1.0WCAG AA

projects/common/interactive/expandable/expandable.directive.ts

Import#

import { CngxExpandable } from '@cngx/common/interactive'

Description#

Passive expand/collapse contract for elements whose open state is driven from the outside - typically a CngxTreeController or any component that manages a shared expansion set. Mirrors aria-expanded and (optionally) aria-controls into the host; carries no interaction of its own.

Use CngxDisclosure instead for self-triggering expanders (FAQ, accordion headings). The distinction is deliberate: a tree-item row is a selection target, not a toggle - clicks, Enter, and Space belong to the selection flow, while expand/collapse is wired to ArrowLeft/Right via a sibling nav directive or to a dedicated twisty button.

<div role="tree" aria-label="Files">
  <div
    role="treeitem"
    aria-level="1"
    cngxExpandable
    [cngxExpandableOpen]="ctrl.isExpanded(id)()"
    [controls]="childrenId"
  >
    <button
      type="button"
      tabindex="-1"
      (click)="ctrl.toggle(id)"
    >▸</button>
    <span>{{ label }}</span>
  </div>
  <div [id]="childrenId" [hidden]="!ctrl.isExpanded(id)()">…</div>
</div>

Metadata#

Host#

Index#

Inputs#

controls#string | undefined
input()

id of the controlled content element, bound to aria-controls.

expandedInput#boolean | undefined
input()

Controlled expanded state. When bound, wins over internal state.

default undefined, { alias: 'cngxExpandableOpen', }

Outputs#

expandedChange#boolean
output()

Emitted when the expanded state changes.

Methods#

collapse#void
expand#void
toggle#void

HostBindings#

BindingExpression
[attr.aria-expanded]expanded()
[attr.aria-controls]controls() ?? null