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

has-tabbed

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

has-tabbed

Small library that adds CSS class to html when user starts tabbing, and removes it if user clicks anywhere.

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

has-tabbed

npm version npm downloads

:focus-visible

Today, :focus-visible is widely supported, so you probably want to use that instead of this library. However, I'll keep it around for posterity and poor souls that still have to support old browsers.

What is this?

Small library that adds CSS class to html when user starts using keyboard to navigate, and removes it if user clicks anywhere.

This enables you to have focus outline only when user is using keyboard.

Demo | Blog post

Usage

Get it from npm

npm install --save has-tabbed

and use it

import HasTabbed from 'has-tabbed';

const tabbed = new HasTabbed();

That's it. By default library is active when instance is created. You can control it manually by using addEvents and removeEvents methods.

// Removes all listeners and CSS class
tabbed.removeEvents();

// Adds listeners again
tabbed.addEvents();

Then you can use has-tabbed class in your CSS

/* This is naive example used in the demo */
* {
  outline: 3px solid transparent;
  outline-offset: 0.3rem;
}

.has-tabbed *:focus {
  outline: 3px solid #409ad7;
}

Options

Library accepts a single options object with the following properties:

  • className (default has-tabbed)

    CSS class name which will be added to the html element.

  • triggerOnAllKeys (default false)

    If you want to add CSS class on all keyboard events not only when user presses tab, change this one to true

import HasTabbed from 'has-tabbed';

const tabbed = new HasTabbed({
  className: 'navigating-using-keyboard',
  triggerOnAllKeys: true,
});

v1.0.0 breaking changes

  • className property is now replaced with an options object.
  • Default class name is changed from --tabbed to has-tabbed.

Old school usage

You should use ES modules, but you can use it directly in the browser.

<!-- copy "has-tabbed.js" to your project -->
<script src="has-tabbed.js"></script>
<script>
  var tabbed = new HasTabbed();
</script>

Keywords

FAQs

Package last updated on 19 Jul 2023

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