Skip to content
Open
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 @@ -77,6 +77,21 @@ export class AccordionPanel {
this._deferredContentAware.contentVisible.set(!this._pattern.hidden());
});
}

/** 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 @@ -136,6 +151,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 @@ -205,6 +235,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
15 changes: 15 additions & 0 deletions src/aria/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ export class Combobox<V> {
}
});
}

/** Opens the combobox. */
open(nav?: {first?: boolean; last?: boolean; selected?: boolean}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should discuss with the team how these navigation options are surfaced to developers. When it was an internal impl detail, it was fine to just call open({first: true}), etc. But now that it is part of the public api, it would be good to see if folks think there is a more intuitive way to expose this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. I will add that the context-menu example appears to call _pattern.first() because there was no option to open and navigate to first, so at least providing it in the open (or simply making the default first: true) will remove the need to expose navigation separately. But again, just having it clearly navigate to first would possibly be enough.

this._pattern.open(nav);
}

/** Closes the combobox. */
close(opts?: {reset: boolean}) {
this._pattern.close(opts);
}

/** Selects an item in the combobox popup. */
select(opts: {item?: V; commit?: boolean; close?: boolean} = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't expose item, or close as options here. Not sure what we should do about commit, but will likely need to go a different route than surfacing it as a option this way

this._pattern.select(opts);
}
}

@Directive({
Expand Down
39 changes: 27 additions & 12 deletions src/aria/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ export class MenuTrigger<V> {
onFocusIn() {
this.hasBeenFocused.set(true);
}

/** Opens the menu. */
open(opts?: {first?: boolean; last?: boolean}) {
this._pattern.open(opts);
}

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

/**
Expand Down Expand Up @@ -223,24 +233,14 @@ 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);
this._pattern.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);
}
this._pattern.closeAll(opts);
}
}

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

/** Closes the menubar and refocuses the root menu bar item. */
close(opts?: {refocus?: boolean}) {
this._pattern.close(opts);
}
}

/**
Expand Down Expand Up @@ -403,6 +408,16 @@ export class MenuItem<V> {
onFocusIn() {
this.hasBeenFocused.set(true);
}

/** Opens the submenu. */
open(opts?: {first?: boolean; last?: boolean}) {
this._pattern.open(opts);
}

/** Closes the submenu. */
close(opts: {refocus?: boolean} = {}) {
this._pattern.close(opts);
}
}

/** Defers the rendering of the menu content. */
Expand Down
19 changes: 13 additions & 6 deletions src/aria/private/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class MenuPattern<V> {
.on('Home', () => this.first())
.on('End', () => this.last())
.on('Enter', () => this.trigger())
.on('Escape', () => this.closeAll())
.on('Escape', () => this.closeAll({refocus: true}))
.on(this._expandKey, () => this.expand())
.on(this._collapseKey, () => this.collapse())
.on(this.dynamicSpaceKey, () => this.trigger())
Expand Down Expand Up @@ -345,20 +345,25 @@ export class MenuPattern<V> {
}
}

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

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

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

if (root instanceof MenuBarPattern) {
root.close();
}

if (root instanceof MenuPattern) {
root.inputs.activeItem()?.close({refocus: true});
root.inputs.activeItem()?.close(opts);
}
}
}
Expand Down Expand Up @@ -496,8 +501,10 @@ export class MenuBarPattern<V> {
}

/** Closes the menubar and refocuses the root menu bar item. */
close() {
this.inputs.activeItem()?.close({refocus: this.isFocused()});
close(opts?: {refocus?: boolean}) {
opts ??= {refocus: this.isFocused()};

this.inputs.activeItem()?.close(opts);
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/aria/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ export class Tabs {
this._unorderedPanels.set(new Set(this._unorderedPanels()));
}
}

/** Opens the tab panel with the specified value. */
open(value: string) {
const tab = this._findTabPatternByValue(value);

tab?.expansion.open();
}

_findTabPatternByValue(value: string) {
return this.tabs()?.find(t => t.value() === value);
}
}

/**
Expand Down Expand Up @@ -277,6 +288,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
10 changes: 10 additions & 0 deletions src/aria/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ export class Tree<V> {
scrollActiveItemIntoView(options: ScrollIntoViewOptions = {block: 'nearest'}) {
this._pattern.inputs.activeItem()?.element().scrollIntoView(options);
}

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

/** Collapses all tree items. */
collapseAll() {
this._pattern.expansionManager.closeAll();
}
}

/**
Expand Down
Loading