Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@notainc/key-focus-visible

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@notainc/key-focus-visible

This library allows you to show CSS :focus pseudo-class only when triggered by the keyboard.

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
210
decreased by-65.8%
Maintainers
5
Weekly downloads
 
Created
Source

Key focus visible

This library allows you to show CSS :focus pseudo-class only when triggered by the keyboard.

Alternatively, :focus-visible polyfill is available. Here are advantages compared to the polifill:

  • Easy to debug the stylesheets on Chrome.
  • Does not conflict with React or Vue since it doesn't change the DOM of each element.
  • Code is simpler.

Detailed behavior:

  • Works well when the focus is returned after you close the modal/dropdown by the mouse or keyboard.
  • Works well when the focus is given programmatically.

In both cases, we remember the last used input device to focus, and if it was a keyboard, focus is shown, if it was a pointing device, focus is not shown.

Install

$ npm install @notainc/key-focus-visible

How to use

Just import/require this library to your project.

import '@notainc/key-focus-visible'

It sets data-focus-visible attribute on body element when the focus is given by the keyboard. So you can apply the style as follows:

*:focus {
  outline: none;
}

[data-focus-visible] *:focus {
  box-shadow: 0 0 0px 4px rgba(64, 167, 255, 0.6);
}

You can also use it in Sass:

.foo-component {
  background-color: #fff;

  &:active,
  &:hover,
  [data-focus-visible] &:focus {
    background-color: #ccc;
  }
}

Demo

See the live demo here

Compatibility

Suports ordinary modern dekstop browsers (Chrome, Firefox, Safari, Opera, Edge) and mobile browsers (Chrome for Android, iOS Safari)

Does not throw error on IE.

License

This software is released under the MIT License, see LICENSE.

Keywords

FAQs

Package last updated on 24 Apr 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc