Socket
Book a DemoInstallSign in
Socket

track-focus

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

track-focus

Tracks the focus event for better accessibility styling.

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
14
-65%
Maintainers
1
Weekly downloads
 
Created
Source

I created a newer version of trackFocus that includes more generic event detection (including touch and pointer), only adds a single attribute to the body instead of littering the DOM with classes and exposes a small API for scripting. Check out What Input?.

Track Focus

trackFocus adds a class to elements when they receive focus, allowing specific styling for keyboard versus mouse interaction.

Check out the demo page.

How it works

  • Watches the body for the mousedown and keydown events and stores as a variable.
  • Watches the body for the focusin event and applies the correct class based on whether the previous event was from the mouse or keyboard.
  • Watches the body for the focusout event and removes the mouse/keyboard class.
  • Style the focus state as needed.

Usage

  • Include trackFocus.min.js (just 500 bytes).
  • Style focus states.

Compatibility

Works as-is in all modern browsers. For older browsers, like IE8, grab these polyfills:

Keywords

accessibility

FAQs

Package last updated on 31 Oct 2017

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.