Skip to content

Commit 16a4d08

Browse files
committed
fix(aria/many): don't repeat keys
1 parent d67ac1f commit 16a4d08

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/aria/private/behaviors/event-manager/event-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface EventWithModifiers extends Event {
2424
* This library has not yet had a need for stopPropagationImmediate.
2525
*/
2626
export interface EventHandlerOptions {
27+
handleRepeat?: boolean;
2728
stopPropagation: boolean;
2829
preventDefault: boolean;
2930
}

src/aria/private/behaviors/event-manager/keyboard-event-manager.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type KeyCode = string | SignalLike<string> | RegExp;
3030
*/
3131
export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<T> {
3232
options: EventHandlerOptions = {
33+
handleRepeat: false,
3334
preventDefault: true,
3435
stopPropagation: true,
3536
};
@@ -50,7 +51,7 @@ export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<
5051

5152
this.configs.push({
5253
handler: handler,
53-
matcher: event => this._isMatch(event, key, modifiers),
54+
matcher: event => this._isMatch(event, key, modifiers, options),
5455
...this.options,
5556
...options,
5657
});
@@ -73,11 +74,20 @@ export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<
7374
};
7475
}
7576

76-
private _isMatch(event: T, key: KeyCode, modifiers: ModifierInputs) {
77+
private _isMatch(
78+
event: T,
79+
key: KeyCode,
80+
modifiers: ModifierInputs,
81+
options?: Partial<EventHandlerOptions>,
82+
): boolean {
7783
if (!hasModifiers(event, modifiers)) {
7884
return false;
7985
}
8086

87+
if (event.repeat && !options?.handleRepeat) {
88+
return false;
89+
}
90+
8191
if (key instanceof RegExp) {
8292
return key.test(event.key);
8393
}

src/aria/private/toolbar/toolbar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export class ToolbarPattern<V> {
8080
const manager = new KeyboardEventManager();
8181

8282
return manager
83-
.on(this._nextKey, () => this.listBehavior.next())
84-
.on(this._prevKey, () => this.listBehavior.prev())
85-
.on(this._altNextKey, () => this._groupNext())
86-
.on(this._altPrevKey, () => this._groupPrev())
83+
.on(this._nextKey, () => this.listBehavior.next(), {handleRepeat: true})
84+
.on(this._prevKey, () => this.listBehavior.prev(), {handleRepeat: true})
85+
.on(this._altNextKey, () => this._groupNext(), {handleRepeat: true})
86+
.on(this._altPrevKey, () => this._groupPrev(), {handleRepeat: true})
8787
.on(' ', () => this.select())
8888
.on('Enter', () => this.select())
8989
.on('Home', () => this.listBehavior.first())

0 commit comments

Comments
 (0)