Skip to content

Commit 610442f

Browse files
committed
refactor(aria/accordion): Add accessors for pattern properties
1 parent dabbfeb commit 610442f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/aria/accordion/accordion.ts

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

63+
/** Whether the accordion panel is visible. True if the associated trigger is expanded. */
64+
readonly visible = computed(() => !this._pattern.hidden());
65+
6366
/** The parent accordion trigger pattern that controls this panel. This is set by AccordionGroup. */
6467
readonly accordionTrigger: WritableSignal<AccordionTriggerPattern | undefined> =
6568
signal(undefined);
@@ -74,7 +77,7 @@ export class AccordionPanel {
7477
constructor() {
7578
// Connect the panel's hidden state to the DeferredContentAware's visibility.
7679
afterRenderEffect(() => {
77-
this._deferredContentAware.contentVisible.set(!this._pattern.hidden());
80+
this._deferredContentAware.contentVisible.set(this.visible());
7881
});
7982
}
8083
}
@@ -88,10 +91,10 @@ export class AccordionPanel {
8891
exportAs: 'ngAccordionTrigger',
8992
host: {
9093
'class': 'ng-accordion-trigger',
91-
'[attr.data-active]': '_pattern.active()',
94+
'[attr.data-active]': 'active()',
9295
'role': 'button',
9396
'[id]': '_pattern.id()',
94-
'[attr.aria-expanded]': '_pattern.expanded()',
97+
'[attr.aria-expanded]': 'expanded()',
9598
'[attr.aria-controls]': '_pattern.controls()',
9699
'[attr.aria-disabled]': '_pattern.disabled()',
97100
'[attr.disabled]': 'hardDisabled() ? true : null',
@@ -117,6 +120,12 @@ export class AccordionTrigger {
117120
/** Whether the trigger is disabled. */
118121
disabled = input(false, {transform: booleanAttribute});
119122

123+
/** Whether the trigger is active. */
124+
readonly active = computed(() => this._pattern.active());
125+
126+
/** Whether the trigger is expanded. */
127+
readonly expanded = computed(() => this._pattern.expanded());
128+
120129
/**
121130
* Whether this trigger is completely inaccessible.
122131
*

0 commit comments

Comments
 (0)