Do not check the target height when cursor finds no target

Bug: Issue 5812
Change-Id: Iea4913da51314ec635b3b8381fb549ffbc063092
This commit is contained in:
Wyatt Allen
2017-07-17 09:53:16 -07:00
parent f5c1bf60c1
commit e5be3b5454
2 changed files with 13 additions and 4 deletions

View File

@@ -157,19 +157,21 @@
const newIndex = this._getNextindex(delta, opt_condition);
let newTarget = null;
if (newIndex != -1) {
if (newIndex !== -1) {
newTarget = this.stops[newIndex];
}
this.index = newIndex;
this.target = newTarget;
if (!this.target) { return; }
if (opt_getTargetHeight) {
this._targetHeight = opt_getTargetHeight(newTarget);
} else {
this._targetHeight = newTarget.scrollHeight;
}
this.index = newIndex;
this.target = newTarget;
if (this.focusOnMove) { this.target.focus(); }
this._decorateTarget();

View File

@@ -143,6 +143,13 @@ limitations under the License.
assert.isTrue(getTargetHeight.called);
});
test('_moveCursor from -1 does not check height', () => {
element.stops = list.querySelectorAll('li');
const getTargetHeight = sinon.stub();
element._moveCursor(1, () => false, getTargetHeight);
assert.isFalse(getTargetHeight.called);
});
test('opt_noScroll', () => {
sandbox.stub(element, '_targetIsVisible', () => false);
const scrollStub = sandbox.stub(window, 'scrollTo');