Skip to content

Commit ba9fb35

Browse files
authored
docs: update jsdocs for public aria API (angular#32316)
* docs: update jsdocs for public aria API * refactor: fix lint
1 parent 03b0def commit ba9fb35

File tree

8 files changed

+513
-106
lines changed

8 files changed

+513
-106
lines changed

src/aria/accordion/accordion.ts

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,22 @@ import {
3030
} from '@angular/aria/private';
3131

3232
/**
33-
* Represents the content panel of an accordion item. It is controlled by an
34-
* associated `AccordionTrigger`.
33+
* The content panel of an accordion item that is conditionally visible.
34+
*
35+
* This directive is a container for the content that is shown or hidden. It requires
36+
* a `panelId` that must match the `panelId` of its corresponding `ngAccordionTrigger`.
37+
* The content within the panel should be provided using an `ng-template` with the
38+
* `ngAccordionContent` directive so that the content is not rendered on the page until the trigger
39+
* is expanded. It applies `role="region"` for accessibility and uses the `inert` attribute to hide
40+
* its content from assistive technologies when not visible.
41+
*
42+
* ```html
43+
* <div ngAccordionPanel panelId="unique-id-1">
44+
* <ng-template ngAccordionContent>
45+
* <p>This content is lazily rendered and will be shown when the panel is expanded.</p>
46+
* </ng-template>
47+
* </div>
48+
* ```
3549
*
3650
* @developerPreview 21.0
3751
*/
@@ -100,8 +114,19 @@ export class AccordionPanel {
100114
}
101115

102116
/**
103-
* Represents the trigger button for an accordion item. It controls the expansion
104-
* state of an associated `AccordionPanel`.
117+
* The trigger that toggles the visibility of its associated `ngAccordionPanel`.
118+
*
119+
* This directive requires a `panelId` that must match the `panelId` of the `ngAccordionPanel` it
120+
* controls. When clicked, it will expand or collapse the panel. It also handles keyboard
121+
* interactions for navigation within the `ngAccordionGroup`. It applies `role="button"` and manages
122+
* `aria-expanded`, `aria-controls`, and `aria-disabled` attributes for accessibility.
123+
* The `disabled` input can be used to disable the trigger.
124+
*
125+
* ```html
126+
* <button ngAccordionTrigger panelId="unique-id-1">
127+
* Accordion Trigger Text
128+
* </button>
129+
* ```
105130
*
106131
* @developerPreview 21.0
107132
*/
@@ -145,11 +170,8 @@ export class AccordionTrigger {
145170
/** Whether the trigger is expanded. */
146171
readonly expanded = computed(() => this._pattern.expanded());
147172

148-
/**
149-
* Whether this trigger is completely inaccessible.
150-
*
151-
* TODO(ok7sai): Consider move this to UI patterns.
152-
*/
173+
// TODO(ok7sai): Consider moving this to UI patterns.
174+
/** Whether this trigger is inaccessible via keyboard navigation. */
153175
readonly hardDisabled = computed(() => this._pattern.disabled() && this._pattern.tabIndex() < 0);
154176

155177
/** The accordion panel pattern controlled by this trigger. This is set by AccordionGroup. */
@@ -182,9 +204,38 @@ export class AccordionTrigger {
182204
}
183205

184206
/**
185-
* Container for a group of accordion items. It manages the overall state and
207+
* A container for a group of accordion items. It manages the overall state and
186208
* interactions of the accordion, such as keyboard navigation and expansion mode.
187209
*
210+
* The `ngAccordionGroup` serves as the root of a group of accordion triggers and panels,
211+
* coordinating the behavior of the `ngAccordionTrigger` and `ngAccordionPanel` elements within it.
212+
* It supports both single and multiple expansion modes.
213+
*
214+
* ```html
215+
* <div ngAccordionGroup [multiExpandable]="true" [(expandedPanels)]="expandedItems">
216+
* <div class="accordion-item">
217+
* <h3>
218+
* <button ngAccordionTrigger panelId="item-1">Item 1</button>
219+
* </h3>
220+
* <div ngAccordionPanel panelId="item-1">
221+
* <ng-template ngAccordionContent>
222+
* <p>Content for Item 1.</p>
223+
* </ng-template>
224+
* </div>
225+
* </div>
226+
* <div class="accordion-item">
227+
* <h3>
228+
* <button ngAccordionTrigger panelId="item-2">Item 2</button>
229+
* </h3>
230+
* <div ngAccordionPanel panelId="item-2">
231+
* <ng-template ngAccordionContent>
232+
* <p>Content for Item 2.</p>
233+
* </ng-template>
234+
* </div>
235+
* </div>
236+
* </div>
237+
* ```
238+
*
188239
* @developerPreview 21.0
189240
*/
190241
@Directive({
@@ -213,10 +264,13 @@ export class AccordionGroup {
213264
/** Whether multiple accordion items can be expanded simultaneously. */
214265
multiExpandable = input(true, {transform: booleanAttribute});
215266

216-
/** The ids of the current expanded accordion panels. */
267+
/** The ids of the currently expanded accordion panels. */
217268
expandedPanels = model<string[]>([]);
218269

219-
/** Whether to allow disabled items to receive focus. */
270+
/**
271+
* Whether to allow disabled items to receive focus. When `true`, disabled items are
272+
* focusable but not interactive. When `false`, disabled items are skipped during navigation.
273+
*/
220274
softDisabled = input(true, {transform: booleanAttribute});
221275

222276
/** Whether keyboard navigation should wrap around from the last item to the first, and vice-versa. */
@@ -263,8 +317,20 @@ export class AccordionGroup {
263317
}
264318

265319
/**
266-
* A structural directive that marks the `ng-template` to be used as the content
267-
* for a `AccordionPanel`. This content can be lazily loaded.
320+
* A structural directive that provides a mechanism for lazily rendering the content for an
321+
* `ngAccordionPanel`.
322+
*
323+
* This directive should be applied to an `ng-template` inside an `ngAccordionPanel`.
324+
* It allows the content of the panel to be lazily rendered, improving performance
325+
* by only creating the content when the panel is first expanded.
326+
*
327+
* ```html
328+
* <div ngAccordionPanel panelId="unique-id-1">
329+
* <ng-template ngAccordionContent>
330+
* <p>This is the content that will be displayed inside the panel.</p>
331+
* </ng-template>
332+
* </div>
333+
* ```
268334
*
269335
* @developerPreview 21.0
270336
*/

src/aria/combobox/combobox.ts

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@ import {Directionality} from '@angular/cdk/bidi';
3232
import {toSignal} from '@angular/core/rxjs-interop';
3333

3434
/**
35+
* The container element that wraps a combobox input and popup, and orchestrates its behavior.
36+
*
37+
* The `ngCombobox` directive is the main entry point for creating a combobox and customizing its
38+
* behavior. It coordinates the interactions between the `ngComboboxInput` and the popup, which
39+
* is defined by a `ng-template` with the `ngComboboxPopupContainer` directive. If using the
40+
* `CdkOverlay`, the `cdkConnectedOverlay` directive takes the place of `ngComboboxPopupContainer`.
41+
*
42+
* ```html
43+
* <div ngCombobox filterMode="highlight">
44+
* <input
45+
* ngComboboxInput
46+
* placeholder="Search for a state..."
47+
* [(value)]="searchString"
48+
* />
49+
*
50+
* <ng-template ngComboboxPopupContainer>
51+
* <div ngListbox [(value)]="selectedValue">
52+
* @for (option of filteredOptions(); track option) {
53+
* <div ngOption [value]="option" [label]="option">
54+
* <span>{{option}}</span>
55+
* </div>
56+
* }
57+
* </div>
58+
* </ng-template>
59+
* </div>
60+
* ```
61+
*
3562
* @developerPreview 21.0
3663
*/
3764
@Directive({
@@ -70,7 +97,12 @@ export class Combobox<V> {
7097
/** The combobox popup. */
7198
readonly popup = contentChild<ComboboxPopup<V>>(ComboboxPopup);
7299

73-
/** The filter mode for the combobox. */
100+
/**
101+
* The filter mode for the combobox.
102+
* - `manual`: The consumer is responsible for filtering the options.
103+
* - `auto-select`: The combobox automatically selects the first matching option.
104+
* - `highlight`: The combobox highlights matching text in the options without changing selection.
105+
*/
74106
filterMode = input<'manual' | 'auto-select' | 'highlight'>('manual');
75107

76108
/** Whether the combobox is disabled. */
@@ -88,7 +120,7 @@ export class Combobox<V> {
88120
// TODO: Maybe make expanded a signal that can be passed in?
89121
// Or an "always expanded" option?
90122

91-
/** Whether the combobox popup is always expanded. */
123+
/** Whether the combobox popup should always be expanded, regardless of user interaction. */
92124
readonly alwaysExpanded = input(false);
93125

94126
/** Input element connected to the combobox, if any. */
@@ -145,6 +177,21 @@ export class Combobox<V> {
145177
}
146178

147179
/**
180+
* An input that is part of a combobox. It is responsible for displaying the
181+
* current value and handling user input for filtering and selection.
182+
*
183+
* This directive should be applied to an `<input>` element within an `ngCombobox`
184+
* container. It automatically handles keyboard interactions, such as opening the
185+
* popup and navigating through the options.
186+
*
187+
* ```html
188+
* <input
189+
* ngComboboxInput
190+
* placeholder="Search..."
191+
* [(value)]="searchString"
192+
* />
193+
* ```
194+
*
148195
* @developerPreview 21.0
149196
*/
150197
@Directive({
@@ -193,6 +240,33 @@ export class ComboboxInput {
193240
}
194241

195242
/**
243+
* A structural directive that marks the `ng-template` to be used as the popup
244+
* for a combobox. This content is conditionally rendered.
245+
*
246+
* The content of the popup can be a `ngListbox`, `ngTree`, or `role="dialog"`, allowing for
247+
* flexible and complex combobox implementations. The consumer is responsible for
248+
* implementing the filtering logic based on the `ngComboboxInput`'s value.
249+
*
250+
* ```html
251+
* <ng-template ngComboboxPopupContainer>
252+
* <div ngListbox [(value)]="selectedValue">
253+
* <!-- ... options ... -->
254+
* </div>
255+
* </ng-template>
256+
* ```
257+
*
258+
* When using CdkOverlay, this directive can be replaced by `cdkConnectedOverlay`.
259+
*
260+
* ```html
261+
* <ng-template
262+
* [cdkConnectedOverlay]="{origin: inputElement, usePopover: 'inline' matchWidth: true}"
263+
* [cdkConnectedOverlayOpen]="combobox.expanded()">
264+
* <div ngListbox [(value)]="selectedValue">
265+
* <!-- ... options ... -->
266+
* </div>
267+
* </ng-template>
268+
* ```
269+
*
196270
* @developerPreview 21.0
197271
*/
198272
@Directive({
@@ -203,6 +277,13 @@ export class ComboboxInput {
203277
export class ComboboxPopupContainer {}
204278

205279
/**
280+
* Identifies an element as a popup for an `ngCombobox`.
281+
*
282+
* This directive acts as a bridge, allowing the `ngCombobox` to discover and interact
283+
* with the underlying control (e.g., `ngListbox`, `ngTree`, or `ngComboboxDialog`) that
284+
* manages the options. It's primarily used as a host directive and is responsible for
285+
* exposing the popup's control pattern to the parent combobox.
286+
*
206287
* @developerPreview 21.0
207288
*/
208289
@Directive({
@@ -213,7 +294,7 @@ export class ComboboxPopup<V> {
213294
/** The combobox that the popup belongs to. */
214295
readonly combobox = inject<Combobox<V>>(Combobox, {optional: true});
215296

216-
/** The controls the popup exposes to the combobox. */
297+
/** The popup controls exposed to the combobox. */
217298
readonly controls = signal<
218299
| ComboboxListboxControls<any, V>
219300
| ComboboxTreeControls<any, V>
@@ -223,6 +304,18 @@ export class ComboboxPopup<V> {
223304
}
224305

225306
/**
307+
* Integrates a native `<dialog>` element with the combobox, allowing for
308+
* a modal or non-modal popup experience. It handles the opening and closing of the dialog
309+
* based on the combobox's expanded state.
310+
*
311+
* ```html
312+
* <ng-template ngComboboxPopupContainer>
313+
* <dialog ngComboboxDialog class="example-dialog">
314+
* <!-- ... dialog content ... -->
315+
* </dialog>
316+
* </ng-template>
317+
* ```
318+
*
226319
* @developerPreview 21.0
227320
*/
228321
@Directive({

0 commit comments

Comments
 (0)