GithubHelp home page GithubHelp logo

isabella232 / iron-a11y-keys-behavior Goto Github PK

View Code? Open in Web Editor NEW

This project forked from katapultdevelopment/iron-a11y-keys-behavior

0.0 0.0 0.0 1.63 MB

A behavior that enables keybindings for greater a11y

HTML 51.23% JavaScript 48.77%

iron-a11y-keys-behavior's Introduction

Published on NPM Build status Published on webcomponents.org

<iron-a11y-keys-behavior>

Polymer.IronA11yKeysBehavior provides a normalized interface for processing keyboard commands that pertain to WAI-ARIA best practices. The element takes care of browser differences with respect to Keyboard events and uses an expressive syntax to filter key presses.

See: Documentation, Demo.

Usage

Installation

npm install --save @polymer/iron-a11y-keys-behavior

In a Polymer 3 element

import {PolymerElement, html} from '@polymer/polymer';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
import {IronA11yKeysBehavior} from '@polymer/iron-a11y-keys-behavior/iron-a11y-keys-behavior.js';

class SampleElement extends  extends mixinBehaviors([IronA11yKeysBehavior], PolymerElement) {
  static get template() {
    return html`
      <pre>[[pressed]]</pre>
    `;
  }

  static get properties() {
    return {
      pressed: {type: String, readOnly: true, value: ''},
      keyBindings: {
        'space': '_onKeydown', // same as 'space:keydown'
        'shift+tab': '_onKeydown',
        'enter:keypress': '_onKeypress',
        'esc:keyup': '_onKeyup'
      }
    }
  }

  function _onKeydown: function(event) {
    console.log(event.detail.combo); // KEY+MODIFIER, e.g. "shift+tab"
    console.log(event.detail.key); // KEY only, e.g. "tab"
    console.log(event.detail.event); // EVENT, e.g. "keydown"
    console.log(event.detail.keyboardEvent); // the original KeyboardEvent
  }
}
customElements.define('sample-element', SampleElement);

Contributing

If you want to send a PR to this element, here are the instructions for running the tests and demo locally:

Installation

git clone https://github.com/PolymerElements/iron-a11y-keys-behavior
cd iron-a11y-keys-behavior
npm install
npm install -g polymer-cli

Running the demo locally

polymer serve --npm
open http://127.0.0.1:<port>/demo/

Running the tests

polymer test --npm

iron-a11y-keys-behavior's People

Contributors

addyosmani avatar aomarks avatar bicknellr avatar blasten avatar brendankenny avatar cdata avatar cwayfinder avatar dependabot[bot] avatar dfreedm avatar dschuyler avatar e111077 avatar filaraujo avatar fredj avatar garlicnation avatar jakemac53 avatar jklein24 avatar marcus7778 avatar mgiuffrida avatar notwaldorf avatar pleku avatar rictic avatar robdodson avatar sandeshdamkondwar avatar saulis avatar tedium-bot avatar tjsavage avatar valdrinkoshi 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.