@polymer/iron-a11y-keys-behavior
Advanced tools
Comparing version 3.0.0-pre.21 to 3.0.0-pre.22
/** | ||
@license | ||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
This code may only be used under the BSD style license found at | ||
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at | ||
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be | ||
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as | ||
part of the polymer project is also subject to an additional IP rights grant | ||
found at http://polymer.github.io/PATENTS.txt | ||
*/ | ||
import '@polymer/polymer/polymer-legacy.js'; | ||
import { IronA11yKeysBehavior } from '../iron-a11y-keys-behavior.js'; | ||
import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js'; | ||
import { html } from '@polymer/polymer/lib/utils/html-tag.js'; | ||
import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js'; | ||
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; | ||
import {IronA11yKeysBehavior} from '../iron-a11y-keys-behavior.js'; | ||
Polymer({ | ||
@@ -16,0 +19,0 @@ _template: html` |
/** | ||
@license | ||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
This code may only be used under the BSD style license found at | ||
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at | ||
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be | ||
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as | ||
part of the polymer project is also subject to an additional IP rights grant | ||
found at http://polymer.github.io/PATENTS.txt | ||
*/ | ||
@@ -10,0 +11,0 @@ import '@polymer/polymer/polymer-legacy.js'; |
@@ -17,24 +17,16 @@ { | ||
"devDependencies": { | ||
"@polymer/gen-typescript-declarations": "^1.2.2", | ||
"bower": "^1.8.0", | ||
"webmat": "^0.2.0", | ||
"@polymer/iron-demo-helpers": "^3.0.0-pre.21", | ||
"@polymer/iron-component-page": "^3.0.0-pre.21", | ||
"@polymer/iron-test-helpers": "^3.0.0-pre.21", | ||
"@polymer/test-fixture": "^3.0.0-pre.21", | ||
"@polymer/iron-demo-helpers": "^3.0.0-pre.20", | ||
"@polymer/iron-test-helpers": "^3.0.0-pre.20", | ||
"@polymer/test-fixture": "^3.0.0-pre.20", | ||
"wct-browser-legacy": "^1.0.1", | ||
"@webcomponents/webcomponentsjs": "^2.0.0" | ||
"@webcomponents/webcomponentsjs": "^2.0.0", | ||
"@polymer/gen-typescript-declarations": "^1.5.0" | ||
}, | ||
"scripts": { | ||
"update-types": "bower install && gen-typescript-declarations --deleteExisting --outDir .", | ||
"format": "webmat && npm run update-types" | ||
"format": "webmat", | ||
"generate-types": "gen-typescript-declarations --deleteExisting --outDir .", | ||
"prepack": "npm run generate-types" | ||
}, | ||
"version": "3.0.0-pre.21", | ||
"resolutions": { | ||
"inherits": "2.0.3", | ||
"samsam": "1.1.3", | ||
"supports-color": "3.1.2", | ||
"type-detect": "1.0.0", | ||
"@webcomponents/webcomponentsjs": "2.0.0-beta.2" | ||
}, | ||
"version": "3.0.0-pre.22", | ||
"main": "iron-a11y-keys-behavior.js", | ||
@@ -41,0 +33,0 @@ "author": "The Polymer Authors", |
@@ -1,9 +0,6 @@ | ||
[![Published on NPM](https://img.shields.io/npm/v/@polymer/iron-a11y-keys-behavior.svg)](https://www.npmjs.com/package/@polymer/iron-a11y-keys-behavior) | ||
[![Build status](https://travis-ci.org/PolymerElements/iron-a11y-keys-behavior.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-a11y-keys-behavior) | ||
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://webcomponents.org/element/@polymer/iron-a11y-keys-behavior) | ||
_[Demo and API docs](https://elements.polymer-project.org/elements/iron-a11y-keys-behavior)_ | ||
## Polymer.IronA11yKeysBehavior | ||
## <iron-a11y-keys-behavior> | ||
`Polymer.IronA11yKeysBehavior` provides a normalized interface for processing | ||
@@ -14,33 +11,68 @@ keyboard commands that pertain to [WAI-ARIA best practices](http://www.w3.org/TR/wai-aria-practices/#kbd_general_binding). | ||
Use the `keyBindings` prototype property to express what combination of keys | ||
will trigger the callback. A key binding has the format | ||
`"KEY+MODIFIER:EVENT": "callback"` (`"KEY": "callback"` or | ||
`"KEY:EVENT": "callback"` are valid as well). Some examples: | ||
See: [Documentation](https://www.webcomponents.org/element/@polymer/iron-a11y-keys-behavior), | ||
[Demo](https://www.webcomponents.org/element/@polymer/iron-a11y-keys-behavior/demo/demo/index.html). | ||
```javascript | ||
keyBindings: { | ||
'space': '_onKeydown', // same as 'space:keydown' | ||
'shift+tab': '_onKeydown', | ||
'enter:keypress': '_onKeypress', | ||
'esc:keyup': '_onKeyup' | ||
} | ||
## Usage | ||
### Installation | ||
``` | ||
npm install --save @polymer/iron-a11y-keys-behavior | ||
``` | ||
The callback will receive with an event containing the following information in `event.detail`: | ||
### In a Polymer 3 element | ||
```js | ||
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'; | ||
```javascript | ||
_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 | ||
} | ||
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); | ||
``` | ||
Use the `keyEventTarget` attribute to set up event handlers on a specific | ||
node. | ||
## Contributing | ||
If you want to send a PR to this element, here are | ||
the instructions for running the tests and demo locally: | ||
See the [demo source code](https://github.com/PolymerElements/iron-a11y-keys-behavior/blob/master/demo/x-key-aware.html) | ||
for an example. | ||
### Installation | ||
```sh | ||
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 | ||
```sh | ||
polymer serve --npm | ||
open http://127.0.0.1:<port>/demo/ | ||
``` | ||
### Running the tests | ||
```sh | ||
polymer test --npm | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
634
78
29303
8
1