🚀 DAY 4 OF LAUNCH WEEK: Introducing GitHub Actions Scanning Support.Learn more
Socket
Book a DemoInstallSign in
Socket

fauxcus

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fauxcus

Make in-page links accessible on mobile devices

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Fauxcus (fōˈkəs) Build status

Description

Fauxcus allows the focusing of all elements. This includes elements that are normally not focusable such as the main element or div elements. It does so by adding a tabindex attribute with a value of -1. In addition to adding the tabindex attribute an event listener is bound that will remove the tabindex attribute when the element loses focus.

The functionality that fauxcus provides is particularly useful for skip links and other in-page links that are currently (as of late 2018) broken on mobile devices. It is a vanilla JavaScript implementation of the focusing functionality of Anika Henke's solution. Her solution also deals with hash changes and URLs that contain a fragment identifier when opened. fauxcus only handles setting focus.

Installation

Install using npm or yarn.

$ npm install --save fauxcus

API

fauxcus(node)

Put focus on node.

When node is already focusable, either because it is by default or it already has a tabindex attribute, it will only get focus.

If it is not focusable it will be made focusable by adding a tabindex="-1" attribute and get focus. It will lose the tabindex attribute upon losing focus.

Example

import { fauxcus } from 'fauxcus';

const main = document.querySelector('main');

fauxcus(main);

Keywords

focus

FAQs

Package last updated on 08 Oct 2018

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