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
32 changes: 17 additions & 15 deletions src/aria/private/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ export class ToolbarPattern<V> {
const manager = new KeyboardEventManager();

return manager
.on(this._nextKey, () => this._next())
.on(this._prevKey, () => this._prev())
.on(this._altNextKey, () => this._groupNext())
.on(this._altPrevKey, () => this._groupPrev())
.on(' ', () => this._trigger())
.on('Enter', () => this._trigger())
.on('Home', () => this._first())
.on('End', () => this._last());
.on(this._nextKey, () => this.next())
.on(this._prevKey, () => this.prev())
.on(this._altNextKey, () => this.groupNext())
.on(this._altPrevKey, () => this.groupPrev())
.on(' ', () => this.trigger())
.on('Enter', () => this.trigger())
.on('Home', () => this.first())
.on('End', () => this.last());
});

/** The pointerdown event manager for the toolbar. */
private readonly _pointerdown = computed(() => new PointerEventManager().on(e => this._goto(e)));

/** Navigates to the next widget in the toolbar. */
private _next() {
next() {
const item = this.inputs.activeItem();
if (item instanceof ToolbarWidgetGroupPattern) {
if (!item.disabled() && !item.controls().isOnLastItem()) {
Expand All @@ -111,7 +111,7 @@ export class ToolbarPattern<V> {
}

/** Navigates to the previous widget in the toolbar. */
private _prev() {
prev() {
const item = this.inputs.activeItem();
if (item instanceof ToolbarWidgetGroupPattern) {
if (!item.disabled() && !item.controls().isOnFirstItem()) {
Expand All @@ -128,28 +128,30 @@ export class ToolbarPattern<V> {
}
}

private _groupNext() {
/** Navigates to the next group in the toolbar. */
groupNext() {
const item = this.inputs.activeItem();
if (item instanceof ToolbarWidgetPattern) return;
item?.controls().next(true);
}

private _groupPrev() {
/** Navigates to the previous group in the toolbar. */
groupPrev() {
const item = this.inputs.activeItem();
if (item instanceof ToolbarWidgetPattern) return;
item?.controls().prev(true);
}

/** Triggers the action of the currently active widget. */
private _trigger() {
trigger() {
const item = this.inputs.activeItem();
if (item instanceof ToolbarWidgetGroupPattern) {
item.controls().trigger();
}
}

/** Navigates to the first widget in the toolbar. */
private _first() {
first() {
const item = this.inputs.activeItem();
if (item instanceof ToolbarWidgetGroupPattern) {
item.controls().unfocus();
Expand All @@ -163,7 +165,7 @@ export class ToolbarPattern<V> {
}

/** Navigates to the last widget in the toolbar. */
private _last() {
last() {
const item = this.inputs.activeItem();
if (item instanceof ToolbarWidgetGroupPattern) {
item.controls().unfocus();
Expand Down
35 changes: 35 additions & 0 deletions src/aria/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,41 @@ export class Toolbar<V> {
}
}

/** Navigates to the next widget in the toolbar. */
next(): void {
this._pattern.next();
}

/** Navigates to the previous widget in the toolbar. */
prev(): void {
this._pattern.prev();
}

/** Navigates to the first widget in the toolbar. */
first(): void {
this._pattern.first();
}

/** Navigates to the last widget in the toolbar. */
last(): void {
this._pattern.last();
}

/** Navigates to the next group in the toolbar. */
groupNext() {
this._pattern.groupNext();
}

/** Navigates to the previous group in the toolbar. */
groupPrev() {
this._pattern.groupPrev();
}

/** Triggers the action of the currently active widget. */
trigger() {
this._pattern.trigger();
}

/** Finds the toolbar item associated with a given element. */
private _getItem(element: Element) {
const widgetTarget = element.closest('.ng-toolbar-widget');
Expand Down
Loading