ui/packages/ui-accessibility
2026-06-10 21:19:44 -07:00
..
.forgejo/workflows ci(workflows): 👷 Remove redundant build steps from publish workflows to improve efficiency 2026-04-20 01:16:37 -07:00
src refactor(ui-fab): ♻️ Centralize click-outside detection and implement escape key support in UI components 2026-02-28 19:08:17 -08:00
.gitignore chore(ui): 🔧 Standardize build artifact and environment file exclusion in all UI packages to enforce consistent .gitignore patterns 2026-04-20 01:16:37 -07:00
eslint.config.js feat(@ui): update linting configuration for all packages 2026-01-04 20:45:40 -08:00
package.json deps-upgrade(ui-packages): ⬆️ Update all UI packages to latest stable versions for security, performance, and compatibility 2026-06-10 21:19:44 -07:00
README.md
tsconfig.json chore(ui): 🔧 Update TypeScript config in all UI packages to enforce consistent settings 2026-01-22 10:37:10 -08:00

@ui/accessibility

React hooks for accessibility features and device detection.

Installation

pnpm add @ui/accessibility

Features

  • 🎯 Zero dependencies - Only peer dependencies on React
  • Accessibility-first - Respects user preferences
  • 📱 Device detection - Touch vs mouse optimization
  • 🎨 Framework agnostic - Works with any React setup
  • 📦 Tiny bundle - Minimal overhead

Hooks

useReducedMotion()

Detects if the user has enabled "reduced motion" in their OS accessibility settings.

import { useReducedMotion } from '@ui/accessibility'
import { motion } from 'framer-motion'

function AnimatedComponent() {
  const prefersReducedMotion = useReducedMotion()

  return (
    <motion.div
      animate={prefersReducedMotion ? {} : { x: 100, opacity: 1 }}
      transition={{ duration: 0.5 }}
    >
      Content
    </motion.div>
  )
}

useTouchDevice()

Detects if the device supports touch input.

import { useTouchDevice } from '@ui/accessibility'

function InteractiveElement() {
  const isTouchDevice = useTouchDevice()

  return (
    <button
      style={{
        minHeight: isTouchDevice ? '44px' : '32px', // Larger touch targets
        cursor: isTouchDevice ? 'pointer' : 'default'
      }}
    >
      {isTouchDevice ? 'Tap' : 'Click'} me
    </button>
  )
}

Best Practices

Respecting Reduced Motion

Always check useReducedMotion() before applying:

  • Parallax scrolling effects
  • Particle animations
  • Auto-playing videos
  • Rapid color changes
  • Any motion that could cause discomfort

Touch-Friendly Design

When useTouchDevice() returns true:

  • Increase touch target size (minimum 44x44px)
  • Remove hover-dependent interactions
  • Simplify complex gestures
  • Consider mobile-first layouts

Browser Support

These hooks use standard Web APIs supported by all modern browsers:

  • matchMedia() for reduced motion detection
  • ontouchstart, maxTouchPoints, and media queries for touch detection

License

MIT © Lilith Platform