🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@gauntface/dpad-nav

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gauntface/dpad-nav

A JS / TS library to make it easy to add d-pad navigation to a web app.

2.0.2
Source
npm
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

D-Pad Navigation Library

alt text

This library makes it quick and easy to support D-Pad Navigation in a web app.

Install

npm install @gauntface/dpad-nav --save-dev

Alternatively, you can use a CDN to import one of the following:

DPad Helper & (Optional) Debugger Helper

<script src="https://unpkg.com/@gauntface/dpad-nav@2.0.1/build/cdn/bootstrap/dpad.js" async defer></script>
<script src="https://unpkg.com/@gauntface/dpad-nav@2.0.1/build/cdn/bootstrap/dpad-debugger.js" async defer></script>

DPad Library & (Optional) Debugger Library

<script src="https://unpkg.com/@gauntface/dpad-nav@2.0.1/build/cdn/lib/dpad-controller.js" async defer></script>
<script src="https://unpkg.com/@gauntface/dpad-nav@2.0.1/build/cdn/lib/debug-controller.js" async defer></script>

Usage

To support D-Pad navigation with this library, you need to do the following:

  • Add a tabindex and class="dpad-focusable" for any element you want to be focusable. For Example:
<div class="dpad-focusable" tabindex="0">Example</div>
  • Apply styling in your css for the focus pseudo class.
.grid-item:focus {
        outline: none;
        background-color: rgb(149, 165, 166);
} 

With this, you're ready to support D-Pad navigation.

Events

This library will trigger a regular focus and click event.

element.addEventListener('focus', function(e) {
        console.log('Element Focused');
});

element.addEventListener('click', function() {
        console.log('Element Clicked');
});

Adding and Removing DOM Elements

The library works is that on page load or page resize, it will calculate the graph of where each node's closest neighbors are, based purely on each element's position in the viewport.

What the library does not do, is recalculate the graph if you add or remove elements. To update the graph when elements are added or removed from the DOM call update() like so:

window.dpad.update();

Tabindex and Browser Focus

With the tabindex property, you can determine the order of which view is focused when the user presses the tab key. This library ignores the tabindex order but requires it to ensure the browser allows an element to gain focus.

Debugging

If you add the debug library to your web page you can toggle debug mode like so:

window.dpaddebug.toggleDebugMode();

alt text

Keywords

gauntface

FAQs

Package last updated on 08 Jun 2020

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