describe('withKeys and withModifiers as pro', () => {
const onKeydown = withKeys(e => {}, [''])
- const onClick = withModifiers(e => {}, [''])
+ const onClick = withModifiers(e => {}, [])
;<input onKeydown={onKeydown} onClick={onClick} />
})
})
test('it should support key modifiers and system modifiers', () => {
- const keyNames = ['ctrl', 'shift', 'meta', 'alt']
+ const keyNames = ['ctrl', 'shift', 'meta', 'alt'] as const
keyNames.forEach(keyName => {
const el = document.createElement('div')
const systemModifiers = ['ctrl', 'shift', 'alt', 'meta']
type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent
+type ModifierGuardsKeys =
+ | 'stop'
+ | 'prevent'
+ | 'self'
+ | 'ctrl'
+ | 'shift'
+ | 'alt'
+ | 'meta'
+ | 'left'
+ | 'middle'
+ | 'right'
+ | 'exact'
const modifierGuards: Record<
- string,
+ ModifierGuardsKeys,
(e: Event, modifiers: string[]) => void | boolean
> = {
stop: e => e.stopPropagation(),
T extends (event: Event, ...args: unknown[]) => any,
>(
fn: T & { _withMods?: { [key: string]: T } },
- modifiers: string[],
+ modifiers: ModifierGuardsKeys[],
) => {
const cache = fn._withMods || (fn._withMods = {})
const cacheKey = modifiers.join('.')