You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<Hds::Accordion @forceState={{this.state}} as |A|>
155
+
<Hds::Accordion @forceState={{this.accordionState}} as |A|>
156
156
<A.Item>
157
157
<:toggle>Exam experience</:toggle>
158
158
<:content>
@@ -186,6 +186,55 @@ The `@forceState` argument enables you to implement expand/collapse all function
186
186
</Hds::Accordion>
187
187
```
188
188
189
+
### Persist Item state
190
+
191
+
The `@forceState` argument can be used to programmatically control individual Accordion Items. For example, use `@onClickToggle` to respond to the user’s click, save the open/close state, then use `@forceState` to persist the state if the screen refreshes.
192
+
193
+
```handlebars
194
+
<Hds::Accordion as |A|>
195
+
<A.Item>
196
+
<:toggle>Item one</:toggle>
197
+
<:content>
198
+
Additional content for item one
199
+
</:content>
200
+
</A.Item>
201
+
<A.Item
202
+
@onClickToggle={{this.onItemToggle}}
203
+
@forceState={{this.itemState}}
204
+
>
205
+
<:toggle>Item two</:toggle>
206
+
<:content>
207
+
Item open on page load. Click to close then refresh the window.
208
+
The Item will remember its state and remain closed.
209
+
</:content>
210
+
</A.Item>
211
+
<A.Item>
212
+
<:toggle>Item three</:toggle>
213
+
<:content>
214
+
Additional content for item three
215
+
</:content>
216
+
</A.Item>
217
+
</Hds::Accordion>
218
+
```
219
+
220
+
#### JavaScript code
221
+
222
+
```javascript{data-execute=false}
223
+
@tracked itemState;
224
+
225
+
// Store Item state in session storage to persist across page reloads
The `ariaLabel` value is applied to the HTML button which controls visibility of the content block. The text does not display in the UI. The default value is "Toggle display" but you can set a custom value useful for translated text for example.
0 commit comments