mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-09-01 05:39:45 +08:00
fix(Picker): should not render mask and frame when options is empty (#10135)
* docs(Search): update action slot demo * fix(Picker): should not render mask and frame when options is empty
This commit is contained in:
parent
e36081d68a
commit
be0de2023c
@ -165,14 +165,6 @@ exports[`should render demo and match snapshot 1`] = `
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -331,14 +323,6 @@ exports[`should render demo and match snapshot 1`] = `
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -410,14 +394,6 @@ exports[`should render demo and match snapshot 1`] = `
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -495,14 +471,6 @@ exports[`should render demo and match snapshot 1`] = `
|
|||||||
>
|
>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -36,14 +36,6 @@ exports[`should render columns-top、columns-bottom slot correctly 1`] = `
|
|||||||
>
|
>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
Bottom
|
Bottom
|
||||||
</div>
|
</div>
|
||||||
@ -130,14 +122,6 @@ exports[`should render two columns when columns-num prop is two 1`] = `
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -352,14 +352,29 @@ export default defineComponent({
|
|||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
const renderMask = (wrapHeight: number) => {
|
||||||
|
const hasOptions = formattedColumns.value.some(
|
||||||
|
(item) => item[valuesKey] && item[valuesKey].length !== 0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hasOptions) {
|
||||||
|
const frameStyle = { height: `${itemHeight.value}px` };
|
||||||
|
const maskStyle = {
|
||||||
|
backgroundSize: `100% ${(wrapHeight - itemHeight.value) / 2}px`,
|
||||||
|
};
|
||||||
|
return [
|
||||||
|
<div class={bem('mask')} style={maskStyle} />,
|
||||||
|
<div
|
||||||
|
class={[BORDER_UNSET_TOP_BOTTOM, bem('frame')]}
|
||||||
|
style={frameStyle}
|
||||||
|
/>,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const renderColumns = () => {
|
const renderColumns = () => {
|
||||||
const wrapHeight = itemHeight.value * +props.visibleItemCount;
|
const wrapHeight = itemHeight.value * +props.visibleItemCount;
|
||||||
const frameStyle = { height: `${itemHeight.value}px` };
|
|
||||||
const columnsStyle = { height: `${wrapHeight}px` };
|
const columnsStyle = { height: `${wrapHeight}px` };
|
||||||
const maskStyle = {
|
|
||||||
backgroundSize: `100% ${(wrapHeight - itemHeight.value) / 2}px`,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={bem('columns')}
|
class={bem('columns')}
|
||||||
@ -367,11 +382,7 @@ export default defineComponent({
|
|||||||
onTouchmove={preventDefault}
|
onTouchmove={preventDefault}
|
||||||
>
|
>
|
||||||
{renderColumnItems()}
|
{renderColumnItems()}
|
||||||
<div class={bem('mask')} style={maskStyle} />
|
{renderMask(wrapHeight)}
|
||||||
<div
|
|
||||||
class={[BORDER_UNSET_TOP_BOTTOM, bem('frame')]}
|
|
||||||
style={frameStyle}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -168,14 +168,6 @@ exports[`columns-top、columns-bottom prop 1`] = `
|
|||||||
>
|
>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
Custom Columns Bottom
|
Custom Columns Bottom
|
||||||
</div>
|
</div>
|
||||||
@ -403,14 +395,6 @@ exports[`should render confirm/cancel slot correctly 1`] = `
|
|||||||
>
|
>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -439,14 +423,6 @@ exports[`should render title slot correctly 1`] = `
|
|||||||
>
|
>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -465,14 +441,6 @@ exports[`should render toolbar slot correctly 1`] = `
|
|||||||
>
|
>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -488,14 +456,6 @@ exports[`toolbar-position prop 1`] = `
|
|||||||
>
|
>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
<div class="van-picker__toolbar">
|
<div class="van-picker__toolbar">
|
||||||
<button type="button"
|
<button type="button"
|
||||||
|
@ -345,3 +345,17 @@ test('readonly prop', () => {
|
|||||||
|
|
||||||
expect(wrapper.emitted('change')).toBeFalsy();
|
expect(wrapper.emitted('change')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not render mask and frame when options is empty', async () => {
|
||||||
|
const wrapper = mount(Picker, {
|
||||||
|
props: {
|
||||||
|
columns: [{ values: [] }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(wrapper.find('.van-picker__mask').exists()).toBeFalsy();
|
||||||
|
expect(wrapper.find('.van-picker__frame').exists()).toBeFalsy();
|
||||||
|
|
||||||
|
await wrapper.setProps({ columns: [{ values: ['foo'] }] });
|
||||||
|
expect(wrapper.find('.van-picker__mask').exists()).toBeTruthy();
|
||||||
|
expect(wrapper.find('.van-picker__frame').exists()).toBeTruthy();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user