From 3397e396dcebb797006f1c4ae8186ea0d422a5f7 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Fri, 6 Mar 2020 13:03:21 +0200 Subject: Further tweaks to ComboBox popup positioning. (#11910) * Further tweaks to ComboBox popup positioning. - Updated a comment and renamed a private method for better clarity. - Blocked unnecessary position updates. - Added a test for #11866 / #11894. --- .../main/java/com/vaadin/client/ui/VComboBox.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'client') diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index 140d8e3ce4..cf06e06b2d 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -902,11 +902,16 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, int comboBoxLeft = VComboBox.this.getAbsoluteLeft(); int comboBoxWidth = VComboBox.this.getOffsetWidth(); - if (hasParentWithUnadjustedPositioning()) { - // ComboBox itself may be incorrectly positioned, don't adjust - // popup position yet. Width calculations must be performed - // anyway to avoid flickering. - setPopupPosition(left, top); + if (hasParentWithUnadjustedHorizontalPositioning()) { + // ComboBox itself may be incorrectly positioned, don't try to + // adjust horizontal popup position yet. Earlier width + // calculations must be performed anyway to avoid flickering. + if (top != topPosition) { + // Variable 'left' still contains the original popupLeft, + // 'top' has been updated, thus vertical position needs + // adjusting. + setPopupPosition(left, top); + } return; } if (left > comboBoxLeft @@ -929,7 +934,10 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, menu.setWidth(Window.getClientWidth() + "px"); } - setPopupPosition(left, top); + // Only update the position if it has changed. + if (top != topPosition || left != getPopupLeft()) { + setPopupPosition(left, top); + } menu.scrollSelectionIntoView(); } @@ -941,7 +949,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, * @return {@code true} if unadjusted parents found, {@code false} * otherwise */ - private boolean hasParentWithUnadjustedPositioning() { + private boolean hasParentWithUnadjustedHorizontalPositioning() { /* * If there are any VHorizontalLayouts among this VComboBox's * parents, any spacing or expand ratio may cause incorrect -- cgit v1.2.3