Browse Source

Table: extend height prop usage (#9575)

FuryBean 7 years ago
parent
commit
ab2f3830d6

+ 1 - 1
examples/docs/en-US/table.md

@@ -1948,7 +1948,7 @@ You can customize row index in `type=index` columns.
 | Attribute      | Description          | Type      | Accepted Values       | Default  |
 |---------- |-------------- |---------- |--------------------------------  |-------- |
 | data | Table data | array | — | — |
-| height | Table's height. By default it has an `auto` height. If its value is a number, the height is measured in pixels; if its value is a string, the height is affected by external styles | string/number | — | — |
+| height | Table's height. By default it has an `auto` height. If its value is a number, the height is measured in pixels; if its value is a string, the value will be assigned to element's style.height, the height is affected by external styles | string/number | — | — |
 | max-height | Table's max-height. The height of the table starts from `auto` until it reaches the maxHeight limit. The `maxHeight` is measured in pixels, same as `height` | string/number | — | — |
 | stripe | whether Table is striped | boolean | — | false |
 | border | whether Table has vertical border | boolean | — | false |

+ 1 - 1
examples/docs/zh-CN/table.md

@@ -2008,7 +2008,7 @@
 | 参数      | 说明          | 类型      | 可选值                           | 默认值  |
 |---------- |-------------- |---------- |--------------------------------  |-------- |
 | data | 显示的数据 | array | — | — |
-| height | Table 的高度,默认为自动高度。如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则 Table 的高度受控于外部样式。  | string/number | — | — |
+| height | Table 的高度,默认为自动高度。如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则这个高度会设置为 Table 的 style.height 的值,Table 的高度受控于外部样式。  | string/number | — | — |
 | max-height | Table 的最大高度 | string/number | — | — |
 | stripe | 是否为斑马纹 table | boolean | — | false |
 | border | 是否带有纵向边框 | boolean | — | false |

+ 1 - 3
packages/table/src/table-layout.js

@@ -63,9 +63,7 @@ class TableLayout {
 
       this.updateElsHeight();
     } else if (typeof value === 'string') {
-      if (value === '') {
-        el.style[prop] = '';
-      }
+      el.style[prop] = value;
       this.updateElsHeight();
     }
   }

+ 9 - 0
test/unit/specs/table.spec.js

@@ -90,6 +90,15 @@ describe('Table', () => {
       }, DELAY);
     });
 
+    it('height as string', done => {
+      const vm = createTable('height="100pt"');
+      setTimeout(_ => {
+        expect(vm.$el.style.height).to.equal('100pt');
+        destroyVM(vm);
+        done();
+      }, DELAY);
+    });
+
     it('maxHeight', done => {
       const vm = createTable('max-height="134"');
       setTimeout(_ => {