Browse Source

Merge pull request #210378 in DEC/fineui from master to feature/x

* commit 'fed413cdc413f2de06f221d2245b63927b740430':
  REPORT-85956 fix:设置textWidth属性时如果内容超过按钮宽度会溢出
research/test
superman 2 years ago
parent
commit
437972b3e9
  1. 5
      demo/js/base/button/demo.button.js
  2. 18
      src/base/single/button/buttons/button.js

5
demo/js/base/button/demo.button.js

@ -385,6 +385,11 @@ Demo.Button = BI.inherit(BI.Widget, {
type: "bi.button",
text: "小于最小宽度的按钮",
width: 50,
}, {
type: "bi.button",
text: "一个文字超级超级长的 button, 他比按钮宽度还长。",
textWidth: 500,
width: 100,
}];
return {

18
src/base/single/button/buttons/button.js

@ -81,7 +81,7 @@
},
hgap: o.hgap,
vgap: o.vgap,
items: self.generateItems()
items: self.generateItems(),
});
// 如果 options 对应的属性为 true 则给元素添加 class
@ -102,7 +102,7 @@
// 由于button默认情况下有个边框,所以要主动算行高
var lineHeight, textHeight = o.textHeight;
var hasBorder = false
var hasBorder = false;
if (BI.isNumber(o.height)) {
if (!isVertical(o.iconPosition)) {
if (!(o.clear && o.block && o.light)) {
@ -121,12 +121,12 @@
var iconInvisible = !(o.loading || o.iconCls || o.icon || defaultRenderIcon);
var textWidth = o.textWidth;
if (BI.isNull(o.textWidth)) {
textWidth = (o.minWidth > 0 && o.width < o.minWidth) ? o.minWidth : o.width;
textWidth -= (o.hgap * 2 + o.iconGap)
textWidth -= iconInvisible || isVertical(o.iconPosition) ? 0 : this._const.iconWidth
}
var maxTextWidth = Math.max(o.minWidth, o.width);
maxTextWidth -= (o.hgap * 2 + o.iconGap);
// 减去图标水平占位宽度
maxTextWidth -= iconInvisible || isVertical(o.iconPosition) ? 0 : this._const.iconWidth;
var textWidth = BI.isNull(o.textWidth) ? maxTextWidth : Math.min(o.textWidth, maxTextWidth);
this.text = BI.createWidget({
type: "bi.label",
text: o.text,
@ -140,7 +140,7 @@
});
if (iconInvisible) {
return [this.text]
return [this.text];
}
this._iconRendered = true;

Loading…
Cancel
Save