Giter Club home page Giter Club logo

makeup-navigation-emitter's Introduction

makeup-navigation-emitter

Build Status Coverage Status Dependency status devDependency status

A vanilla JavaScript port of jquery-linear-navigation.

Emits custom events based on keyboard navigation of one or two dimensional model.

Experimental

This module is still in an experimental state, until it reaches v1.0.0 you must consider all minor releases as breaking changes. Patch releases may introduce new features, but will be backwards compatible.

Install

// via npm
npm install makeup-navigation-emitter

// via yarn
yarn add makeup-navigation-emitter

Example 1

Example support for a roving tabindex model of keyboard navigation.

Note that this module will not change focus, that is the job of an observer such as makeup-roving-tabindex.

<div class="widget">
    <ul>
        <li tabindex="0">Item 0</li>
        <li>Item 1</li>
        <li>Item 2</li>
    </ul>
</div>
const NavigationEmitter = require('makeup-navigation-emitter');

const widgetEl = document.querySelector('.widget');

var emitter = NavigationEmitter.createLinear(widgetEl, 'li'));

widgetEl.addEventListener('navigationModelChange', function(e) {
    console.log(e.detail.fromIndex, e.detail.toIndex);
});

Example 2

Example support for an active descendant model of navigation with focus on ancestor of items.

Note that this module will not highlight the active item, that is the job of an observer such as makeup-active-descendant.

<div class="widget" tabindex="0">
    <ul>
        <li>Item 0</li>
        <li>Item 1</li>
        <li>Item 2</li>
    </ul>
</div>
const NavigationEmitter = require('makeup-navigation-emitter');

const widgetEl = document.querySelector('.widget');

var emitter = NavigationEmitter.createLinear(widgetEl, 'li', { autoInit: -1, autoReset: -1 }));

widgetEl.addEventListener('navigationModelChange', function(e) {
    console.log(e.detail.fromIndex, e.detail.toIndex);
});

Example 3

Example support for an active descendant model of navigation with focus on non-ancestor of items.

Note that this module will not highlight the active item, that is the job of an observer such as makeup-active-descendant.

<div class="widget">
    <input type="text" />
    <ul>
        <li>Item 0</li>
        <li>Item 1</li>
        <li>Item 2</li>
    </ul>
</div>
const NavigationEmitter = require('makeup-navigation-emitter');

const widgetEl = document.querySelector('.widget');

var emitter = NavigationEmitter.createLinear(widgetEl, 'li', { autoInit: -1, autoReset: -1 }));

widgetEl.addEventListener('navigationModelChange', function(e) {
    console.log(e.detail.fromIndex, e.detail.toIndex);
});

Options

  • autoInit: specify an integer or -1 for initial index (default: 0)
  • autoReset: specify an integer or -1 for index position when focus exits widget (default: null)
  • wrap : specify whether arrow keys should wrap/loop (default: false)

Events

  • navigationModelInit - fired when the model is auto initialised
  • navigationModelChange - fired when the index is set by any means other than auto init or auto reset
  • navigationModelReset - fired when the model is auto reset

For all 3 events, the event detail object contains the fromIndex and toIndex.

Dependencies

Development

  • npm start
  • npm test
  • npm run lint
  • npm run fix
  • npm run build
  • npm run clean

The following hooks exist, and do not need to be invoked manually:

  • npm prepublishOnly cleans, lints, tests and builds on every npm publish command
  • pre-commit cleans, lints, tests and builds on every git commit command

Test Reports

Each test run will generate the following reports:

  • /reports/coverage contains Istanbul code coverage report
  • /reports/html contains HTML test report

CI Build

https://travis-ci.org/makeup-js/makeup-navigation-emitter

Code Coverage

https://coveralls.io/github/makeup-js/makeup-navigation-emitter

makeup-navigation-emitter's People

Contributors

ianmcburnie avatar

Watchers

James Cloos avatar Dylan Piercey avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.