From 8ccee1e58484976a7b7ef6e8c05ac11ff86a1220 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Tue, 3 Nov 2020 20:47:35 +0800 Subject: [PATCH 1/5] docs: fix ContactCard title --- src/contact-card/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contact-card/README.md b/src/contact-card/README.md index cc84a4253..5e2f2ef9a 100644 --- a/src/contact-card/README.md +++ b/src/contact-card/README.md @@ -1,4 +1,4 @@ -# Contact +# ContactCard ### Install From b9a8773a0a27846622f0e675590cb9d9900cb9e6 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 4 Nov 2020 18:16:08 +0800 Subject: [PATCH 2/5] fix(Toast): onClose option should only be called once (#7496) --- src/toast/index.js | 1 + src/toast/test/index.spec.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/toast/index.js b/src/toast/index.js index 514a45202..33a022a54 100644 --- a/src/toast/index.js +++ b/src/toast/index.js @@ -108,6 +108,7 @@ function Toast(options = {}) { if (options.onClose) { options.onClose(); + options.onClose = null; } if (multiple && !isServer) { diff --git a/src/toast/test/index.spec.js b/src/toast/test/index.spec.js index 3026877ef..3b0584969 100644 --- a/src/toast/test/index.spec.js +++ b/src/toast/test/index.spec.js @@ -150,7 +150,7 @@ test('toast duration 0', () => { Toast.allowMultiple(false); }); -test('onClose callback', () => { +test('should trigger onClose callback after closed', () => { Toast.allowMultiple(); const onClose = jest.fn(); const toast = Toast({ @@ -158,6 +158,10 @@ test('onClose callback', () => { onClose, }); + toast.clear(); + expect(onClose).toHaveBeenCalledTimes(1); + + // onClose should only be called once toast.clear(); expect(onClose).toHaveBeenCalledTimes(1); Toast.allowMultiple(false); From ce619c67e231b3bc148a450b4e524939d4d0cacc Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 4 Nov 2020 18:32:35 +0800 Subject: [PATCH 3/5] style(Switch): remove unnecessary z-index (#7497) --- src/style/var.less | 1 - src/switch/index.less | 1 - 2 files changed, 2 deletions(-) diff --git a/src/style/var.less b/src/style/var.less index 1599fe253..92f0481e1 100644 --- a/src/style/var.less +++ b/src/style/var.less @@ -731,7 +731,6 @@ @switch-width: 2em; @switch-height: 1em; @switch-node-size: 1em; -@switch-node-z-index: 1; @switch-node-background-color: @white; @switch-node-box-shadow: 0 3px 1px 0 rgba(0, 0, 0, 0.05), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 3px 3px 0 rgba(0, 0, 0, 0.05); diff --git a/src/switch/index.less b/src/switch/index.less index 8baa7a43a..c0d65d7be 100644 --- a/src/switch/index.less +++ b/src/switch/index.less @@ -17,7 +17,6 @@ position: absolute; top: 0; left: 0; - z-index: @switch-node-z-index; width: @switch-node-size; height: @switch-node-size; background-color: @switch-node-background-color; From ebd78a9d02c24d1de3d7c3d7ef8e681ae00f4cdc Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 4 Nov 2020 19:39:52 +0800 Subject: [PATCH 4/5] feat(Sticky): offset-top support vh unit (#7498) --- src/area/README.md | 2 +- src/area/README.zh-CN.md | 2 +- src/datetime-picker/README.md | 2 +- src/datetime-picker/README.zh-CN.md | 2 +- src/picker/README.md | 2 +- src/picker/README.zh-CN.md | 2 +- src/sticky/README.md | 2 +- src/sticky/README.zh-CN.md | 2 +- src/tab/README.md | 2 +- src/tab/README.zh-CN.md | 2 +- src/utils/format/unit.ts | 9 ++++++++- src/utils/test/index.spec.js | 4 ++++ 12 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/area/README.md b/src/area/README.md index 2a063927f..b4db1c884 100644 --- a/src/area/README.md +++ b/src/area/README.md @@ -65,7 +65,7 @@ To have a selected value,simply pass the `code` of target area to `value` prop | columns-placeholder | Placeholder of columns | _string[]_ | `[]` | | loading | Whether to show loading prompt | _boolean_ | `false` | | readonly `v2.10.5` | Whether to be readonly | _boolean_ | `false` | -| item-height `v2.8.6` | Option height, supports `px` `vw` `rem` unit, default `px` | _number \| string_ | `44` | +| item-height `v2.8.6` | Option height, supports `px` `vw` `vh` `rem` unit, default `px` | _number \| string_ | `44` | | columns-num | Level of picker | _number \| string_ | `3` | | visible-item-count | Count of visible columns | _number \| string_ | `6` | | swipe-duration | Duration of the momentum animation,unit `ms` | _number \| string_ | `1000` | diff --git a/src/area/README.zh-CN.md b/src/area/README.zh-CN.md index b4719c003..8e1cfdec0 100644 --- a/src/area/README.zh-CN.md +++ b/src/area/README.zh-CN.md @@ -65,7 +65,7 @@ Vue.use(Area); | columns-placeholder | 列占位提示文字 | _string[]_ | `[]` | | loading | 是否显示加载状态 | _boolean_ | `false` | | readonly `v2.10.5` | 是否为只读状态,只读状态下无法切换选项 | _boolean_ | `false` | -| item-height `v2.8.6` | 选项高度,支持 `px` `vw` `rem` 单位,默认 `px` | _number \| string_ | `44` | +| item-height `v2.8.6` | 选项高度,支持 `px` `vw` `vh` `rem` 单位,默认 `px` | _number \| string_ | `44` | | columns-num | 显示列数,3-省市区,2-省市,1-省 | _number \| string_ | `3` | | visible-item-count | 可见的选项个数 | _number \| string_ | `6` | | swipe-duration | 快速滑动时惯性滚动的时长,单位`ms` | _number \| string_ | `1000` | diff --git a/src/datetime-picker/README.md b/src/datetime-picker/README.md index 0b2c4e23a..c42961fe5 100644 --- a/src/datetime-picker/README.md +++ b/src/datetime-picker/README.md @@ -260,7 +260,7 @@ export default { | filter | Option filter | _(type, vals) => vals_ | - | | formatter | Option text formatter | _(type, val) => val_ | - | | columns-order `v2.9.2` | Array for ordering columns, where item can be set to
`year`, `month`, `day`, `hour` and `minute` | _string[]_ | - | -| item-height `v2.8.6` | Option height, supports `px` `vw` `rem` unit, default `px` | _number \| string_ | `44` | +| item-height `v2.8.6` | Option height, supports `px` `vw` `vh` `rem` unit, default `px` | _number \| string_ | `44` | | visible-item-count | Count of visible columns | _number \| string_ | `6` | | swipe-duration | Duration of the momentum animation,unit `ms` | _number \| string_ | `1000` | diff --git a/src/datetime-picker/README.zh-CN.md b/src/datetime-picker/README.zh-CN.md index d5c26fff7..dd0a3dfc6 100644 --- a/src/datetime-picker/README.zh-CN.md +++ b/src/datetime-picker/README.zh-CN.md @@ -269,7 +269,7 @@ export default { | filter | 选项过滤函数 | _(type, vals) => vals_ | - | | formatter | 选项格式化函数 | _(type, val) => val_ | - | | columns-order `v2.9.2` | 自定义列排序数组, 子项可选值为
`year`、`month`、`day`、`hour`、`minute` | _string[]_ | - | -| item-height `v2.8.6` | 选项高度,支持 `px` `vw` `rem` 单位,默认 `px` | _number \| string_ | `44` | +| item-height `v2.8.6` | 选项高度,支持 `px` `vw` `vh` `rem` 单位,默认 `px` | _number \| string_ | `44` | | visible-item-count | 可见的选项个数 | _number \| string_ | `6` | | swipe-duration | 快速滑动时惯性滚动的时长,单位`ms` | _number \| string_ | `1000` | diff --git a/src/picker/README.md b/src/picker/README.md index b8609568f..6976f409b 100644 --- a/src/picker/README.md +++ b/src/picker/README.md @@ -253,7 +253,7 @@ export default { | show-toolbar | Whether to show toolbar | _boolean_ | `false` | | allow-html | Whether to allow HTML in option text | _boolean_ | `true` | | default-index | Default value index of single column picker | _number \| string_ | `0` | -| item-height `v2.8.6` | Option height, supports `px` `vw` `rem` unit, default `px` | _number \| string_ | `44` | +| item-height `v2.8.6` | Option height, supports `px` `vw` `vh` `rem` unit, default `px` | _number \| string_ | `44` | | visible-item-count | Count of visible columns | _number \| string_ | `6` | | swipe-duration | Duration of the momentum animation,unit `ms` | _number \| string_ | `1000` | diff --git a/src/picker/README.zh-CN.md b/src/picker/README.zh-CN.md index 0214fbc8e..d90758c68 100644 --- a/src/picker/README.zh-CN.md +++ b/src/picker/README.zh-CN.md @@ -276,7 +276,7 @@ export default { | show-toolbar | 是否显示顶部栏 | _boolean_ | `false` | | allow-html | 是否允许选项内容中渲染 HTML | _boolean_ | `true` | | default-index | 单列选择时,默认选中项的索引 | _number \| string_ | `0` | -| item-height `v2.8.6` | 选项高度,支持 `px` `vw` `rem` 单位,默认 `px` | _number \| string_ | `44` | +| item-height `v2.8.6` | 选项高度,支持 `px` `vw` `vh` `rem` 单位,默认 `px` | _number \| string_ | `44` | | visible-item-count | 可见的选项个数 | _number \| string_ | `6` | | swipe-duration | 快速滑动时惯性滚动的时长,单位 `ms` | _number \| string_ | `1000` | diff --git a/src/sticky/README.md b/src/sticky/README.md index 17ce81ccd..4691e0abb 100644 --- a/src/sticky/README.md +++ b/src/sticky/README.md @@ -56,7 +56,7 @@ export default { | Attribute | Description | Type | Default | | --- | --- | --- | --- | -| offset-top `v2.8.7` | Offset top, supports `px` `vw` `rem` unit, default `px` | _number \| string_ | `0` | +| offset-top `v2.8.7` | Offset top, supports `px` `vw` `vh` `rem` unit, default `px` | _number \| string_ | `0` | | z-index | z-index when sticky | _number \| string_ | `99` | | container | Container DOM | _Element_ | - | diff --git a/src/sticky/README.zh-CN.md b/src/sticky/README.zh-CN.md index 79c9f4467..fe6db1108 100644 --- a/src/sticky/README.zh-CN.md +++ b/src/sticky/README.zh-CN.md @@ -66,7 +66,7 @@ export default { | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | -| offset-top `v2.8.7` | 吸顶时与顶部的距离,支持 `px` `vw` `rem` 单位,默认 `px` | _number \| string_ | `0` | +| offset-top `v2.8.7` | 吸顶时与顶部的距离,支持 `px` `vw` `vh` `rem` 单位,默认 `px` | _number \| string_ | `0` | | z-index | 吸顶时的 z-index | _number \| string_ | `99` | | container | 容器对应的 HTML 节点 | _Element_ | - | diff --git a/src/tab/README.md b/src/tab/README.md index 39ac034de..bcd38d88a 100644 --- a/src/tab/README.md +++ b/src/tab/README.md @@ -233,7 +233,7 @@ export default { | swipeable | Whether to switch tabs with swipe gestrue in the content | _boolean_ | `false` | | lazy-render | Whether to enable tab content lazy render | _boolean_ | `true` | | scrollspy `v2.3.0` | Whether to use scrollspy mode | _boolean_ | `false` | -| offset-top `v2.8.7` | Sticky offset top , supports `px` `vw` `rem` unit, default `px` | _number \| string_ | `0` | +| offset-top `v2.8.7` | Sticky offset top , supports `px` `vw` `vh` `rem` unit, default `px` | _number \| string_ | `0` | | swipe-threshold | Set swipe tabs threshold | _number \| string_ | `5` | - | | title-active-color | Title active color | _string_ | - | | title-inactive-color | Title inactive color | _string_ | - | diff --git a/src/tab/README.zh-CN.md b/src/tab/README.zh-CN.md index 2c228653c..b33490f94 100644 --- a/src/tab/README.zh-CN.md +++ b/src/tab/README.zh-CN.md @@ -240,7 +240,7 @@ export default { | swipeable | 是否开启手势滑动切换 | _boolean_ | `false` | | lazy-render | 是否开启延迟渲染(首次切换到标签时才触发内容渲染) | _boolean_ | `true` | | scrollspy `v2.3.0` | 是否开启滚动导航 | _boolean_ | `false` | -| offset-top `v2.8.7` | 粘性定位布局下与顶部的最小距离,支持 `px` `vw` `rem` 单位,默认 `px` | _number \| string_ | `0` | +| offset-top `v2.8.7` | 粘性定位布局下与顶部的最小距离,支持 `px` `vw` `vh` `rem` 单位,默认 `px` | _number \| string_ | `0` | | swipe-threshold | 滚动阈值,标签数量超过阈值且总宽度超过标签栏宽度时开始横向滚动 | _number \| string_ | `5` | | title-active-color | 标题选中态颜色 | _string_ | - | | title-inactive-color | 标题默认态颜色 | _string_ | - | diff --git a/src/utils/format/unit.ts b/src/utils/format/unit.ts index 9b2de011d..5234870a2 100644 --- a/src/utils/format/unit.ts +++ b/src/utils/format/unit.ts @@ -35,6 +35,11 @@ function convertVw(value: string) { return (+value * window.innerWidth) / 100; } +function convertVh(value: string) { + value = value.replace(/vh/g, ''); + return (+value * window.innerHeight) / 100; +} + export function unitToPx(value: string | number): number { if (typeof value === 'number') { return value; @@ -44,10 +49,12 @@ export function unitToPx(value: string | number): number { if (value.indexOf('rem') !== -1) { return convertRem(value); } - if (value.indexOf('vw') !== -1) { return convertVw(value); } + if (value.indexOf('vh') !== -1) { + return convertVh(value); + } } return parseFloat(value); diff --git a/src/utils/test/index.spec.js b/src/utils/test/index.spec.js index 2dd16e4d4..eb263eaa2 100644 --- a/src/utils/test/index.spec.js +++ b/src/utils/test/index.spec.js @@ -131,6 +131,8 @@ test('addUnit', () => { test('unitToPx', () => { const originGetComputedStyle = window.getComputedStyle; + window.innerWidth = 100; + window.innerHeight = 200; window.getComputedStyle = () => ({ fontSize: '16px' }); expect(unitToPx(0)).toEqual(0); @@ -138,6 +140,8 @@ test('unitToPx', () => { expect(unitToPx('10px')).toEqual(10); expect(unitToPx('0rem')).toEqual(0); expect(unitToPx('10rem')).toEqual(160); + expect(unitToPx('10vw')).toEqual(10); + expect(unitToPx('10vh')).toEqual(20); window.getComputedStyle = originGetComputedStyle; }); From 287a4acea0a72b74c64c4a81499ac7de94141761 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 4 Nov 2020 20:03:38 +0800 Subject: [PATCH 5/5] fix(Picker): move to next option when default option is disabled (#7499) * fix(Picker): should move to next option when defaultOption is disabled * test: update spec name --- src/picker/index.js | 12 +++++-- .../test/__snapshots__/cascade.spec.js.snap | 31 +++++++++++++++++++ src/picker/test/cascade.spec.js | 20 ++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/picker/index.js b/src/picker/index.js index 805a0062f..5b5a379b1 100644 --- a/src/picker/index.js +++ b/src/picker/index.js @@ -86,7 +86,15 @@ export default createComponent({ let cursor = { children: this.columns }; while (cursor && cursor.children) { - const defaultIndex = cursor.defaultIndex ?? +this.defaultIndex; + const { children } = cursor; + let defaultIndex = cursor.defaultIndex ?? +this.defaultIndex; + + while ( + children[defaultIndex].disabled && + defaultIndex < children.length - 1 + ) { + defaultIndex++; + } formatted.push({ values: cursor.children, @@ -94,7 +102,7 @@ export default createComponent({ defaultIndex, }); - cursor = cursor.children[defaultIndex]; + cursor = children[defaultIndex]; } this.formattedColumns = formatted; diff --git a/src/picker/test/__snapshots__/cascade.spec.js.snap b/src/picker/test/__snapshots__/cascade.spec.js.snap index c6decf9d7..09e3c4952 100644 --- a/src/picker/test/__snapshots__/cascade.spec.js.snap +++ b/src/picker/test/__snapshots__/cascade.spec.js.snap @@ -5,3 +5,34 @@ exports[`disabled in cascade 1`] = `
A2
`; + +exports[`should move to next option when default option is disabled 1`] = ` +
+ +
+
+
    +
  • +
    A1
    +
  • +
  • +
    A2
    +
  • +
+
+
+
    +
  • +
    B3
    +
  • +
  • +
    B4
    +
  • +
+
+
+
+
+ +
+`; diff --git a/src/picker/test/cascade.spec.js b/src/picker/test/cascade.spec.js index 02e7cd2da..7fce043eb 100644 --- a/src/picker/test/cascade.spec.js +++ b/src/picker/test/cascade.spec.js @@ -125,3 +125,23 @@ test('disabled in cascade', () => { expect(wrapper.find('.van-picker-column__item--disabled')).toMatchSnapshot(); }); + +test('should move to next option when default option is disabled', () => { + const wrapper = mount(Picker, { + propsData: { + columns: [ + { + text: 'A1', + disabled: true, + children: [{ text: 'B1' }, { text: 'B2' }], + }, + { + text: 'A2', + children: [{ text: 'B3' }, { text: 'B4' }], + }, + ], + }, + }); + + expect(wrapper).toMatchSnapshot(); +});