Skip to content

Commit ff5e7bb

Browse files
committed
refactor(aria/accordion): Add accessors for pattern properties
1 parent 25f15bf commit ff5e7bb

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/aria/accordion/accordion.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
'role': 'region',
4747
'[attr.id]': '_pattern.id()',
4848
'[attr.aria-labelledby]': '_pattern.accordionTrigger()?.id()',
49-
'[attr.inert]': '_pattern.hidden() ? true : null',
49+
'[attr.inert]': 'hidden() ? true : null',
5050
},
5151
})
5252
export class AccordionPanel {
@@ -59,6 +59,9 @@ export class AccordionPanel {
5959
/** A local unique identifier for the panel, used to match with its trigger's value. */
6060
value = input.required<string>();
6161

62+
/** Whether the accordion panel is hidden. True if the associated trigger is not expanded. */
63+
readonly hidden = computed(() => this._pattern.hidden());
64+
6265
/** The parent accordion trigger pattern that controls this panel. This is set by AccordionGroup. */
6366
readonly accordionTrigger: WritableSignal<AccordionTriggerPattern | undefined> =
6467
signal(undefined);
@@ -73,7 +76,7 @@ export class AccordionPanel {
7376
constructor() {
7477
// Connect the panel's hidden state to the DeferredContentAware's visibility.
7578
afterRenderEffect(() => {
76-
this._deferredContentAware.contentVisible.set(!this._pattern.hidden());
79+
this._deferredContentAware.contentVisible.set(!this.hidden());
7780
});
7881
}
7982
}
@@ -87,10 +90,10 @@ export class AccordionPanel {
8790
exportAs: 'ngAccordionTrigger',
8891
host: {
8992
'class': 'ng-accordion-trigger',
90-
'[attr.data-active]': '_pattern.active()',
93+
'[attr.data-active]': 'active()',
9194
'role': 'button',
9295
'[id]': '_pattern.id()',
93-
'[attr.aria-expanded]': '_pattern.expanded()',
96+
'[attr.aria-expanded]': 'expanded()',
9497
'[attr.aria-controls]': '_pattern.controls()',
9598
'[attr.aria-disabled]': '_pattern.disabled()',
9699
'[attr.disabled]': 'hardDisabled() ? true : null',
@@ -116,6 +119,15 @@ export class AccordionTrigger {
116119
/** Whether the trigger is disabled. */
117120
disabled = input(false, {transform: booleanAttribute});
118121

122+
/** Whether the trigger is active. */
123+
readonly active = computed(() => this._pattern.active());
124+
125+
/** Whether the trigger is expanded. */
126+
readonly expanded = computed(() => this._pattern.expanded());
127+
128+
/** The index of the trigger within its accordion group. */
129+
readonly index = computed(() => this._pattern.index());
130+
119131
/**
120132
* Whether this trigger is completely inaccessible.
121133
*

0 commit comments

Comments
 (0)