Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/aria/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ export class AccordionPanel {
this._deferredContentAware.contentVisible.set(this.visible());
});
}

/** Expands this item. */
expand() {
this.accordionTrigger()?.expansionControl.open();
}

/** Collapses this item. */
collapse() {
this.accordionTrigger()?.expansionControl.close();
}

/** Toggles the expansion state of this item. */
toggle() {
this.accordionTrigger()?.expansionControl.toggle();
}
}

/**
Expand Down Expand Up @@ -145,6 +160,21 @@ export class AccordionTrigger {
accordionGroup: computed(() => this._accordionGroup._pattern),
accordionPanel: this.accordionPanel,
});

/** Expands this item. */
expand() {
this._pattern.expansionControl.open();
}

/** Collapses this item. */
collapse() {
this._pattern.expansionControl.close();
}

/** Toggles the expansion state of this item. */
toggle() {
this._pattern.expansionControl.toggle();
}
}

/**
Expand Down Expand Up @@ -214,6 +244,16 @@ export class AccordionGroup {
}
});
}

/** Expands all accordion panels if multi-expandable. */
expandAll() {
this._pattern.expansionManager.openAll();
}

/** Collapses all accordion panels. */
collapseAll() {
this._pattern.expansionManager.closeAll();
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/aria/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ export class Combobox<V> {
}
});
}

/** Opens the combobox to the selected item. */
open() {
this._pattern.open({selected: true});
}

/** Closes the combobox. */
close() {
this._pattern.close();
}
}

@Directive({
Expand Down
44 changes: 27 additions & 17 deletions src/aria/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ export class MenuTrigger<V> {
constructor() {
effect(() => this.menu()?.parent.set(this));
}

/** Opens the menu focusing on the first menu item. */
open() {
this._pattern.open({first: true});
}

/** Closes the menu. */
close() {
this._pattern.close();
}
}

/**
Expand Down Expand Up @@ -220,24 +230,9 @@ export class Menu<V> {
});
}

// TODO(wagnermaciel): Author close, closeAll, and open methods for each directive.

/** Closes the menu. */
close(opts?: {refocus?: boolean}) {
this._pattern.inputs.parent()?.close(opts);
}

/** Closes all parent menus. */
closeAll(opts?: {refocus?: boolean}) {
const root = this._pattern.root();

if (root instanceof MenuTriggerPattern) {
root.close(opts);
}

if (root instanceof MenuPattern || root instanceof MenuBarPattern) {
root.inputs.activeItem()?.close(opts);
}
close() {
this._pattern.close();
}
}

Expand Down Expand Up @@ -318,6 +313,11 @@ export class MenuBar<V> {
}
});
}

/** Closes the menubar. */
close() {
this._pattern.close();
}
}

/**
Expand Down Expand Up @@ -396,6 +396,16 @@ export class MenuItem<V> {
constructor() {
effect(() => this.submenu()?.parent.set(this));
}

/** Opens the submenu focusing on the first menu item. */
open() {
this._pattern.open({first: true});
}

/** Closes the submenu. */
close() {
this._pattern.close();
}
}

/** Defers the rendering of the menu content. */
Expand Down
5 changes: 5 additions & 0 deletions src/aria/private/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ export class MenuPattern<V> {
}
}

/** Closes the menu. */
close() {
this.inputs.parent()?.close();
}

/** Closes the menu and all parent menus. */
closeAll() {
const root = this.root();
Expand Down
12 changes: 12 additions & 0 deletions src/aria/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ export class Tabs {
this._unorderedPanels.set(new Set(this._unorderedPanels()));
}
}

/** Opens the tab panel with the specified value. */
open(value: string) {
const tab = this.tabs()?.find(t => t.value() === value);

tab?.expansion.open();
}
}

/**
Expand Down Expand Up @@ -286,6 +293,11 @@ export class Tab implements HasElement, OnInit, OnDestroy {
value: this.value,
});

/** Opens this tab panel. */
open() {
this._pattern.expansion.open();
}

ngOnInit() {
this._tabList.register(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class MenuContextExample {

open(event: MouseEvent) {
const menu = this.menu();
menu?.closeAll();
menu?._pattern.closeAll();

if (menu) {
event.preventDefault();
Expand Down
Loading