Skip to content

Commit

Permalink
Fix #1266: Keyboard: Fix focus preservation edge case
Browse files Browse the repository at this point in the history
(cherry picked from commit e7f4251)
  • Loading branch information
Kenneth G. Franqueiro committed Apr 1, 2016
1 parent f9cf1c4 commit 562949e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ define([
this._focusOnNode(node, false);
}
else {
if (this._removedFocus) {
this._removedFocus.active = true;
}
this.contentNode.focus();
}
}
Expand Down
31 changes: 28 additions & 3 deletions test/intern/mixins/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ define([
handles[i].remove && handles[i].remove();
}
handles = [];

// Restore item that was removed for focus retention test
testStore.put(item);
}

function after() {
// Destroy list or grid
grid.destroy();
// Restore item that was removed for focus retention test
testStore.put(item);
}

// Common test functions for grid w/ cellNavigation: false and list
Expand Down Expand Up @@ -452,7 +453,6 @@ define([
assert.ok(element && element.className && element.className.indexOf('dgrid-cell') > -1,
'focus(id) call focused a cell');

// Focus the button we added to move focus out of the grid
button.focus();

nextElement = grid.cell(2, 'col1').element;
Expand All @@ -468,6 +468,31 @@ define([

return dfd;
});

test.test('grid.focus called in same turn after item removal', function () {
var dfd = this.async(1000),
element,
nextElement;

grid.focus(grid.cell(1, 'col1'));

element = document.activeElement;
assert.ok(element && element.className && element.className.indexOf('dgrid-cell') > -1,
'focus(id) call focused a cell');

button.focus();

nextElement = grid.cell(2, 'col1').element;
grid.collection.remove(1);
grid.focus();

setTimeout(dfd.callback(function () {
assert.strictEqual(nextElement, document.activeElement,
'The next row is focused after removing the item and calling focus on the same turn');
}), 0);

return dfd;
});
});

test.suite('Keyboard (Grid + cellNavigation:false)', function () {
Expand Down

0 comments on commit 562949e

Please sign in to comment.