Skip to main content
cngx-src documentation

CngxDisclosure

DirectivePrimaryv0.1.0WCAG AA

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>
}
<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>

https://cngxjs.github.io/cngx/examples/#/common/interactive/disclosure/basic-uncontrolled https://cngxjs.github.io/cngx/examples/#/common/interactive/disclosure/controlled-mode https://cngxjs.github.io/cngx/examples/#/common/interactive/disclosure/faq-accordion

Metadata#

Host#

Index#

Inputs#

controls#string | undefined
input()

The id of the controlled content element. Sets aria-controls.

openedInput#boolean | undefined
input()

Controlled opened state. When bound, takes precedence over internal state.

default undefined, { alias: 'cngxDisclosureOpened' }

Outputs#

openedChange#boolean
output()

Emitted when the opened state changes.

Methods#

close#void

Closes the disclosure.

open#void

Opens the disclosure.

toggle#void

Toggles the disclosure between open and closed.

HostBindings#

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

HostListeners#

EventHandler
(click)click()
(keydown.enter)keydown.enter()
(keydown.space)keydown.space()