1
- import { Component , Host , h , Element , ComponentInterface , State , Prop } from '@stencil/core'
1
+ import { Component , Host , h , Element , ComponentInterface , State , Prop , Method } from '@stencil/core'
2
2
import { BEM } from '../../../utils/bem'
3
3
import { Loggable , Logger , LogInstance } from '../../../utils/log'
4
4
import { stopEventBubbling } from '../../../utils/form-input'
5
5
import { AccordionState } from '../../../interfaces'
6
+ import { BalConfigState , BalLanguage , defaultConfig , ListenToConfig } from '../../../utils/config'
7
+ import { i18nBalAccordion } from '../bal-accordion.i18n'
8
+ import { ariaBooleanToString } from 'packages/core/src/utils/aria'
6
9
7
10
@Component ( {
8
11
tag : 'bal-accordion-trigger' ,
@@ -14,6 +17,7 @@ export class AccordionTrigger implements ComponentInterface, Loggable {
14
17
@Element ( ) el ?: HTMLElement
15
18
16
19
@State ( ) parentAccordionId ?: string
20
+ @State ( ) language : BalLanguage = defaultConfig . language
17
21
18
22
log ! : LogInstance
19
23
@@ -90,6 +94,20 @@ export class AccordionTrigger implements ComponentInterface, Loggable {
90
94
this . updateAccordionId ( )
91
95
}
92
96
97
+ /**
98
+ * LISTENERS
99
+ * ------------------------------------------------------
100
+ */
101
+
102
+ /**
103
+ * @internal define config for the component
104
+ */
105
+ @Method ( )
106
+ @ListenToConfig ( )
107
+ async configChanged ( state : BalConfigState ) : Promise < void > {
108
+ this . language = state . language
109
+ }
110
+
93
111
/**
94
112
* GETTERS
95
113
* ------------------------------------------------------
@@ -170,6 +188,9 @@ export class AccordionTrigger implements ComponentInterface, Loggable {
170
188
iconTurn = { turn }
171
189
color = { this . color }
172
190
size = { this . size }
191
+ title = { this . active ? i18nBalAccordion [ this . language ] . close : i18nBalAccordion [ this . language ] . open }
192
+ aria-label = { this . active ? i18nBalAccordion [ this . language ] . close : i18nBalAccordion [ this . language ] . open }
193
+ aria-expanded = { ariaBooleanToString ( this . active ) }
173
194
onClick = { this . onClick }
174
195
>
175
196
{ label }
@@ -182,9 +203,11 @@ export class AccordionTrigger implements ComponentInterface, Loggable {
182
203
} }
183
204
id = { `${ id } -button` }
184
205
aria-controls = { `${ this . parentAccordionId } -details-content` }
185
- aria-label = "accordion trigger"
206
+ aria-expanded = { ariaBooleanToString ( this . active ) }
186
207
part = { buttonPart }
187
208
data-testid = "bal-accordion-trigger"
209
+ title = { this . active ? i18nBalAccordion [ this . language ] . close : i18nBalAccordion [ this . language ] . open }
210
+ aria-label = { this . active ? i18nBalAccordion [ this . language ] . close : i18nBalAccordion [ this . language ] . open }
188
211
onClick = { this . onClick }
189
212
{ ...triggerAttributes }
190
213
>
0 commit comments