Skip to content

Commit f59c759

Browse files
authored
Merge branch 'angular:main' into aria-isnot
2 parents 494422f + ea08fb0 commit f59c759

File tree

6 files changed

+95
-18
lines changed

6 files changed

+95
-18
lines changed

src/aria/accordion/accordion.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ export class AccordionPanel {
8080
this._deferredContentAware.contentVisible.set(this.visible());
8181
});
8282
}
83+
84+
/** Expands this item. */
85+
expand() {
86+
this.accordionTrigger()?.expansionControl.open();
87+
}
88+
89+
/** Collapses this item. */
90+
collapse() {
91+
this.accordionTrigger()?.expansionControl.close();
92+
}
93+
94+
/** Toggles the expansion state of this item. */
95+
toggle() {
96+
this.accordionTrigger()?.expansionControl.toggle();
97+
}
8398
}
8499

85100
/**
@@ -145,6 +160,21 @@ export class AccordionTrigger {
145160
accordionGroup: computed(() => this._accordionGroup._pattern),
146161
accordionPanel: this.accordionPanel,
147162
});
163+
164+
/** Expands this item. */
165+
expand() {
166+
this._pattern.expansionControl.open();
167+
}
168+
169+
/** Collapses this item. */
170+
collapse() {
171+
this._pattern.expansionControl.close();
172+
}
173+
174+
/** Toggles the expansion state of this item. */
175+
toggle() {
176+
this._pattern.expansionControl.toggle();
177+
}
148178
}
149179

150180
/**
@@ -214,6 +244,16 @@ export class AccordionGroup {
214244
}
215245
});
216246
}
247+
248+
/** Expands all accordion panels if multi-expandable. */
249+
expandAll() {
250+
this._pattern.expansionManager.openAll();
251+
}
252+
253+
/** Collapses all accordion panels. */
254+
collapseAll() {
255+
this._pattern.expansionManager.closeAll();
256+
}
217257
}
218258

219259
/**

src/aria/combobox/combobox.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ export class Combobox<V> {
117117
}
118118
});
119119
}
120+
121+
/** Opens the combobox to the selected item. */
122+
open() {
123+
this._pattern.open({selected: true});
124+
}
125+
126+
/** Closes the combobox. */
127+
close() {
128+
this._pattern.close();
129+
}
120130
}
121131

122132
@Directive({

src/aria/menu/menu.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ export class MenuTrigger<V> {
8383
constructor() {
8484
effect(() => this.menu()?.parent.set(this));
8585
}
86+
87+
/** Opens the menu focusing on the first menu item. */
88+
open() {
89+
this._pattern.open({first: true});
90+
}
91+
92+
/** Closes the menu. */
93+
close() {
94+
this._pattern.close();
95+
}
8696
}
8797

8898
/**
@@ -220,24 +230,9 @@ export class Menu<V> {
220230
});
221231
}
222232

223-
// TODO(wagnermaciel): Author close, closeAll, and open methods for each directive.
224-
225233
/** Closes the menu. */
226-
close(opts?: {refocus?: boolean}) {
227-
this._pattern.inputs.parent()?.close(opts);
228-
}
229-
230-
/** Closes all parent menus. */
231-
closeAll(opts?: {refocus?: boolean}) {
232-
const root = this._pattern.root();
233-
234-
if (root instanceof MenuTriggerPattern) {
235-
root.close(opts);
236-
}
237-
238-
if (root instanceof MenuPattern || root instanceof MenuBarPattern) {
239-
root.inputs.activeItem()?.close(opts);
240-
}
234+
close() {
235+
this._pattern.close();
241236
}
242237
}
243238

@@ -318,6 +313,11 @@ export class MenuBar<V> {
318313
}
319314
});
320315
}
316+
317+
/** Closes the menubar. */
318+
close() {
319+
this._pattern.close();
320+
}
321321
}
322322

323323
/**
@@ -396,6 +396,16 @@ export class MenuItem<V> {
396396
constructor() {
397397
effect(() => this.submenu()?.parent.set(this));
398398
}
399+
400+
/** Opens the submenu focusing on the first menu item. */
401+
open() {
402+
this._pattern.open({first: true});
403+
}
404+
405+
/** Closes the submenu. */
406+
close() {
407+
this._pattern.close();
408+
}
399409
}
400410

401411
/** Defers the rendering of the menu content. */

src/aria/private/menu/menu.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ export class MenuPattern<V> {
395395
}
396396
}
397397

398+
/** Closes the menu. */
399+
close() {
400+
this.inputs.parent()?.close();
401+
}
402+
398403
/** Closes the menu and all parent menus. */
399404
closeAll() {
400405
const root = this.root();

src/aria/tabs/tabs.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ export class Tabs {
112112
this._unorderedPanels.set(new Set(this._unorderedPanels()));
113113
}
114114
}
115+
116+
/** Opens the tab panel with the specified value. */
117+
open(value: string) {
118+
const tab = this.tabs()?.find(t => t.value() === value);
119+
120+
tab?.expansion.open();
121+
}
115122
}
116123

117124
/**
@@ -286,6 +293,11 @@ export class Tab implements HasElement, OnInit, OnDestroy {
286293
value: this.value,
287294
});
288295

296+
/** Opens this tab panel. */
297+
open() {
298+
this._pattern.expansion.open();
299+
}
300+
289301
ngOnInit() {
290302
this._tabList.register(this);
291303
}

src/components-examples/aria/menu/menu-context/menu-context-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class MenuContextExample {
3737

3838
open(event: MouseEvent) {
3939
const menu = this.menu();
40-
menu?.closeAll();
40+
menu?._pattern.closeAll();
4141

4242
if (menu) {
4343
event.preventDefault();

0 commit comments

Comments
 (0)