Skip to content

Commit 03685a9

Browse files
authored
fix(aria/combobox): avoid error for synthetic events (#33360)
Fixes that the `KeyboardEventManager` might throw an error for synthetic events. Also got rid of a couple of `any` usages. Fixes #33359.
1 parent 330b496 commit 03685a9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<
4646
options?: Partial<EventHandlerOptions>,
4747
): this;
4848

49-
on(...args: any[]) {
49+
on(...args: unknown[]) {
5050
const {modifiers, key, handler, options} = this._normalizeInputs(...args);
5151

5252
this.configs.push({
@@ -59,8 +59,8 @@ export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<
5959
return this;
6060
}
6161

62-
private _normalizeInputs(...args: any[]) {
63-
const withModifiers = Array.isArray(args[0]) || args[0] in Modifier;
62+
private _normalizeInputs(...args: unknown[]) {
63+
const withModifiers = Array.isArray(args[0]) || (args[0] as string) in Modifier;
6464
const modifiers = withModifiers ? args[0] : Modifier.None;
6565
const key = withModifiers ? args[1] : args[0];
6666
const handler = withModifiers ? args[2] : args[1];
@@ -80,7 +80,8 @@ export class KeyboardEventManager<T extends KeyboardEvent> extends EventManager<
8080
modifiers: ModifierInputs,
8181
options?: Partial<EventHandlerOptions>,
8282
): boolean {
83-
if (!hasModifiers(event, modifiers)) {
83+
// In some cases the `key` may be undefined, despite the types saying otherwise. See #33359.
84+
if (event.key == null || !hasModifiers(event, modifiers)) {
8485
return false;
8586
}
8687

0 commit comments

Comments
 (0)