mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): should move to first option when all options are disabled (#7504)
This commit is contained in:
parent
287a4acea0
commit
f07d8e6709
@ -89,11 +89,13 @@ export default createComponent({
|
||||
const { children } = cursor;
|
||||
let defaultIndex = cursor.defaultIndex ?? +this.defaultIndex;
|
||||
|
||||
while (
|
||||
children[defaultIndex].disabled &&
|
||||
defaultIndex < children.length - 1
|
||||
) {
|
||||
defaultIndex++;
|
||||
while (children[defaultIndex] && children[defaultIndex].disabled) {
|
||||
if (defaultIndex < children.length - 1) {
|
||||
defaultIndex++;
|
||||
} else {
|
||||
defaultIndex = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
formatted.push({
|
||||
|
@ -6,6 +6,37 @@ exports[`disabled in cascade 1`] = `
|
||||
</li>
|
||||
`;
|
||||
|
||||
exports[`should move to first option when all options are 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, 110px, 0); transition-duration: 0ms; transition-property: none;">
|
||||
<li role="button" tabindex="-1" class="van-picker-column__item van-picker-column__item--disabled van-picker-column__item--selected" style="height: 44px;">
|
||||
<div class="van-ellipsis">A1</div>
|
||||
</li>
|
||||
<li role="button" tabindex="-1" class="van-picker-column__item van-picker-column__item--disabled" 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="-1" class="van-picker-column__item van-picker-column__item--disabled van-picker-column__item--selected" style="height: 44px;">
|
||||
<div class="van-ellipsis">B1</div>
|
||||
</li>
|
||||
<li role="button" tabindex="-1" class="van-picker-column__item van-picker-column__item--disabled" style="height: 44px;">
|
||||
<div class="van-ellipsis">B2</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>
|
||||
`;
|
||||
|
||||
exports[`should move to next option when default option is disabled 1`] = `
|
||||
<div class="van-picker">
|
||||
<!---->
|
||||
|
@ -145,3 +145,30 @@ test('should move to next option when default option is disabled', () => {
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should move to first option when all options are disabled', () => {
|
||||
const wrapper = mount(Picker, {
|
||||
propsData: {
|
||||
columns: [
|
||||
{
|
||||
text: 'A1',
|
||||
disabled: true,
|
||||
children: [
|
||||
{ text: 'B1', disabled: true },
|
||||
{ text: 'B2', disabled: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'A2',
|
||||
disabled: true,
|
||||
children: [
|
||||
{ text: 'B3', disabled: true },
|
||||
{ text: 'B4', disabled: true },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user