Skip to content

Commit 42c7610

Browse files
committed
feat(aria/accordion): Extend public api with open/close methods
1 parent 022dba9 commit 42c7610

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/aria/accordion/accordion.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ export class AccordionPanel {
7676
this._deferredContentAware.contentVisible.set(!this.pattern.hidden());
7777
});
7878
}
79+
80+
/** Opens this item. */
81+
open(itemValue: string) {
82+
this.accordionTrigger()?.expansionControl.open();
83+
}
84+
85+
/** Closes this item. */
86+
close(itemValue: string) {
87+
this.accordionTrigger()?.expansionControl.close();
88+
}
89+
90+
/** Toggles the expansion state of this item. */
91+
toggle(itemValue: string) {
92+
this.accordionTrigger()?.expansionControl.toggle();
93+
}
7994
}
8095

8196
/**
@@ -135,6 +150,21 @@ export class AccordionTrigger {
135150
accordionGroup: computed(() => this._accordionGroup.pattern),
136151
accordionPanel: this.accordionPanel,
137152
});
153+
154+
/** Opens this item. */
155+
open(itemValue: string) {
156+
this.pattern.expansionControl.open();
157+
}
158+
159+
/** Closes this item. */
160+
close(itemValue: string) {
161+
this.pattern.expansionControl.close();
162+
}
163+
164+
/** Toggles the expansion state of this item. */
165+
toggle(itemValue: string) {
166+
this.pattern.expansionControl.toggle();
167+
}
138168
}
139169

140170
/**
@@ -204,6 +234,36 @@ export class AccordionGroup {
204234
}
205235
});
206236
}
237+
238+
/** Opens the specified item. */
239+
open(itemValue: string) {
240+
this.pattern.expansionManager.open(this._patternForValue(itemValue)!);
241+
}
242+
243+
/** Closes the specified item. */
244+
close(itemValue: string) {
245+
this.pattern.expansionManager.close(this._patternForValue(itemValue)!);
246+
}
247+
248+
/** Toggles the expansion state of the specified item. */
249+
toggle(itemValue: string) {
250+
this.pattern.expansionManager.toggle(this._patternForValue(itemValue)!);
251+
}
252+
253+
/** Opens all focusable items in the list. */
254+
openAll() {
255+
this.pattern.expansionManager.openAll();
256+
}
257+
258+
/** Closes all focusable items in the list. */
259+
closeAll() {
260+
this.pattern.expansionManager.closeAll();
261+
}
262+
263+
_patternForValue(value: string) {
264+
const trigger = this._triggers().find(t => t.value() === value);
265+
return trigger?.pattern;
266+
}
207267
}
208268

209269
/**

0 commit comments

Comments
 (0)