@superherocheesecake/tab-indicator

1.0.1 • Public • Published

TabIndicator

Observes if a user is using the tab key (to navigate through the site).

Get the package

npm i --save @superherocheesecake/tab-indicator

Import

import TabIndicator from '@superherocheesecake/tab-indicator';

Basic Usage

const tabIndicator = new TabIndicator();

Events

Get Current State

addClassToBody() {
    document.body.classList.add('is-tab-enabled');
}
removeClassFromBody() {
    document.body.classList.remove('is-tab-enabled');
}

// single update event
tabIndicator.addEventListener('update', (isEnabled) => {
    if (isEnabled) {
        addClassToBody();
    }
    else {
        removeClassFromBody();
    }
});

// or listen to separate events
tabIndicator.addEventListener('enabled', () => {
    addClassToBody();
});
tabIndicator.addEventListener('disabled', () => {
    removeClassFromBody();
});

Methods

Get Current State

tabIndicator.isEnabled();

Examples

Example styling for focus (in _base.scss)

:focus {
    outline: highlight solid 2px;
    outline: -webkit-focus-ring-color auto 5px;
}

body:not(.is-tab-enabled) :focus {
    outline: none !important;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @superherocheesecake/tab-indicator

Weekly Downloads

1

Version

1.0.1

License

none

Unpacked Size

7.87 kB

Total Files

8

Last publish

Collaborators

  • n0cha
  • edwardmediamonks
  • wesleysmulders
  • ksawery.mediamonks
  • vandenhork25
  • johanholwerda
  • renedrie
  • kristemmerman123
  • odin.schwartz
  • bolex222
  • coco_g
  • frontend_shcc
  • alfred_shcc
  • carinashcc
  • lukasfeitsma
  • jameswhite
  • raul.roman
  • jaak.kivinukk