Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tijnjh/ios-haptics/llms.txt

Use this file to discover all available pages before exploring further.

haptic is the main export of ios-haptics. When called, it triggers a single haptic tap on iOS (via the checkbox switch trick) or a 50ms vibration on Android (via navigator.vibrate). Import
import { haptic } from 'ios-haptics'

haptic()

Triggers a single haptic feedback event. Signature: haptic(): void
document.getElementById('my-button').addEventListener('click', () => {
  haptic()
})
On iOS, haptic() creates an <input type="checkbox" switch> element wrapped in a hidden label, appends it to document.head, clicks it, then immediately removes it. This exploits the native checkbox switch interaction to produce a haptic tap. On Android, it calls navigator.vibrate(50) instead.

haptic.confirm()

Triggers two rapid haptic feedback events — suitable for confirmation actions. Signature: haptic.confirm(): void On iOS, calls haptic() twice, 120ms apart. On Android, calls navigator.vibrate([50, 70, 50]).
document.getElementById('submit-button').addEventListener('click', () => {
  haptic.confirm()
})
Use this for success confirmations, form submissions, or positive user actions.

haptic.error()

Triggers three rapid haptic feedback events — suitable for error states. Signature: haptic.error(): void On iOS, calls haptic() three times, 120ms apart (at 0ms, 120ms, and 240ms). On Android, calls navigator.vibrate([50, 70, 50, 70, 50]).
document.getElementById('submit-button').addEventListener('click', () => {
  try {
    submitForm()
  } catch {
    haptic.error()
  }
})
Use this for validation errors, failed operations, or warning states.

Error handling

The internal _haptic() function is wrapped in a try/catch block — any DOM errors are silently ignored. The library will never throw, so it is always safe to call without additional error handling.

Build docs developers (and LLMs) love