Skip to content

Commit

Permalink
Fix regression where Accordion doesn't remember the previously focuse…
Browse files Browse the repository at this point in the history
…d header.

Fixes #679, refs ibm-js/delite#462.
  • Loading branch information
wkeese committed Dec 7, 2016
1 parent 9080840 commit 45dba9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,14 @@ define([
this._lastFocusedDescendant ? this.navigateTo(this._lastFocusedDescendant) : this.navigateToFirst();
},

_keynavDeactivatedHandler: dcl.superCall(function (sup) {
return function () {
this._lastFocusedDescendant = this.navigatedDescendant;
sup.call(this);
focusoutHandler: dcl.superCall(function (sup) {
return function (evt) {
// When focus moves outside of the Accordion, save reference to previously focused child.
if (!this.contains(evt.relatedTarget)) {
this._lastFocusedDescendant = this.navigatedDescendant;
}

sup.apply(this, arguments);
};
})
});
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ define(["intern",
assert.strictEqual(value.replace(panelHeaderStr, ""), "panel3");
});
},
"Remembering position": function () {
// Assumes that we start on panel3.
var remote = this.remote;
if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {
return this.skip("no keyboard support");
}
return remote
.execute("return document.activeElement.getAttribute('id');").then(function (value) {
assert.strictEqual(value.replace(panelHeaderStr, ""), "panel3", "initial position");
})
.pressKeys(keys.TAB)
.pressKeys(keys.SHIFT + keys.TAB)
.pressKeys(keys.SHIFT) // release shift key
.execute("return document.activeElement.getAttribute('id');").then(function (value) {
assert.strictEqual(value.replace(panelHeaderStr, ""), "panel3",
"returned to previously focused");
});
},
"Arrow keys - cyclic": function () {
var remote = this.remote;
if (remote.environmentType.brokenSendKeys || !remote.environmentType.nativeEvents) {
Expand Down

0 comments on commit 45dba9f

Please sign in to comment.