fix(core): allow undefined hotkey options (#1242)

This commit is contained in:
rahim
2026-04-07 02:06:39 -07:00
committed by GitHub
parent 7c63d82f84
commit d2c43db550
9 changed files with 22 additions and 23 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ export type HotkeyActionName =
export interface HotkeyActionContext {
store: AnyPlayerStore;
value?: number;
value?: number | undefined;
/** The matched key character (used by `seekToPercent` to derive digit). */
key: string;
}
+1 -1
View File
@@ -142,7 +142,7 @@ export class HotkeyCoordinator {
const { options, parsed } = binding;
if (options.disabled) continue;
if (event.repeat && options.allowRepeat === false) continue;
if (event.repeat && options.repeatable === false) continue;
// Only consider bindings matching the event's target scope.
const isDocBinding = options.target === 'document';
+4 -4
View File
@@ -16,12 +16,12 @@ export interface HotkeyOptions {
keys: string;
onActivate: (event: KeyboardEvent, key: string) => void;
/** Where to listen — `'player'` (container) or `'document'`. */
target?: 'player' | 'document';
target?: 'player' | 'document' | undefined;
/** Whether `event.repeat` should fire the callback. */
allowRepeat?: boolean;
disabled?: boolean;
repeatable?: boolean | undefined;
disabled?: boolean | undefined;
/** Action name for the ARIA registry. */
action?: string;
action?: string | undefined;
}
const MODIFIER_KEYS = new Set(['shift', 'ctrl', 'alt', 'meta']);
@@ -200,20 +200,20 @@ describe('HotkeyCoordinator', () => {
});
describe('repeat handling', () => {
it('ignores repeat events when allowRepeat is false', () => {
it('ignores repeat events when repeat is false', () => {
const c = setup();
const onActivate = vi.fn();
c.add({ keys: 'k', onActivate, allowRepeat: false });
c.add({ keys: 'k', onActivate, repeatable: false });
keydown(container, 'k', { repeat: true });
expect(onActivate).not.toHaveBeenCalled();
});
it('fires repeat events when allowRepeat is true', () => {
it('fires repeat events when repeatable is true', () => {
const c = setup();
const onActivate = vi.fn();
c.add({ keys: 'k', onActivate, allowRepeat: true });
c.add({ keys: 'k', onActivate, repeatable: true });
keydown(container, 'k', { repeat: true });