Fix issue where dropdown position is incorrect with page scroll
gr-textarea did not take into account scroll position when positioning the emoji dropdown. This fixes it by adding scrollTop to non-fixed position textareas. Change-Id: I490d03443b4ca910602ab0636f3dfc19957fdd89
This commit is contained in:
@@ -206,6 +206,10 @@
|
||||
10);
|
||||
},
|
||||
|
||||
_getScrollTop() {
|
||||
return document.body.scrollTop;
|
||||
},
|
||||
|
||||
/**
|
||||
* This positions the dropdown to be just below the cursor position. It is
|
||||
* calculated by having a hidden element with the same width and styling of
|
||||
@@ -219,7 +223,12 @@
|
||||
const caratPosition = this._getPositionOfCursor();
|
||||
const fontSize = this._getFontSize();
|
||||
|
||||
const top = caratPosition.top + fontSize + VERTICAL_OFFSET + 'px';
|
||||
let top = caratPosition.top + fontSize + VERTICAL_OFFSET;
|
||||
|
||||
if (!this.fixedPositionDropdown) {
|
||||
top += this._getScrollTop();
|
||||
}
|
||||
top += 'px';
|
||||
const left = caratPosition.left + 'px';
|
||||
this.$.emojiSuggestions.setPosition(top, left);
|
||||
},
|
||||
|
@@ -181,9 +181,12 @@ limitations under the License.
|
||||
sandbox.stub(element, '_getPositionOfCursor', () => {
|
||||
return {top: 100, left: 30};
|
||||
});
|
||||
sandbox.stub(element, '_getFontSize', () => {
|
||||
return 12;
|
||||
});
|
||||
sandbox.stub(element, '_getFontSize', () => 12);
|
||||
sandbox.stub(element, '_getScrollTop', () => 100);
|
||||
element._updateSelectorPosition();
|
||||
assert.isTrue(setPositionSpy.lastCall.calledWithExactly('219px', '30px'));
|
||||
|
||||
element.fixedPositionDropdown = true;
|
||||
element._updateSelectorPosition();
|
||||
assert.isTrue(setPositionSpy.lastCall.calledWithExactly('119px', '30px'));
|
||||
});
|
||||
|
Reference in New Issue
Block a user