Merge branch '2.x' into dev

This commit is contained in:
chenjiahan
2020-11-04 20:06:59 +08:00
18 changed files with 88 additions and 16 deletions
+1 -1
View File
@@ -251,7 +251,7 @@ export default {
| show-toolbar | Whether to show toolbar | _boolean_ | `true` |
| allow-html | Whether to allow HTML in option text | _boolean_ | `false` |
| 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 animationunit `ms` | _number \| string_ | `1000` |
+1 -1
View File
@@ -274,7 +274,7 @@ export default {
| show-toolbar | 是否显示顶部栏 | _boolean_ | `true` |
| allow-html | 是否允许选项内容中渲染 HTML | _boolean_ | `false` |
| 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` |
+10 -2
View File
@@ -66,7 +66,15 @@ export default createComponent({
let cursor = { children: props.columns };
while (cursor && cursor.children) {
const defaultIndex = cursor.defaultIndex ?? +props.defaultIndex;
const { children } = cursor;
let defaultIndex = cursor.defaultIndex ?? +this.defaultIndex;
while (
children[defaultIndex].disabled &&
defaultIndex < children.length - 1
) {
defaultIndex++;
}
formatted.push({
values: cursor.children,
@@ -74,7 +82,7 @@ export default createComponent({
defaultIndex,
});
cursor = cursor.children[defaultIndex];
cursor = children[defaultIndex];
}
formattedColumns.value = formatted;
@@ -5,3 +5,34 @@ exports[`disabled in cascade 1`] = `
<div class="van-ellipsis">A2</div>
</li>
`;
exports[`should move to next option when default option is disabled 1`] = `
<div class="van-picker">
<!---->
<div class="van-picker__columns" style="height: 264px;">
<div class="van-picker-column">
<ul class="van-picker-column__wrapper" style="transform: translate3d(0, 66px, 0); transition-duration: 0ms; transition-property: none;">
<li role="button" tabindex="-1" class="van-picker-column__item van-picker-column__item--disabled" style="height: 44px;">
<div class="van-ellipsis">A1</div>
</li>
<li role="button" tabindex="0" class="van-picker-column__item van-picker-column__item--selected" style="height: 44px;">
<div class="van-ellipsis">A2</div>
</li>
</ul>
</div>
<div class="van-picker-column">
<ul class="van-picker-column__wrapper" style="transform: translate3d(0, 110px, 0); transition-duration: 0ms; transition-property: none;">
<li role="button" tabindex="0" class="van-picker-column__item van-picker-column__item--selected" style="height: 44px;">
<div class="van-ellipsis">B3</div>
</li>
<li role="button" tabindex="0" class="van-picker-column__item" style="height: 44px;">
<div class="van-ellipsis">B4</div>
</li>
</ul>
</div>
<div class="van-picker__mask" style="background-size: 100% 110px;"></div>
<div class="van-hairline-unset--top-bottom van-picker__frame" style="height: 44px;"></div>
</div>
<!---->
</div>
`;
+20
View File
@@ -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();
});