Răsfoiți Sursa

Form: fix label style (#14969)

hetech 6 ani în urmă
părinte
comite
7b24f82586

+ 1 - 0
packages/form/src/form.vue

@@ -56,6 +56,7 @@
     },
     },
     computed: {
     computed: {
       autoLabelWidth() {
       autoLabelWidth() {
+        if (!this.potentialLabelWidthArr.length) return 0;
         const max = Math.max(...this.potentialLabelWidthArr);
         const max = Math.max(...this.potentialLabelWidthArr);
         return max ? `${max}px` : '';
         return max ? `${max}px` : '';
       }
       }

+ 7 - 5
packages/form/src/label-wrap.vue

@@ -15,7 +15,10 @@ export default {
       const autoLabelWidth = this.elForm.autoLabelWidth;
       const autoLabelWidth = this.elForm.autoLabelWidth;
       const style = {};
       const style = {};
       if (autoLabelWidth && autoLabelWidth !== 'auto') {
       if (autoLabelWidth && autoLabelWidth !== 'auto') {
-        style.width = autoLabelWidth;
+        const marginLeft = parseInt(autoLabelWidth, 10) - this.computedWidth;
+        if (marginLeft) {
+          style.marginLeft = marginLeft + 'px';
+        }
       }
       }
       return (<div class="el-form-item__label-wrap" style={style}>
       return (<div class="el-form-item__label-wrap" style={style}>
         { slots }
         { slots }
@@ -64,10 +67,9 @@ export default {
     this.updateLabelWidth('update');
     this.updateLabelWidth('update');
   },
   },
 
 
-  // Is this necessary?
-  // updated() {
-  //   this.updateLabelWidth('update');
-  // },
+  updated() {
+    this.updateLabelWidth('update');
+  },
 
 
   beforeDestroy() {
   beforeDestroy() {
     this.updateLabelWidth('remove');
     this.updateLabelWidth('remove');

+ 0 - 1
packages/theme-chalk/src/form.scss

@@ -86,7 +86,6 @@
 
 
   @include e(label-wrap) {
   @include e(label-wrap) {
     float: left;
     float: left;
-    text-align: right;
     .el-form-item__label {
     .el-form-item__label {
       display: inline-block;
       display: inline-block;
       float: none;
       float: none;