@hyperfrontend/ui-utils/event

event

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

§function

clickAtPosition(x: number, y: number): void

Simulates a mouse click at the specified screen coordinates. Dispatches a synthetic mousedown event to the document.

Parameters

NameTypeDescription
number
The x-coordinate for the click position
number
The y-coordinate for the click position

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()
§function

createGestureListener(callback: Callback): () => void

Creates a gesture listener that detects mouse/touch interactions and keyboard events with a cleanup function.

Parameters

NameTypeDescription
§callback
Callback
The function to execute when a gesture is detected (Escape key or pinch gesture)

Returns

() => void
A 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()

Types

§type

Callback

Callback function invoked when a gesture is detected.
type Callback = () => void
§type

TMouseEvent

Extended MouseEvent with guaranteed pageX and pageY coordinates.
type TMouseEvent = MouseEvent & ClickPageCoordinates