Browse Source

Pull request #3270: BI-118849 fix: combo在屏幕边缘,左右位置不够之后的位置调整逻辑

Merge in VISUAL/fineui from ~DAILER/fineui:master to master

* commit '18391d26560b613a471533166790c381a7d427e5':
  BI-118849 fix: combo在屏幕边缘,左右位置不够之后的位置调整逻辑
research/test
Dailer-刘荣歆 2 years ago
parent
commit
0c8d8ed638
  1. 17
      src/core/platform/web/dom.js

17
src/core/platform/web/dom.js

@ -250,12 +250,12 @@
_getLeftAlignPosition: function (combo, popup, extraWidth, container) {
var comboRect = combo.element[0].getBoundingClientRect(),
popupRect = popup.element.bounds(),
popupRect = popup.element[0].getBoundingClientRect(),
viewportRect = document.documentElement.getBoundingClientRect(),
containerRect = container ? container.getBoundingClientRect() : { left: 0 };
var left = comboRect.left - containerRect.left + extraWidth;
if (left + popupRect.width - containerRect.left > viewportRect.width) {
if (comboRect.left + popupRect.width > viewportRect.width) {
left = viewportRect.width - popupRect.width - containerRect.left;
}
return left;
@ -265,12 +265,13 @@
var left = this._getLeftAlignPosition(combo, popup, extraWidth, container);
var dir = "";
// 如果放不下,优先使用RightAlign, 如果RightAlign也放不下, 再使用left=0
if (left < 0) {
var containerRect = container ? container.getBoundingClientRect() : { left: 0 };
if (left + containerRect.left < 0) {
left = this._getRightAlignPosition(combo, popup, extraWidth);
dir = "left";
}
if (left < 0) {
left = 0;
if (left + containerRect.left < 0) {
left = 0 - containerRect.left;
}
return {
left: left,
@ -678,8 +679,8 @@
getComboPosition: function (combo, popup, extraWidth, extraHeight, needAdaptHeight, directions, offsetStyle, positionRelativeElement) {
extraWidth || (extraWidth = 0);
extraHeight || (extraHeight = 0);
var bodyHeight = BI.Widget._renderEngine.createElement("body").bounds().height - extraHeight;
var maxHeight = Math.min(popup.attr("maxHeight") || bodyHeight, bodyHeight);
var viewportBounds = document.documentElement.getBoundingClientRect();
var maxHeight = Math.min(popup.attr("maxHeight") || viewportBounds.height, viewportBounds.height);
popup.resetHeight && popup.resetHeight(maxHeight);
var position = BI.DOM.getComboPositionByDirections(combo, popup, extraWidth, extraHeight, needAdaptHeight, directions || ["bottom", "top", "right", "left"], positionRelativeElement);
switch (offsetStyle) {
@ -703,7 +704,7 @@
break;
}
if (needAdaptHeight === true) {
popup.resetHeight && popup.resetHeight(Math.min(bodyHeight - position.top + (positionRelativeElement ? positionRelativeElement.getBoundingClientRect().top : 0), maxHeight));
popup.resetHeight && popup.resetHeight(Math.min(viewportBounds.height - position.top + (positionRelativeElement ? positionRelativeElement.getBoundingClientRect().top : 0), maxHeight));
}
return position;
},

Loading…
Cancel
Save