mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 18:00:27 +08:00
fix(TreeSelect): should sync value before trigger click-item event (#5153)
This commit is contained in:
parent
3c45cdb231
commit
d1a8adab20
@ -97,9 +97,8 @@ function TreeSelect(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(ctx, 'click-item', item);
|
|
||||||
emit(ctx, 'update:active-id', newActiveId);
|
emit(ctx, 'update:active-id', newActiveId);
|
||||||
|
emit(ctx, 'click-item', item);
|
||||||
// compatible for old usage, should be removed in next major version
|
// compatible for old usage, should be removed in next major version
|
||||||
emit(ctx, 'itemclick', item);
|
emit(ctx, 'itemclick', item);
|
||||||
}
|
}
|
||||||
@ -119,9 +118,8 @@ function TreeSelect(
|
|||||||
class={bem('nav')}
|
class={bem('nav')}
|
||||||
activeKey={mainActiveIndex}
|
activeKey={mainActiveIndex}
|
||||||
onChange={(index: number) => {
|
onChange={(index: number) => {
|
||||||
emit(ctx, 'click-nav', index);
|
|
||||||
emit(ctx, 'update:main-active-index', index);
|
emit(ctx, 'update:main-active-index', index);
|
||||||
|
emit(ctx, 'click-nav', index);
|
||||||
// compatible for old usage, should be removed in next major version
|
// compatible for old usage, should be removed in next major version
|
||||||
emit(ctx, 'navclick', index);
|
emit(ctx, 'navclick', index);
|
||||||
}}
|
}}
|
||||||
|
@ -295,3 +295,37 @@ test('className of nav', () => {
|
|||||||
const items = wrapper.findAll('.van-tree-select__nav-item');
|
const items = wrapper.findAll('.van-tree-select__nav-item');
|
||||||
expect(items.at(0).element.classList.contains('my-class')).toBeTruthy();
|
expect(items.at(0).element.classList.contains('my-class')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should sync value before trigger click-item event', done => {
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<van-tree-select
|
||||||
|
:items="items"
|
||||||
|
:main-active-index="0"
|
||||||
|
:active-id.sync="activeId"
|
||||||
|
@click-item="onClickItem"
|
||||||
|
/>
|
||||||
|
`,
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
activeId: mockItem.id,
|
||||||
|
mainActiveIndex: 0,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: 'group1',
|
||||||
|
children: [mockItem, mockItem2]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClickItem() {
|
||||||
|
expect(wrapper.vm.activeId).toEqual(mockItem2.id);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const items = wrapper.findAll('.van-tree-select__item');
|
||||||
|
items.at(1).trigger('click');
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user