fix(steps): steps.current should be update before @enter
This commit is contained in:
parent
610b908f62
commit
ebe2bc1aad
2 changed files with 36 additions and 1 deletions
|
|
@ -110,13 +110,14 @@ export class LionSteps extends ObserverMixin(LionLitElement) {
|
||||||
const toStep = { number: newCurrent, element: newStepElement };
|
const toStep = { number: newCurrent, element: newStepElement };
|
||||||
|
|
||||||
oldStepElement.leave();
|
oldStepElement.leave();
|
||||||
newStepElement.enter();
|
|
||||||
|
|
||||||
if (this.current !== newCurrent) {
|
if (this.current !== newCurrent) {
|
||||||
this._internalCurrentSync = true;
|
this._internalCurrentSync = true;
|
||||||
this.current = newCurrent;
|
this.current = newCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newStepElement.enter();
|
||||||
|
|
||||||
this._dispatchTransitionEvent(fromStep, toStep);
|
this._dispatchTransitionEvent(fromStep, toStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,40 @@ describe('lion-steps', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('events', () => {
|
||||||
|
it('will trigger lion-step @leave event before changing .current', async () => {
|
||||||
|
let currentInLeaveEvent;
|
||||||
|
const onLeave = ev => {
|
||||||
|
currentInLeaveEvent = ev.target.controller.current;
|
||||||
|
};
|
||||||
|
const el = await fixture(html`
|
||||||
|
<lion-steps>
|
||||||
|
<lion-step @leave=${onLeave}>Step 0</lion-step>
|
||||||
|
<lion-step>Step 1</lion-step>
|
||||||
|
<lion-step>Step 2</lion-step>
|
||||||
|
</lion-steps>
|
||||||
|
`);
|
||||||
|
el.next();
|
||||||
|
expect(currentInLeaveEvent).to.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will trigger lion-step @enter event after changing .current', async () => {
|
||||||
|
let currentInEnterEvent;
|
||||||
|
const onEnter = ev => {
|
||||||
|
currentInEnterEvent = ev.target.controller.current;
|
||||||
|
};
|
||||||
|
const el = await fixture(html`
|
||||||
|
<lion-steps>
|
||||||
|
<lion-step>Step 0</lion-step>
|
||||||
|
<lion-step @enter=${onEnter}> Step 1</lion-step>
|
||||||
|
<lion-step>Step 2</lion-step>
|
||||||
|
</lion-steps>
|
||||||
|
`);
|
||||||
|
el.next();
|
||||||
|
expect(currentInEnterEvent).to.equal(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('workflow with data and conditions', () => {
|
describe('workflow with data and conditions', () => {
|
||||||
it('navigates to the next step which passes the condition', async () => {
|
it('navigates to the next step which passes the condition', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue