diff --git a/packages/progress/index.vue b/packages/progress/index.vue index 5900e1f76..2b6a2a2e2 100644 --- a/packages/progress/index.vue +++ b/packages/progress/index.vue @@ -1,7 +1,7 @@ @@ -40,24 +40,52 @@ export default create({ } }, + data() { + return { + pivotWidth: 0, + progressWidth: 0 + }; + }, + computed: { - componentColor() { + currentColor() { return this.inactive ? '#cacaca' : this.color; }, pivotStyle() { return { color: this.textColor, - background: this.pivotColor || this.componentColor + background: this.pivotColor || this.currentColor }; }, portionStyle() { return { - width: this.percentage + '%', - background: this.componentColor + width: (this.progressWidth - this.pivotWidth) * this.percentage / 100 + 'px', + background: this.currentColor }; } + }, + + mounted() { + this.getWidth(); + }, + + watch: { + showPivot() { + this.getWidth(); + }, + + pivotText() { + this.getWidth(); + } + }, + + methods: { + getWidth() { + this.progressWidth = this.$el.offsetWidth; + this.pivotWidth = this.$refs.pivot ? this.$refs.pivot.offsetWidth : 0; + } } }); diff --git a/packages/progress/test/__snapshots__/demo.spec.js.snap b/packages/progress/test/__snapshots__/demo.spec.js.snap index 66029b4e7..f5170e156 100644 --- a/packages/progress/test/__snapshots__/demo.spec.js.snap +++ b/packages/progress/test/__snapshots__/demo.spec.js.snap @@ -3,19 +3,19 @@ exports[`renders demo correctly 1`] = `
-
50% +
50%
-
50% +
50%
-
橙色 +
橙色
-
红色 +
红色
-
紫色 +
紫色
diff --git a/packages/progress/test/__snapshots__/index.spec.js.snap b/packages/progress/test/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..df4bd5a17 --- /dev/null +++ b/packages/progress/test/__snapshots__/index.spec.js.snap @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`calc width 1`] = `
`; + +exports[`calc width 2`] = ` +
test +
+`; diff --git a/packages/progress/test/index.spec.js b/packages/progress/test/index.spec.js new file mode 100644 index 000000000..aae9d7ffa --- /dev/null +++ b/packages/progress/test/index.spec.js @@ -0,0 +1,16 @@ +import Progress from '../'; +import { mount } from '@vue/test-utils'; + +test('calc width', () => { + const wrapper = mount(Progress, { + propsData: { + showPivot: false, + percentage: 100 + } + }); + expect(wrapper.html()).toMatchSnapshot(); + + wrapper.vm.showPivot = true; + wrapper.vm.pivotText = 'test'; + expect(wrapper.html()).toMatchSnapshot(); +}); diff --git a/packages/vant-css/src/progress.css b/packages/vant-css/src/progress.css index 20e24f36b..6f63dae65 100644 --- a/packages/vant-css/src/progress.css +++ b/packages/vant-css/src/progress.css @@ -11,6 +11,11 @@ height: 100%; position: absolute; border-radius: inherit; + + &--with-pivot { + border-top-right-radius: 0; + border-bottom-right-radius: 0; + } } &__pivot { @@ -26,6 +31,6 @@ word-break: keep-all; box-sizing: border-box; background-color: $gray-light; - transform: translate(50%, -50%); + transform: translate(100%, -50%); } }