@hyperfrontend/ui-utils/eventevent
Synthetic mouse-event emission and gesture-listener helpers.
clickAtPosition dispatches a synthetic click at given page coordinates — useful for programmatic interactions and tests. createGestureListener builds a unified pointer-down / pointer-move / pointer-up handler chain that abstracts over mouse, touch, and pen events, calling a single Callback shape regardless of input type.
API Reference
ƒ Functions
Simulates a mouse click at the specified screen coordinates. Dispatches a synthetic mousedown event to the document.
Parameters
Example
Simulating click at coordinates
// Test that a click outside a modal closes it
document.addEventListener('mousedown', (event) => {
if (!modalElement.contains(event.target as Node)) {
closeModal()
}
})
clickAtPosition(0, 0) // Simulate click at top-left corner
expect(modalElement).not.toBeVisible()Creates a gesture listener that detects mouse/touch interactions and keyboard events with a cleanup function.
Parameters
| Name | Type | Description |
|---|---|---|
§callback | Callback | The function to execute when a gesture is detected (Escape key or pinch gesture) |
Returns
() => voidA cleanup function to remove all event listeners
Example
Detecting gestures for overlay
const closeOverlay = () => {
overlay.style.display = 'none'
}
// Listen for Escape key or pinch-out gesture
const cleanup = createGestureListener(closeOverlay)
// Remove listeners when overlay is destroyed
cleanup()