Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Advance to year field on / key press
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelli committed Apr 25, 2016
1 parent 3e6cb12 commit 01a7af2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"homepage": "https://github.com/PolymerElements/gold-cc-expiration-input",
"ignore": [],
"dependencies": {
"iron-a11y-keys-behavior": "PolymerElements/iron-a11y-keys-behavior#^1.1.2",
"iron-validator-behavior": "PolymerElements/iron-validator-behavior#^1.0.0",
"iron-validatable-behavior": "PolymerElements/iron-validatable-behavior#^1.0.0",
"iron-flex-layout": "PolymerElements/iron-flex-layout#^1.0.0",
Expand Down
10 changes: 10 additions & 0 deletions date-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
<link rel="import" href="../iron-input/iron-input.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-validatable-behavior/iron-validatable-behavior.html">
Expand Down Expand Up @@ -96,6 +97,7 @@
is: 'date-input',

behaviors: [
Polymer.IronA11yKeysBehavior,
Polymer.IronValidatableBehavior
],

Expand Down Expand Up @@ -170,10 +172,18 @@
}
},

keyBindings: {
'/': '_selectYear'
},

observers: [
'_computeDate(month,year)'
],

_selectYear: function() {
this.$.expirationYear.focus();
},

_computeDate: function(month, year) {
// Months are 0-11.
this.date = {month: month, year: year};
Expand Down
10 changes: 10 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@
assert.equal(year.placeholder, 'YY', 'year placeholder is YY');
});

test('/ key advances to year input', function() {
var input = fixture('basic');
forceXIfStamp(input);
var dateInput = Polymer.dom(input.root).querySelector('date-input');
var month = Polymer.dom(dateInput.root).querySelector('#expirationMonth');
var year = Polymer.dom(dateInput.root).querySelector('#expirationYear');
MockInteractions.pressAndReleaseKeyOn(dateInput, 191, [], '/');
assert.equal(Polymer.dom(dateInput.root).activeElement, year, 'year is focused');
});

});

suite('a11y', function() {
Expand Down

0 comments on commit 01a7af2

Please sign in to comment.