title2
diff --git a/packages/tab/test/index.spec.js b/packages/tab/test/index.spec.js
index 45bca7f33..ad8c8273c 100644
--- a/packages/tab/test/index.spec.js
+++ b/packages/tab/test/index.spec.js
@@ -129,10 +129,10 @@ test('render nav-left & nav-right slot', async () => {
});
test('border props', async () => {
- const wrapper = mount({
- template: `
-
- `,
+ const wrapper = mount(Tabs, {
+ propsData: {
+ border: false
+ }
});
expect(wrapper).toMatchSnapshot();
diff --git a/packages/tab/zh-CN.md b/packages/tab/zh-CN.md
index e359785b6..7aff1c32e 100644
--- a/packages/tab/zh-CN.md
+++ b/packages/tab/zh-CN.md
@@ -161,8 +161,8 @@ export default {
| type | 样式类型,可选值为`card` | `String` | `line` | - |
| duration | 动画时间,单位秒 | `Number` | `0.3` | - |
| background | 标签栏背景色 | `String` | `white` | 1.6.5 |
-| line-width | 底部条宽度,单位 px | `Number` | - | 1.1.1 |
-| line-height | 底部条高度,单位 px | `Number` | 3 | 1.5.0 |
+| line-width | 底部条宽度,默认单位 px | `Number | String` | `auto` | 1.1.1 |
+| line-height | 底部条高度,默认单位 px | `Number | String` | `3px` | 1.5.0 |
| color | 标签主题色 | `String` | `#f44` | 1.2.0 |
| title-active-color | 标题选中态颜色 | `String` | - | 1.6.5 |
| title-inactive-color | 标题默认态颜色 | `String` | - | 1.6.5 |
diff --git a/packages/tabs/index.js b/packages/tabs/index.js
index c60f3714e..0ae47331d 100644
--- a/packages/tabs/index.js
+++ b/packages/tabs/index.js
@@ -1,5 +1,5 @@
-import { use, isDef } from '../utils';
-import { raf } from '../utils/dom/raf';
+import { use, isDef, suffixPx } from '../utils';
+import { scrollLeftTo } from './utils';
import { on, off } from '../utils/dom/event';
import { TouchMixin } from '../mixins/touch';
import { ParentMixin } from '../mixins/relation';
@@ -35,6 +35,8 @@ export default sfc({
offsetTop: Number,
swipeable: Boolean,
background: String,
+ lineWidth: [Number, String],
+ lineHeight: [Number, String],
titleActiveColor: String,
titleInactiveColor: String,
border: {
@@ -49,14 +51,6 @@ export default sfc({
type: Boolean,
default: true
},
- lineWidth: {
- type: Number,
- default: null
- },
- lineHeight: {
- type: Number,
- default: null
- },
active: {
type: [Number, String],
default: 0
@@ -240,12 +234,12 @@ export default sfc({
const tab = tabs[this.curActive];
const { lineWidth, lineHeight } = this;
const width = isDef(lineWidth) ? lineWidth : tab.offsetWidth / 2;
- const left = tab.offsetLeft + (tab.offsetWidth - width) / 2;
+ const left = tab.offsetLeft + tab.offsetWidth / 2;
const lineStyle = {
- width: `${width}px`,
+ width: suffixPx(width),
backgroundColor: this.color,
- transform: `translateX(${left}px)`
+ transform: `translateX(${left}px) translateX(-50%)`
};
if (shouldAnimate) {
@@ -253,7 +247,7 @@ export default sfc({
}
if (isDef(lineHeight)) {
- const height = `${lineHeight}px`;
+ const height = suffixPx(lineHeight);
lineStyle.height = height;
lineStyle.borderRadius = height;
}
@@ -314,29 +308,10 @@ export default sfc({
}
const { nav } = this.$refs;
- const { scrollLeft, offsetWidth: navWidth } = nav;
- const { offsetLeft, offsetWidth: tabWidth } = tabs[this.curActive];
+ const active = tabs[this.curActive];
+ const to = active.offsetLeft - (nav.offsetWidth - active.offsetWidth) / 2;
- this.scrollTo(nav, scrollLeft, offsetLeft - (navWidth - tabWidth) / 2, immediate);
- },
-
- // animate the scrollLeft of nav
- scrollTo(el, from, to, immediate) {
- if (immediate) {
- el.scrollLeft += to - from;
- return;
- }
-
- let count = 0;
- const frames = Math.round((this.duration * 1000) / 16);
- const animate = () => {
- el.scrollLeft += (to - from) / frames;
- /* istanbul ignore next */
- if (++count < frames) {
- raf(animate);
- }
- };
- animate();
+ scrollLeftTo(nav, to, immediate ? 0 : this.duration);
},
// render title slot of child tab
diff --git a/packages/tabs/utils.ts b/packages/tabs/utils.ts
new file mode 100644
index 000000000..2b4e96e99
--- /dev/null
+++ b/packages/tabs/utils.ts
@@ -0,0 +1,17 @@
+import { raf } from '../utils/dom/raf';
+
+export function scrollLeftTo(el: HTMLElement, to: number, duration: number) {
+ let count = 0;
+ const from = el.scrollLeft;
+ const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
+
+ function animate() {
+ el.scrollLeft += (to - from) / frames;
+
+ if (++count < frames) {
+ raf(animate);
+ }
+ }
+
+ animate();
+}
diff --git a/packages/utils/test/index.spec.js b/packages/utils/test/index.spec.js
index 0b8ff6432..0eb331a0a 100644
--- a/packages/utils/test/index.spec.js
+++ b/packages/utils/test/index.spec.js
@@ -93,6 +93,8 @@ test('is-mobile', () => {
test('is-number', () => {
expect(isNumber('1')).toBeTruthy();
+ expect(isNumber('1.2')).toBeTruthy();
+ expect(isNumber('1..2')).toBeFalsy();
expect(isNumber('abc')).toBeFalsy();
expect(isNumber('1b2')).toBeFalsy();
});
diff --git a/packages/utils/validate/number.ts b/packages/utils/validate/number.ts
index cb0f36c65..47fbc44ad 100644
--- a/packages/utils/validate/number.ts
+++ b/packages/utils/validate/number.ts
@@ -1,3 +1,3 @@
export function isNumber(value: string): boolean {
- return /^\d+$/.test(value);
+ return /^\d+(\.\d+)?$/.test(value);
}