From 02142972cfa45e45053af3a2e68c654b59b95716 Mon Sep 17 00:00:00 2001 From: treecat Date: Thu, 23 Jun 2022 14:07:18 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-74080=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=9B=BE=E6=A0=87=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=B1=85=E4=B8=AD=EF=BC=8C=E8=B0=83=E6=95=B4=E4=BA=86=E6=92=91?= =?UTF-8?q?=E5=BC=80=E7=9A=84=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/base/button/demo.button.js | 11 +++++++++++ src/base/single/button/buttons/button.js | 24 ++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/demo/js/base/button/demo.button.js b/demo/js/base/button/demo.button.js index 056564c9f..110431afb 100644 --- a/demo/js/base/button/demo.button.js +++ b/demo/js/base/button/demo.button.js @@ -256,6 +256,17 @@ Demo.Button = BI.inherit(BI.Widget, { iconGap: 24, iconPosition: "top" } + },{ + el: { + type: "bi.button", + text: "自动撑开高度", + iconCls: "close-font", + textHeight: 32, + iconGap: 24, + vgap: 16, + hgap: 100, + iconPosition: "top" + } }, { el: { type: "bi.button", diff --git a/src/base/single/button/buttons/button.js b/src/base/single/button/buttons/button.js index 39a116c77..d7f875b8f 100644 --- a/src/base/single/button/buttons/button.js +++ b/src/base/single/button/buttons/button.js @@ -14,20 +14,29 @@ BI.Button = BI.inherit(BI.BasicButton, { _const: { - iconWidth: 16 + iconWidth: 18 }, _defaultConfig: function (props) { var conf = BI.Button.superclass._defaultConfig.apply(this, arguments); + var adaptiveHeight = 0; + if (isVertical(props.iconPosition)) { + // 图标高度和文字高度默认相等 + adaptiveHeight += (props.textHeight || 16) * 2; + adaptiveHeight += props.iconGap || 4; + var tGap = props.tgap || props.vgap || 2; + var bGap = props.bgap || props.vgap || 2; + adaptiveHeight += (tGap + bGap); + } + return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-button" + ((BI.isIE() && BI.isIE9Below()) ? " hack" : ""), attributes: { tabIndex: 1 }, minWidth: (props.block === true || props.clear === true) ? 0 : 80, - // 44 = 垂直间距 6 + 边框 2 + 图标 16 + 图标和文字间隔 8 + 文字 12 - height: isVertical(props.iconPosition) ? 44 + ((props.iconGap || 8) - 8) : 24, + height: isVertical(props.iconPosition) ? adaptiveHeight : 24, shadow: props.clear !== true, isShadowShowingOnSelected: true, readonly: true, @@ -49,7 +58,7 @@ bgap: 0, lgap: 0, rgap: 0, - iconGap: 8, + iconGap: 4, iconPosition: "left" }); }, @@ -81,7 +90,10 @@ cls: o.iconCls, width: this._const.iconWidth, height: lineHeight, - lineHeight: lineHeight + lineHeight: lineHeight, + // 不设置,自定义按钮无法居中 + iconWidth: o.iconWidth, + iconHeight: o.iconHeight }); this.text = BI.createWidget({ type: "bi.label", @@ -197,7 +209,7 @@ setIcon: function (cls) { var o = this.options; - if(this.icon && o.iconCls !== cls) { + if (this.icon && o.iconCls !== cls) { this.icon.element.removeClass(o.iconCls).addClass(cls); o.iconCls = cls; }