CngxDisclosure
projects/common/interactive/nav/disclosure.directive.ts
Import#
import { CngxDisclosure } from '@cngx/common/interactive'
Description#
Generic expand/collapse (disclosure) behavior.
Applied to the trigger element (button, heading, etc.). Manages
aria-expanded and aria-controls host attributes directly - no need
to compose CngxAriaExpanded separately.
Supports controlled ([cngxDisclosureOpened]) and uncontrolled modes,
following the same pattern as CngxDrawer and CngxSort.
The consumer decides how to render/hide the content. Two approaches:
DOM removal (simplest, no animation):
@if (group.opened()) { <div id="content">…</div> }Hidden attribute (enables CSS transitions):
<div id="content" [hidden]="!group.opened()">…</div>FAQ accordion
<button cngxDisclosure #faq="cngxDisclosure" [controls]="'answer-1'">
Question 1
</button>
@if (faq.opened()) {
<div id="answer-1">Answer to question 1.</div>
}Nav group with animation
<button cngxDisclosure #group="cngxDisclosure" [controls]="'nav-items'">
Settings
</button>
<div id="nav-items" [hidden]="!group.opened()" class="collapsible">
<a href="/general">General</a>
<a href="/security">Security</a>
</div>Metadata#
Host#
Index#
Inputs
Outputs
Derived State
HostBindings
HostListeners
Inputs#
boolean | undefinedControlled opened state. When bound, takes precedence over internal state.
undefined, { alias: 'cngxDisclosureOpened' }Outputs#
Methods#
HostBindings#
| Binding | Expression |
|---|---|
[attr.aria-expanded] | opened() |
[attr.aria-controls] | controls() ?? null |
HostListeners#
| Event | Handler |
|---|---|
(click) | click() |
(keydown.enter) | keydown.enter() |
(keydown.space) | keydown.space() |