diff --git a/docs/markdown/changelog.en-US.md b/docs/markdown/changelog.en-US.md index e12c39a6f..1a13c38fe 100644 --- a/docs/markdown/changelog.en-US.md +++ b/docs/markdown/changelog.en-US.md @@ -10,7 +10,30 @@ Vant follows [Semantic Versioning 2.0.0](https://semver.org/lang/zh-CN/). - Minor version:released every one to two months, including backwards compatible features. - Major version:including breaking changes and new features. -### [v2.10.11](https://github.com/youzan/vant/compare/v2.10.11-beta.0...v2.10.11) +### [v2.10.12](https://github.com/youzan/vant/compare/v2.10.11...v2.10.12) + +`2020-10-31` + +**Feature** + +- Image: add icon-prefix prop [#7457](https://github.com/youzan/vant/issues/7457) +- Progress: add resize method [#5161](https://github.com/youzan/vant/issues/5161) +- SubmitBar: add button slot [#7458](https://github.com/youzan/vant/issues/7458) + +**style** + +- ActionSheet: keep the cancel button at the bottom [#7401](https://github.com/youzan/vant/issues/7401) +- Popup: adjust round border radius to 16px [#7421](https://github.com/youzan/vant/issues/7421) +- Sidebar: fix long number wrap [#7456](https://github.com/youzan/vant/issues/7456) + +**Bug Fixes** + +- GridItem: should not emit deprecation warning [#7433](https://github.com/youzan/vant/issues/7433) +- Picker: fix rendering failure during animation on safari [#7460](https://github.com/youzan/vant/issues/7460) +- Tabs: incorrect change event in some cases [#7461](https://github.com/youzan/vant/issues/7461) +- Tabs: should keep active value after insert item [#7445](https://github.com/youzan/vant/issues/7445) + +### [v2.10.11](https://github.com/youzan/vant/compare/v2.10.11...v2.10.11) `2020-10-24` diff --git a/docs/markdown/changelog.zh-CN.md b/docs/markdown/changelog.zh-CN.md index 00885d399..fd073c78a 100644 --- a/docs/markdown/changelog.zh-CN.md +++ b/docs/markdown/changelog.zh-CN.md @@ -10,7 +10,30 @@ Vant 遵循 [Semver](https://semver.org/lang/zh-CN/) 语义化版本规范。 - 次版本号:每隔一至二个月发布,包含新特性和较大的功能更新,向下兼容。 - 主版本号:发布时间不定,包含不兼容更新,预计下一个主版本会与 Vue 3.0 同期发布。 -### [v2.10.11](https://github.com/youzan/vant/compare/v2.10.11-beta.0...v2.10.11) +### [v2.10.12](https://github.com/youzan/vant/compare/v2.10.11...v2.10.12) + +`2020-10-31` + +**Feature** + +- Image: 新增 icon-prefix 属性 [#7457](https://github.com/youzan/vant/issues/7457) +- Progress: 新增 resize 属性 [#5161](https://github.com/youzan/vant/issues/5161) +- SubmitBar: 新增 button 插槽,用于自定义按钮 [#7458](https://github.com/youzan/vant/issues/7458) + +**style** + +- ActionSheet: 当选项较多时,取消按钮现在会固定在底部 [#7401](https://github.com/youzan/vant/issues/7401) +- Popup: 圆角弹窗的圆角大小从 20px 调整为 16px [#7421](https://github.com/youzan/vant/issues/7421) +- Sidebar: 修复文本为长数字时无法自动换行的问题 [#7456](https://github.com/youzan/vant/issues/7456) + +**Bug Fixes** + +- GridItem: 修复使用 badge 属性时会在控制台抛出 warning 的问题 [#7433](https://github.com/youzan/vant/issues/7433) +- Picker: 修复在 safari 上动画弹出过程中遮罩层闪烁的问题 [#7460](https://github.com/youzan/vant/issues/7460) +- Tabs: 修复在个别情况下错误地抛出 change 事件的问题 [#7461](https://github.com/youzan/vant/issues/7461) +- Tabs: 修复动态插入时 active 值可能错误的问题 [#7445](https://github.com/youzan/vant/issues/7445) + +### [v2.10.11](https://github.com/youzan/vant/compare/v2.10.11...v2.10.11) `2020-10-24` diff --git a/src/image-preview/README.md b/src/image-preview/README.md index 67739b83b..31555a8fc 100644 --- a/src/image-preview/README.md +++ b/src/image-preview/README.md @@ -160,7 +160,7 @@ export default { | closed `v2.5.6` | Triggered after closed | - | | change | Triggered when current image change | index: index of current image | | scale `v2.5.0` | Triggered when current image scale | { index: index of current image, scale: scale of current image} | -| swipeTo `2.9.0` | Swipe to target index | index: target index, options: Options | void | +| swipeTo `2.9.0` | Swipe to target index | index: target index, options: Options | - | ### Slots diff --git a/src/image-preview/README.zh-CN.md b/src/image-preview/README.zh-CN.md index bb4b2a91c..697d51893 100644 --- a/src/image-preview/README.zh-CN.md +++ b/src/image-preview/README.zh-CN.md @@ -201,7 +201,7 @@ export default { | closed `v2.5.6` | 关闭且且动画结束后触发 | - | | change | 切换当前图片时触发 | index: 当前图片的索引 | | scale `v2.5.0` | 缩放当前图片时触发 | { index: 当前图片的索引, scale: 当前缩放的值 } | -| swipeTo `2.9.0` | 切换到指定位置 | index: number, options: Options | void | +| swipeTo `2.9.0` | 切换到指定位置 | index: number, options: Options | - | ### Slots diff --git a/src/image/README.md b/src/image/README.md index e043826e1..6c7e7099f 100644 --- a/src/image/README.md +++ b/src/image/README.md @@ -79,6 +79,7 @@ app.use(Lazyload); | show-loading | Whether to show loading placeholder | _boolean_ | `true` | | error-icon `v2.4.2` | Error icon | _string_ | `photo-fail` | | loading-icon `v2.4.2` | Loading icon | _string_ | `photo` | +| icon-prefix `v2.10.12` | Icon className prefix | _string_ | `van-icon` | ### fit optional value diff --git a/src/image/README.zh-CN.md b/src/image/README.zh-CN.md index 36cd3cc5a..d1f8c7773 100644 --- a/src/image/README.zh-CN.md +++ b/src/image/README.zh-CN.md @@ -111,6 +111,7 @@ app.use(Lazyload); | show-loading | 是否展示图片加载中提示 | _boolean_ | `true` | | error-icon `v2.4.2` | 失败时提示的[图标名称](#/zh-CN/icon)或图片链接 | _string_ | `photo-fail` | | loading-icon `v2.4.2` | 加载时提示的[图标名称](#/zh-CN/icon)或图片链接 | _string_ | `photo` | +| icon-prefix `v2.10.12` | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` | ### 图片填充模式  diff --git a/src/image/index.tsx b/src/image/index.tsx index 2ea55cea9..cd4f8a351 100644 --- a/src/image/index.tsx +++ b/src/image/index.tsx @@ -16,6 +16,7 @@ export default createComponent({ height: [Number, String], radius: [Number, String], lazyLoad: Boolean, + iconPrefix: String, showError: { type: Boolean, default: true, @@ -84,7 +85,13 @@ export default createComponent({ return slots.loading(); } - return ; + return ( + + ); }; const renderErrorIcon = () => { @@ -92,7 +99,13 @@ export default createComponent({ return slots.error(); } - return ; + return ( + + ); }; const renderPlaceholder = () => { diff --git a/src/image/test/__snapshots__/index.legacy.js.snap b/src/image/test/__snapshots__/index.legacy.js.snap index bf6b22e39..6fae403fe 100644 --- a/src/image/test/__snapshots__/index.legacy.js.snap +++ b/src/image/test/__snapshots__/index.legacy.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`apply icon-prefix prop to error-icon 1`] = ` +
+
+
+
+`; + +exports[`apply icon-prefix prop to loading-icon 1`] = ` +
+
+
+
+`; + exports[`default slot 1`] = `
diff --git a/src/image/test/index.legacy.js b/src/image/test/index.legacy.js index 28529a564..6599841d0 100644 --- a/src/image/test/index.legacy.js +++ b/src/image/test/index.legacy.js @@ -147,6 +147,31 @@ test('loading-icon prop', () => { expect(wrapper).toMatchSnapshot(); }); +test('apply icon-prefix prop to error-icon', () => { + const wrapper = mount(VanImage, { + propsData: { + errorIcon: 'error', + iconPrefix: 'my-icon', + src: 'https://img.yzcdn.cn/vant/cat.jpeg', + }, + }); + + wrapper.find('img').trigger('error'); + + expect(wrapper).toMatchSnapshot(); +}); + +test('apply icon-prefix prop to loading-icon', () => { + const wrapper = mount(VanImage, { + propsData: { + loadingIcon: 'success', + iconPrefix: 'my-icon', + }, + }); + + expect(wrapper).toMatchSnapshot(); +}); + test('radius prop', () => { const wrapper = mount(VanImage, { propsData: { diff --git a/src/picker/index.less b/src/picker/index.less index 07d5a172b..2d669864e 100644 --- a/src/picker/index.less +++ b/src/picker/index.less @@ -87,7 +87,8 @@ linear-gradient(0deg, hsla(0, 0%, 100%, 0.9), hsla(0, 0%, 100%, 0.4)); background-repeat: no-repeat; background-position: top, bottom; - backface-visibility: hidden; + // fix rendering failure during animation on safari + transform: translateZ(0); pointer-events: none; } diff --git a/src/progress/README.md b/src/progress/README.md index 362a2486f..628471aba 100644 --- a/src/progress/README.md +++ b/src/progress/README.md @@ -62,3 +62,11 @@ Use `pivot-text` to custom text,use `color` to custom bar color. | text-color | Pivot text color | _string_ | `white` | | inactive | Whether to be gray | _boolean_ | `false` | | show-pivot | Whether to show text | _boolean_ | `true` | + +### Methods + +Use [ref](https://vuejs.org/v2/api/#ref) to get Progress instance and call instance methods. + +| Name | Description | Attribute | Return value | +| --- | --- | --- | --- | +| resize | Resize Progress when container element resized or visibility changed | - | - | diff --git a/src/progress/README.zh-CN.md b/src/progress/README.zh-CN.md index b46f1dade..25b371969 100644 --- a/src/progress/README.zh-CN.md +++ b/src/progress/README.zh-CN.md @@ -70,3 +70,38 @@ app.use(Progress); | text-color | 进度文字颜色 | _string_ | `white` | | inactive | 是否置灰 | _boolean_ | `false` | | show-pivot | 是否显示进度文字 | _boolean_ | `true` | + +### 方法 + +通过 ref 可以获取到 Progress 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。 + +| 方法名 | 说明 | 参数 | 返回值 | +| ------ | -------------------------------------------- | ---- | ------ | +| resize | 外层元素大小变化后,可以调用此方法来触发重绘 | - | - | + +## 常见问题 + +### 组件从隐藏状态切换到显示状态时,渲染不正确? + +Progress 组件在挂载时,会获取自身的宽度,并计算出进度条的样式。如果组件一开始处于隐藏状态,则获取到的宽度永远为 0,因此无法展示正确的进度。 + +#### 解决方法 + +方法一,如果是使用 `v-show` 来控制组件展示的,则替换为 `v-if` 即可解决此问题: + +```html + + + + +``` + +方法二,调用组件的 resize 方法来主动触发重绘: + +```html + +``` + +```js +this.$refs.progress.resize(); +``` diff --git a/src/progress/index.tsx b/src/progress/index.tsx index b7951bce2..a3d781a5e 100644 --- a/src/progress/index.tsx +++ b/src/progress/index.tsx @@ -1,5 +1,6 @@ import { ref, watch, computed, nextTick, reactive, onMounted } from 'vue'; import { createNamespace, addUnit } from '../utils'; +import { useExpose } from '../composition/use-expose'; const [createComponent, bem] = createNamespace('progress'); @@ -36,7 +37,7 @@ export default createComponent({ props.inactive ? '#cacaca' : props.color ); - const setWidth = () => { + const resize = () => { nextTick(() => { state.rootWidth = root.value ? root.value.offsetWidth : 0; state.pivotWidth = pivotRef.value ? pivotRef.value.offsetWidth : 0; @@ -65,9 +66,9 @@ export default createComponent({ } }; - watch([() => props.showPivot, () => props.pivotText], setWidth); - - onMounted(setWidth); + watch([() => props.showPivot, () => props.pivotText], resize); + onMounted(resize); + useExpose({ resize }); return () => { const { trackColor, percentage, strokeWidth } = props; diff --git a/src/sidebar-item/index.less b/src/sidebar-item/index.less index 39d075c6c..29e10311b 100644 --- a/src/sidebar-item/index.less +++ b/src/sidebar-item/index.less @@ -9,7 +9,6 @@ color: @sidebar-text-color; font-size: @sidebar-font-size; line-height: @sidebar-line-height; - word-wrap: break-word; background-color: @sidebar-background-color; cursor: pointer; user-select: none; @@ -22,6 +21,11 @@ border-bottom-width: 1px; } + &__text { + // https://github.com/youzan/vant/issues/7455 + word-break: break-all; + } + &--select { color: @sidebar-selected-text-color; font-weight: @sidebar-selected-font-weight; diff --git a/src/submit-bar/README.md b/src/submit-bar/README.md index f97629e32..d98719c4a 100644 --- a/src/submit-bar/README.md +++ b/src/submit-bar/README.md @@ -61,6 +61,7 @@ Use slot to add custom contents. | Attribute | Description | Type | Default | | --- | --- | --- | --- | | price | Price | _number_ | - | +| decimal-length | Price dicemal length | _number \| string_ | `2` | | label | Price left label | _string_ | `Total:` | | suffix-label | Price right label | _string_ | - | | text-align `v2.3.0` | Price label text align can be set to `left` | _string_ | `right` | @@ -70,7 +71,6 @@ Use slot to add custom contents. | tip | Tip | _string_ | - | | tip-icon | Icon | _string_ | - | | currency | Currency symbol | _string_ | `¥` | -| decimal-length | number of digits to appear after the decimal point | _number \| string_ | `2` | | disabled | Whether to disable button | _boolean_ | `false` | | loading | Whether to show loading icon | _boolean_ | `false` | | safe-area-inset-bottom | Whether to enable bottom safe area adaptation | _boolean_ | `true` | @@ -83,8 +83,9 @@ Use slot to add custom contents. ### Slots -| Name | Description | -| ------- | ------------------- | -| default | Custom left content | -| top | Custom top content | -| tip | Custom tips | +| Name | Description | +| ----------------- | ------------------- | +| default | Custom left content | +| button `v2.10.12` | Custom button | +| top | Custom top content | +| tip | Custom tips | diff --git a/src/submit-bar/README.zh-CN.md b/src/submit-bar/README.zh-CN.md index ad5f30945..104f7c7cf 100644 --- a/src/submit-bar/README.zh-CN.md +++ b/src/submit-bar/README.zh-CN.md @@ -66,18 +66,18 @@ app.use(SubmitBar); | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | price | 价格(单位分) | _number_ | - | +| decimal-length | 价格小数点位数 | _number \| string_ | `2` | | label | 价格左侧文案 | _string_ | `合计:` | | suffix-label | 价格右侧文案 | _string_ | - | | text-align `v2.3.0` | 价格文案对齐方向,可选值为 `left` | _string_ | `right` | | button-text | 按钮文字 | _string_ | - | | button-type | 按钮类型 | _string_ | `danger` | | button-color `v2.9.1` | 自定义按钮颜色 | _string_ | - | -| tip | 提示文案 | _string_ | - | -| tip-icon | 左侧[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - | +| tip | 在订单栏上方的提示文案 | _string_ | - | +| tip-icon | 提示文案左侧的[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - | | currency | 货币符号 | _string_ | `¥` | -| decimal-length | 价格小数点后位数 | _number \| string_ | `2` | | disabled | 是否禁用按钮 | _boolean_ | `false` | -| loading | 是否显示加载中的按钮 | _boolean_ | `false` | +| loading | 是否显示将按钮显示为加载中状态 | _boolean_ | `false` | | safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `true` | ### Events @@ -88,8 +88,9 @@ app.use(SubmitBar); ### Slots -| 名称 | 说明 | -| ------- | -------------------------- | -| default | 自定义订单栏左侧内容 | -| top | 自定义订单栏上方内容 | -| tip | 提示文案中的额外操作和说明 | +| 名称 | 说明 | +| ----------------- | -------------------- | +| default | 自定义订单栏左侧内容 | +| button `v2.10.12` | 自定义按钮 | +| top | 自定义订单栏上方内容 | +| tip | 提示文案中的额外内容 | diff --git a/src/submit-bar/index.js b/src/submit-bar/index.js index 64b6b7baa..9cdf66e67 100644 --- a/src/submit-bar/index.js +++ b/src/submit-bar/index.js @@ -84,18 +84,24 @@ export default createComponent({ emit('submit'); }; - const renderButton = () => ( -
diff --git a/src/submit-bar/test/index.legacy.js b/src/submit-bar/test/index.legacy.js index cc1520611..ce81f1744 100644 --- a/src/submit-bar/test/index.legacy.js +++ b/src/submit-bar/test/index.legacy.js @@ -52,7 +52,7 @@ test('without price', () => { test('top slot', () => { const wrapper = mount(SubmitBar, { scopedSlots: { - top: () => 'top', + top: () => 'Custom Top', }, }); @@ -119,3 +119,14 @@ test('button-color prop', () => { }); expect(wrapper).toMatchSnapshot(); }); + +test('button slot', () => { + const wrapper = mount(SubmitBar, { + buttonText: 'text', + scopedSlots: { + button: () => 'Custom button', + }, + }); + + expect(wrapper).toMatchSnapshot(); +}); diff --git a/src/swipe/README.md b/src/swipe/README.md index 475d08db5..bb48e0e3d 100644 --- a/src/swipe/README.md +++ b/src/swipe/README.md @@ -195,8 +195,8 @@ Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get Swipe | --- | --- | --- | --- | | prev `v2.4.2` | Swipe to prev item | - | - | | next `v2.4.2` | Swipe to next item | - | - | -| swipeTo | Swipe to target index | index: target index, options: Options | void | -| resize | Resize Swipe when container element resized | - | void | +| swipeTo | Swipe to target index | index: target index, options: Options | - | +| resize | Resize Swipe when container element resized or visibility changed | - | - | ### swipeTo Options diff --git a/src/swipe/README.zh-CN.md b/src/swipe/README.zh-CN.md index 46c0f867c..c945199fe 100644 --- a/src/swipe/README.zh-CN.md +++ b/src/swipe/README.zh-CN.md @@ -199,14 +199,14 @@ export default { ### Swipe 方法 -通过 ref 可以获取到 Swipe 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。。 +通过 ref 可以获取到 Swipe 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。 | 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | prev `v2.4.2` | 切换到上一轮播 | - | - | | next `v2.4.2` | 切换到下一轮播 | - | - | -| swipeTo | 切换到指定位置 | index: number, options: Options | void | -| resize | 外层元素大小变化后,可以调用此方法来触发重绘 | - | void | +| swipeTo | 切换到指定位置 | index: number, options: Options | - | +| resize | 外层元素大小或组件显示状态变化时,可以调用此方法来触发重绘 | - | - | ### swipeTo Options 格式 @@ -236,3 +236,28 @@ export default { ### Swipe 组件功能太少,无法实现复杂效果? Vant 中的 Swipe 组件是比较轻量的,因此功能也比较基础。如果需要更复杂的轮播效果,推荐使用社区里一些优质的轮播库,比如 [vue-awesome-swiper](https://github.com/surmon-china/vue-awesome-swiper)。 + +### 组件从隐藏状态切换到显示状态时,无法正确渲染? + +Swipe 组件在挂载时,会获取自身的宽度,并计算出轮播图的位置。如果组件一开始处于隐藏状态,则获取到的宽度永远为 0,因此无法正确计算位置。 + +#### 解决方法 + +方法一,如果是使用 `v-show` 来控制组件展示的,则替换为 `v-if` 即可解决此问题: + +```html + + + + +``` + +方法二,调用组件的 resize 方法来主动触发重绘: + +```html + +``` + +```js +this.$refs.swipe.resize(); +``` diff --git a/src/tab/README.md b/src/tab/README.md index 6b9e0d692..42314e74b 100644 --- a/src/tab/README.md +++ b/src/tab/README.md @@ -270,8 +270,8 @@ Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get Tabs i | Name | Description | Attribute | Return value | | --- | --- | --- | --- | -| resize | Resize Tabs when container element resized | - | void | -| scrollTo `v2.9.3` | Go to specified tab in scrollspy mode | name | void | +| resize | Resize Tabs when container element resized or visibility changed | - | - | +| scrollTo `v2.9.3` | Go to specified tab in scrollspy mode | name | - | ### Tabs Slots diff --git a/src/tab/README.zh-CN.md b/src/tab/README.zh-CN.md index f2a7640a2..3ead4d333 100644 --- a/src/tab/README.zh-CN.md +++ b/src/tab/README.zh-CN.md @@ -277,8 +277,8 @@ export default { | 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | -| resize | 外层元素大小变化后,可以调用此方法来触发重绘 | - | void | -| scrollTo `v2.9.3` | 滚动到指定的标签页,在滚动导航模式下可用 | name: 标识符 | void | +| resize | 外层元素大小或组件显示状态变化时,可以调用此方法来触发重绘 | - | - | +| scrollTo `v2.9.3` | 滚动到指定的标签页,在滚动导航模式下可用 | name: 标识符 | - | ### Tabs Slots @@ -293,3 +293,30 @@ export default { | ------- | ---------- | | default | 标签页内容 | | title | 自定义标题 | + +## 常见问题 + +### 组件从隐藏状态切换到显示状态时,底部条位置错误? + +Tabs 组件在挂载时,会获取自身的宽度,并计算出底部条的位置。如果组件一开始处于隐藏状态,则获取到的宽度永远为 0,因此无法展示底部条位置。 + +#### 解决方法 + +方法一,如果是使用 `v-show` 来控制组件展示的,则替换为 `v-if` 即可解决此问题: + +```html + + + + +``` + +方法二,调用组件的 resize 方法来主动触发重绘: + +```html + +``` + +```js +this.$refs.tabs.resize(); +``` diff --git a/src/tab/test/__snapshots__/index.legacy.js.snap b/src/tab/test/__snapshots__/index.legacy.js.snap index 141db9ee3..8558070bd 100644 --- a/src/tab/test/__snapshots__/index.legacy.js.snap +++ b/src/tab/test/__snapshots__/index.legacy.js.snap @@ -331,10 +331,10 @@ exports[`swipe to switch tab 2`] = `
- - + + -
+
@@ -351,10 +351,10 @@ exports[`swipe to switch tab 3`] = `
- - + + -
+
diff --git a/src/tab/test/index.legacy.js b/src/tab/test/index.legacy.js index 1ca16f2a1..df69e2d2e 100644 --- a/src/tab/test/index.legacy.js +++ b/src/tab/test/index.legacy.js @@ -61,12 +61,17 @@ test('swipe to switch tab', async () => { const onChange = jest.fn(); const wrapper = mount({ template: ` - + Text Text Text `, + data() { + return { + active: 0, + }; + }, methods: { onChange, }, @@ -174,7 +179,7 @@ test('name prop', async () => { const wrapper = mount({ template: ` - + Text Text Text @@ -185,6 +190,11 @@ test('name prop', async () => { onChange, onDisabled, }, + data() { + return { + active: 0, + }; + }, }); await later(); diff --git a/src/tab/test/insert.legacy.js b/src/tab/test/insert.legacy.js index 3c28b4053..3bf617316 100644 --- a/src/tab/test/insert.legacy.js +++ b/src/tab/test/insert.legacy.js @@ -27,9 +27,10 @@ test('insert tab dynamically', async () => { }); test('insert tab with name dynamically', async () => { + const onChange = jest.fn(); const wrapper = mount({ template: ` - + 2 1 @@ -37,14 +38,18 @@ test('insert tab with name dynamically', async () => { data() { return { insert: false, - active: [{ name: 'foo', title: 'foo' }], + active: 'foo', }; }, + methods: { + onChange, + }, }); await later(); wrapper.setData({ insert: true }); expect(wrapper).toMatchSnapshot(); + expect(onChange).toHaveBeenCalledTimes(0); }); // this case will throw wierd error in index.spec.js diff --git a/src/tabs/index.js b/src/tabs/index.js index e6aeca15f..e9aa33450 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -218,15 +218,23 @@ export default createComponent({ }; const setCurrentIndex = (currentIndex) => { - currentIndex = findAvailableTab(currentIndex); + const newIndex = findAvailableTab(currentIndex); - if (isDef(currentIndex) && currentIndex !== state.currentIndex) { - const shouldEmitChange = state.currentIndex !== null; - state.currentIndex = currentIndex; - emit('update:active', currentName.value); + if (!isDef(newIndex)) { + return; + } + + const newTab = children[newIndex]; + const newName = getTabName(newTab, newIndex); + const shouldEmitChange = state.currentIndex !== null; + + state.currentIndex = newIndex; + + if (newName !== props.active) { + emit('update:active', newName); if (shouldEmitChange) { - emit('change', currentName.value, children[currentIndex].title); + emit('change', newName, newTab.title); } } }; @@ -377,9 +385,9 @@ export default createComponent({ watch( () => children.length, () => { - setCurrentIndexByName(props.active || currentName.value); - setLine(); nextTick(() => { + setCurrentIndexByName(props.active || currentName.value); + setLine(); scrollIntoView(true); }); } diff --git a/types/index.d.ts b/types/index.d.ts index b1789db02..35631a6c5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -19,6 +19,7 @@ import { List } from './list'; import { Locale } from './locale'; import { Notify } from './notify'; import { Picker } from './picker'; +import { Progress } from './progress'; import { Sku } from './sku'; import { Swipe } from './swipe'; import { SwipeCell } from './swipe-cell'; @@ -66,7 +67,6 @@ export class Pagination extends VanComponent {} export class Panel extends VanComponent {} export class PasswordInput extends VanComponent {} export class Popup extends VanComponent {} -export class Progress extends VanComponent {} export class PullRefresh extends VanComponent {} export class Radio extends VanComponent {} export class RadioGroup extends VanComponent {} @@ -111,6 +111,7 @@ export { Locale, Notify, Picker, + Progress, Sku, Swipe, SwipeCell, diff --git a/types/progress.d.ts b/types/progress.d.ts new file mode 100644 index 000000000..e54f734f9 --- /dev/null +++ b/types/progress.d.ts @@ -0,0 +1,5 @@ +import { VanComponent } from './component'; + +export class Progress extends VanComponent { + resize(): void; +}