/flight-focus

A Flight utility to manage component focus. Useful for determining which component should respond to browser events.

Primary LanguageJavaScriptMIT LicenseMIT

flight-focus

A Flight utility to manage component focus. Useful when determining which component should responsd to browser events such as keypress, gestures, etc.

Installation

bower install --save flight-focus

Example

You need to use both the controller and the mixin. It is not possible to have more than one focus controller per page.

var focusController = require('focus-controller/lib/focus_controller');
focusController.attachTo(document);

var aComponentWithFocus = defineComponent(aComponent, withFocus);

function aComponent() {
  this.after('initialize', function () {
    // init key event
    this.on('keydown', this.handleKeydown);
    // request focus
    this.focusRequest();
  });

  this.handleKeydown = function (event) {
    if (this.hasFocus) {
      // do something
    }
  };
}

Development

Development of this component requires Bower, and preferably Karma to be globally installed:

npm install -g bower karma

Then install the Node.js and client-side dependencies by running the following commands in the repo's root directory.

npm install
bower install

To continuously run the tests in Chrome and Firefox during development, just run:

karma start

Contributing to this project

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.