(modifier: KeyModifier, options: UseModifierOptions<Initial> = {})
| 28 | export type UseKeyModifierReturn<Initial> = ShallowRef<Initial extends boolean ? boolean : boolean | null> |
| 29 | |
| 30 | export function useKeyModifier<Initial extends boolean | null>(modifier: KeyModifier, options: UseModifierOptions<Initial> = {}): UseKeyModifierReturn<Initial> { |
| 31 | const { |
| 32 | events = defaultEvents, |
| 33 | document = defaultDocument, |
| 34 | initial = null, |
| 35 | } = options |
| 36 | |
| 37 | const state = shallowRef(initial) as ShallowRef<boolean> |
| 38 | |
| 39 | if (document) { |
| 40 | events.forEach((listenerEvent) => { |
| 41 | useEventListener(document, listenerEvent, (evt: KeyboardEvent | MouseEvent) => { |
| 42 | if (typeof evt.getModifierState === 'function') |
| 43 | state.value = evt.getModifierState(modifier) |
| 44 | }, { passive: true }) |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | return state |
| 49 | } |
nothing calls this directly
no test coverage detected