mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-21 13:59:15 +08:00
fix(TreeSelect): click-nav event not work when clicking active item (#10239)
This commit is contained in:
parent
c7cc1342fc
commit
8bc55c8b32
@ -112,9 +112,10 @@ export default defineComponent({
|
||||
|
||||
const onSidebarChange = (index: number) => {
|
||||
emit('update:mainActiveIndex', index);
|
||||
emit('click-nav', index);
|
||||
};
|
||||
|
||||
const onClickSidebarItem = (index: number) => emit('click-nav', index);
|
||||
|
||||
const renderSidebar = () => {
|
||||
const Items = props.items.map((item) => (
|
||||
<SidebarItem
|
||||
@ -123,6 +124,7 @@ export default defineComponent({
|
||||
badge={item.badge}
|
||||
class={[bem('nav-item'), item.className]}
|
||||
disabled={item.disabled}
|
||||
onClick={onClickSidebarItem}
|
||||
/>
|
||||
));
|
||||
|
||||
|
@ -26,7 +26,23 @@ test('should render empty TreeSelect correctly', () => {
|
||||
expect(mount(TreeSelect).html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should emit click-nav event when nav item is clicked', () => {
|
||||
test('should emit update:mainActiveIndex event when mainActiveIndex is changed', async () => {
|
||||
const wrapper = mount(TreeSelect, {
|
||||
props: {
|
||||
items: mockItems,
|
||||
mainActiveIndex: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const navItems = wrapper.findAll('.van-tree-select__nav-item');
|
||||
await navItems[0].trigger('click');
|
||||
expect(wrapper.emitted('update:mainActiveIndex')).toBeFalsy();
|
||||
|
||||
await navItems[1].trigger('click');
|
||||
expect(wrapper.emitted('update:mainActiveIndex')?.[0]).toEqual([1]);
|
||||
});
|
||||
|
||||
test('should emit click-nav event when nav item is clicked', async () => {
|
||||
const wrapper = mount(TreeSelect, {
|
||||
props: {
|
||||
items: mockItems,
|
||||
@ -34,9 +50,10 @@ test('should emit click-nav event when nav item is clicked', () => {
|
||||
});
|
||||
|
||||
const navItems = wrapper.findAll('.van-tree-select__nav-item');
|
||||
navItems[1].trigger('click');
|
||||
expect(wrapper.emitted('update:mainActiveIndex')?.[0]).toEqual([1]);
|
||||
expect(wrapper.emitted('click-nav')?.[0]).toEqual([1]);
|
||||
await navItems[0].trigger('click');
|
||||
expect(wrapper.emitted('click-nav')?.[0]).toEqual([0]);
|
||||
await navItems[0].trigger('click');
|
||||
expect(wrapper.emitted('click-nav')?.[1]).toEqual([0]);
|
||||
});
|
||||
|
||||
test('should emit click-item event when item is clicked', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user