Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@charlietango/use-interaction

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@charlietango/use-interaction

Monitor the user interactions on an element

Source
npmnpm
Version
1.7.4
Version published
Weekly downloads
13
-50%
Maintainers
2
Weekly downloads
 
Created
Source

useInteraction

Monitor the user interactions on an element

Checkout the Storybook demo.

Installation

yarn add @charlietango/use-interaction

If the application is using the focus-visible polyfill, then the class it adds will be detected and used to to report the status of focusVisible.

API

const [ref, status] = useInteraction()

The hook returns an Array with a ref function, and the current interaction status. Assign the ref to the element you want to monitor.

status

The status is an object containing a boolean for each of the following properties:

  • active - The user is currently pressing the element, either with the mouse or touch
  • focus - The element has focus
  • focusVisible - The focus outline shouldn't be shown - Enabled if using focus-visible polyfill
  • focusWithin - An element inside this element currently has focus. This will also affect the focusVisible
  • hover - The user is hovering over the element with the mouse, or it was touched and still has focus

Example

import React from 'react'
import useInteraction from '@charlietango/use-interaction'

const Component = () => {
  const [ref, status] = useInteraction()
  return <div ref={ref}>Hovering: {status.hover}</div>
}

export default Component

Keywords

react

FAQs

Package last updated on 10 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts