mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 18:00:27 +08:00
feat(Steps): add click-step event (#5937)
This commit is contained in:
parent
ac3c77c17f
commit
5bbe5608ce
@ -17,6 +17,7 @@ export default createComponent({
|
|||||||
return 'process';
|
return 'process';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
active() {
|
active() {
|
||||||
return this.status === 'process';
|
return this.status === 'process';
|
||||||
},
|
},
|
||||||
@ -48,6 +49,10 @@ export default createComponent({
|
|||||||
|
|
||||||
return <i class={bem('circle')} />;
|
return <i class={bem('circle')} />;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onClickStep() {
|
||||||
|
this.parent.$emit('click-step', this.index);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -59,10 +64,16 @@ export default createComponent({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={[BORDER, bem([direction, { [status]: status }])]}>
|
<div class={[BORDER, bem([direction, { [status]: status }])]}>
|
||||||
<div class={bem('title', { active })} style={titleStyle}>
|
<div
|
||||||
|
class={bem('title', { active })}
|
||||||
|
style={titleStyle}
|
||||||
|
onClick={this.onClickStep}
|
||||||
|
>
|
||||||
{this.slots()}
|
{this.slots()}
|
||||||
</div>
|
</div>
|
||||||
<div class={bem('circle-container')}>{this.genCircle()}</div>
|
<div class={bem('circle-container')} onClick={this.onClickStep}>
|
||||||
|
{this.genCircle()}
|
||||||
|
</div>
|
||||||
<div class={bem('line')} style={lineStyle} />
|
<div class={bem('line')} style={lineStyle} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -85,3 +85,9 @@ export default {
|
|||||||
|------|------|
|
|------|------|
|
||||||
| active-icon | Custom active icon |
|
| active-icon | Custom active icon |
|
||||||
| inactive-icon | Custom inactive icon |
|
| inactive-icon | Custom inactive icon |
|
||||||
|
|
||||||
|
### Steps Events
|
||||||
|
|
||||||
|
| Event | Description | Arguments |
|
||||||
|
|------|------|------|
|
||||||
|
| click-step `v2.6.0` | Triggered when a step's title or icon is clicked | *index: number* |
|
||||||
|
@ -91,3 +91,9 @@ export default {
|
|||||||
|------|------|
|
|------|------|
|
||||||
| active-icon | 自定义激活状态图标 |
|
| active-icon | 自定义激活状态图标 |
|
||||||
| inactive-icon | 自定义未激活状态图标 |
|
| inactive-icon | 自定义未激活状态图标 |
|
||||||
|
|
||||||
|
### Steps Events
|
||||||
|
|
||||||
|
| 事件名 | 说明 | 回调参数 |
|
||||||
|
|------|------|------|
|
||||||
|
| click-step `v2.6.0` | 点击步骤的标题或图标时触发 | *index: number* |
|
||||||
|
@ -1,29 +1,52 @@
|
|||||||
import { mount } from '../../../test';
|
import { mount } from '../../../test';
|
||||||
import Steps from '..';
|
|
||||||
import Step from '../../step';
|
|
||||||
|
|
||||||
test('icon slot', () => {
|
test('icon slot', () => {
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
template: `
|
template: `
|
||||||
<steps :active="1">
|
<van-steps :active="1">
|
||||||
<step>
|
<van-step>
|
||||||
<template v-slot:inactive-icon>Custim Inactive Icon</template>
|
<template v-slot:inactive-icon>Custim Inactive Icon</template>
|
||||||
A
|
A
|
||||||
</step>
|
</van-step>
|
||||||
<step>
|
<van-step>
|
||||||
<template v-slot:active-icon>Custim Active Icon</template>
|
<template v-slot:active-icon>Custim Active Icon</template>
|
||||||
B
|
B
|
||||||
</step>
|
</van-step>
|
||||||
<step>
|
<van-step>
|
||||||
<template v-slot:inactive-icon>Custim Inactive Icon</template>
|
<template v-slot:inactive-icon>Custim Inactive Icon</template>
|
||||||
C
|
C
|
||||||
</step>
|
</van-step>
|
||||||
</steps>
|
</van-steps>
|
||||||
`,
|
`,
|
||||||
components: {
|
|
||||||
Steps,
|
|
||||||
Step,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('click-step event', () => {
|
||||||
|
const onClickStep = jest.fn();
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<van-steps :active="1" @click-step="onClickStep">
|
||||||
|
<van-step>A</van-step>
|
||||||
|
<van-step>B</van-step>
|
||||||
|
<van-step>C</van-step>
|
||||||
|
</van-steps>
|
||||||
|
`,
|
||||||
|
methods: {
|
||||||
|
onClickStep,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-step').trigger('click');
|
||||||
|
expect(onClickStep).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
|
wrapper.find('.van-step__title').trigger('click');
|
||||||
|
expect(onClickStep).toHaveBeenCalledWith(0);
|
||||||
|
|
||||||
|
wrapper
|
||||||
|
.findAll('.van-step__circle-container')
|
||||||
|
.at(2)
|
||||||
|
.trigger('click');
|
||||||
|
expect(onClickStep).toHaveBeenCalledTimes(2);
|
||||||
|
expect(onClickStep).toHaveBeenLastCalledWith(2);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user