Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/aria/private/behaviors/event-manager/event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface EventWithModifiers extends Event {
* This library has not yet had a need for stopPropagationImmediate.
*/
export interface EventHandlerOptions {
handleRepeat?: boolean;
stopPropagation: boolean;
preventDefault: boolean;
}
Expand Down
14 changes: 12 additions & 2 deletions src/aria/private/behaviors/event-manager/keyboard-event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type KeyCode = string | SignalLike<string> | RegExp;
*/
export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<T> {
options: EventHandlerOptions = {
handleRepeat: false,
preventDefault: true,
stopPropagation: true,
};
Expand All @@ -50,7 +51,7 @@ export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<

this.configs.push({
handler: handler,
matcher: event => this._isMatch(event, key, modifiers),
matcher: event => this._isMatch(event, key, modifiers, options),
...this.options,
...options,
});
Expand All @@ -73,11 +74,20 @@ export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<
};
}

private _isMatch(event: T, key: KeyCode, modifiers: ModifierInputs) {
private _isMatch(
event: T,
key: KeyCode,
modifiers: ModifierInputs,
options?: Partial<EventHandlerOptions>,
): boolean {
if (!hasModifiers(event, modifiers)) {
return false;
}

if (event.repeat && !options?.handleRepeat) {
return false;
}

if (key instanceof RegExp) {
return key.test(event.key);
}
Expand Down
10 changes: 5 additions & 5 deletions src/aria/private/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export class ToolbarPattern<V> {
const manager = new KeyboardEventManager();

return manager
.on(this._nextKey, () => this.listBehavior.next())
.on(this._prevKey, () => this.listBehavior.prev())
.on(this._altNextKey, () => this._groupNext())
.on(this._altPrevKey, () => this._groupPrev())
.on(this._nextKey, () => this.listBehavior.next(), {handleRepeat: true})
.on(this._prevKey, () => this.listBehavior.prev(), {handleRepeat: true})
.on(this._altNextKey, () => this._groupNext(), {handleRepeat: true})
.on(this._altPrevKey, () => this._groupPrev(), {handleRepeat: true})
.on(' ', () => this.select())
.on('Enter', () => this.select())
.on('Home', () => this.listBehavior.first())
Expand Down Expand Up @@ -179,7 +179,7 @@ export class ToolbarPattern<V> {

/** Handles click events for the toolbar. */
onClick(event: MouseEvent) {
if (this.disabled()) return;
if (this.disabled() || (event as PointerEvent).pointerType === '') return;
this._goto(event);
}

Expand Down
4 changes: 3 additions & 1 deletion src/aria/toolbar/toolbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ describe('Toolbar', () => {
};

const click = (element: HTMLElement, eventInit?: PointerEventInit) => {
element.dispatchEvent(new PointerEvent('click', {bubbles: true, ...eventInit}));
element.dispatchEvent(
new PointerEvent('click', {bubbles: true, pointerType: 'mouse', ...eventInit}),
);
fixture.detectChanges();
};

Expand Down
Loading