mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(PickerGroup): rendering correctly when using v-for (#12732)
This commit is contained in:
parent
a65e9d4bd1
commit
b1e746f45b
@ -1,12 +1,15 @@
|
||||
import {
|
||||
defineComponent,
|
||||
Comment,
|
||||
Fragment,
|
||||
type InjectionKey,
|
||||
type ExtractPropTypes,
|
||||
type VNode,
|
||||
} from 'vue';
|
||||
|
||||
// Utils
|
||||
import {
|
||||
flat,
|
||||
pick,
|
||||
extend,
|
||||
makeArrayProp,
|
||||
@ -76,9 +79,20 @@ export default defineComponent({
|
||||
const onCancel = () => emit('cancel');
|
||||
|
||||
return () => {
|
||||
const childNodes = slots
|
||||
let childNodes = slots
|
||||
.default?.()
|
||||
?.filter((node) => node.type !== Comment);
|
||||
?.filter((node) => node.type !== Comment)
|
||||
.map((node) => {
|
||||
if (node.type === Fragment) {
|
||||
return node.children as VNode[];
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
if (childNodes) {
|
||||
childNodes = flat(childNodes);
|
||||
}
|
||||
|
||||
const confirmButtonText = showNextButton()
|
||||
? props.nextStepText
|
||||
|
@ -143,3 +143,25 @@ test('support controlled mode to set active-tab', async () => {
|
||||
await later();
|
||||
expect(tabs[1]?.classes()).toContain('van-tab--active');
|
||||
});
|
||||
|
||||
test('should render correctly with v-for', async () => {
|
||||
const Comp = {
|
||||
components: {
|
||||
Picker,
|
||||
PickerGroup,
|
||||
},
|
||||
template: `
|
||||
<picker-group :tabs="['Tab1', 'Tab2']">
|
||||
<picker v-for="_ in 2" :columns="[{ text: '1', value: '1' }]" />
|
||||
</picker-group>
|
||||
`,
|
||||
};
|
||||
|
||||
const wrapper = mount(Comp);
|
||||
const items = wrapper.findAll('.van-swipe-item');
|
||||
|
||||
items.forEach((item) => {
|
||||
const picker = item.find('.van-picker');
|
||||
expect(picker.exists()).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
@ -81,3 +81,6 @@ export const isSameValue = (newValue: unknown, oldValue: unknown) =>
|
||||
|
||||
export const toArray = <T>(item: T | T[]): T[] =>
|
||||
Array.isArray(item) ? item : [item];
|
||||
|
||||
export const flat = <T>(arr: Array<T | T[]>) =>
|
||||
arr.reduce<T[]>((acc, val) => acc.concat(val), []);
|
||||
|
Loading…
x
Reference in New Issue
Block a user