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

Advance to year field when / is pressed #48

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@
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 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