88
99import { Directive , ElementRef , afterRenderEffect , computed , inject , input } from '@angular/core' ;
1010import { _IdGenerator } from '@angular/cdk/a11y' ;
11- import { DeferredContentAware , AccordionTriggerPattern } from '../private' ;
11+ import { DeferredContentAware , AccordionTriggerPattern , LabelControl } from '../private' ;
1212
1313/**
1414 * The content panel of an accordion item that is conditionally visible.
@@ -43,7 +43,8 @@ import {DeferredContentAware, AccordionTriggerPattern} from '../private';
4343 host : {
4444 'role' : 'region' ,
4545 '[attr.id]' : 'id()' ,
46- '[attr.aria-labelledby]' : '_pattern?.id()' ,
46+ '[attr.aria-label]' : '_labelControl.label()' ,
47+ '[attr.aria-labelledby]' : '_labelControl.labelledBy()' ,
4748 '[attr.inert]' : '!visible() ? true : null' ,
4849 } ,
4950} )
@@ -57,9 +58,16 @@ export class AccordionPanel {
5758 /** The DeferredContentAware host directive. */
5859 private readonly _deferredContentAware = inject ( DeferredContentAware ) ;
5960
61+ /** Controls label for this tabpanel. */
62+ readonly _labelControl : LabelControl ;
63+
6064 /** A global unique identifier for the panel. */
6165 readonly id = input ( inject ( _IdGenerator ) . getId ( 'ng-accordion-panel-' , true ) ) ;
6266
67+ readonly label = input < string | undefined > ( undefined ) ;
68+
69+ readonly labelledBy = input < string [ ] > ( [ ] ) ;
70+
6371 /** Whether the accordion panel is visible. True if the associated trigger is expanded. */
6472 readonly visible = computed ( ( ) => this . _pattern ?. expanded ( ) === true ) ;
6573
@@ -71,6 +79,12 @@ export class AccordionPanel {
7179 _pattern ?: AccordionTriggerPattern ;
7280
7381 constructor ( ) {
82+ this . _labelControl = new LabelControl ( {
83+ defaultLabelledBy : computed ( ( ) => this . _pattern ! . id ( ) ) ,
84+ label : this . label ,
85+ labelledBy : this . labelledBy ,
86+ } ) ;
87+
7488 // Connect the panel's hidden state to the DeferredContentAware's visibility.
7589 afterRenderEffect ( {
7690 write : ( ) => {
0 commit comments