Skip to main content
cngx-src documentation

CngxAriaExpanded

DirectivePrimaryv0.1.0WCAG AA

projects/common/a11y/aria/aria-expanded.directive.ts

Import#

import { CngxAriaExpanded } from '@cngx/common/a11y'

Description#

Manages aria-expanded and optionally aria-controls on the host element.

Pairs a disclosure trigger (button) with its controlled region via standard WAI-ARIA attributes. Supports accordions, dropdowns, tree items, and any disclosure pattern where a control toggles visibility of another element.

Unlike manual [attr.aria-expanded] binding, this directive couples both attributes (aria-expanded + aria-controls) in a single declaration, preventing mismatches where one is set without the other.

Simple disclosure

<button [cngxAriaExpanded]="open()" [controls]="'panel-id'" (click)="open.set(!open())">
  Toggle
</button>
<div id="panel-id" role="region" [hidden]="!open()">Panel content</div>

Accordion with multiple panels

@for (panel of panels(); track panel.id) {
  <button [cngxAriaExpanded]="panel.open" [controls]="panel.id" (click)="toggle(panel)">
    {{ panel.label }}
  </button>
  @if (panel.open) {
    <div [id]="panel.id" role="region">{{ panel.content }}</div>
  }
}

https://cngxjs.github.io/cngx/examples/#/common/a11y/aria-expanded/accordion-multiple-panels https://cngxjs.github.io/cngx/examples/#/common/a11y/aria-expanded/disclosure-pattern

Metadata#

Host#

Index#

Inputs#

controls#string | undefined
input()

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

expanded#boolean
input()

Whether the controlled element is currently expanded. Sets aria-expanded.

default false, { alias: 'cngxAriaExpanded' }

HostBindings#

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