Browse Source

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

* commit 'fed413cdc413f2de06f221d2245b63927b740430':
  REPORT-85956 fix:设置textWidth属性时如果内容超过按钮宽度会溢出
master
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", type: "bi.button",
text: "小于最小宽度的按钮", text: "小于最小宽度的按钮",
width: 50, width: 50,
}, {
type: "bi.button",
text: "一个文字超级超级长的 button, 他比按钮宽度还长。",
textWidth: 500,
width: 100,
}]; }];
return { return {

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

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

Loading…
Cancel
Save