Skip to content

Commit 508979f

Browse files
authored
fix(stepper): emits calciteStepperItemChange event when switched to first step (#8422)
**Related Issue:** #8397 ## Summary Emits `calciteStepperItemChange` event when switched to the first enabled step in single view layout.
1 parent 26dec64 commit 508979f

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

packages/calcite-components/src/components/stepper/stepper.e2e.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,10 @@ describe("calcite-stepper", () => {
798798
it("should emit calciteStepperItemChange on user interaction", async () => {
799799
const page = await newE2EPage();
800800
await page.setContent(html`<calcite-stepper style="width: 100px">
801-
<calcite-stepper-item heading="Step 1" id="step-1" disabled>
801+
<calcite-stepper-item heading="Step 1" id="step-1">
802802
<div>Step 1 content</div>
803803
</calcite-stepper-item>
804-
<calcite-stepper-item heading="Step 2" id="step-2">
804+
<calcite-stepper-item heading="Step 2" id="step-2" disabled>
805805
<div>Step 2 content</div>
806806
</calcite-stepper-item>
807807
<calcite-stepper-item heading="Step 3" id="step-2">
@@ -811,27 +811,26 @@ describe("calcite-stepper", () => {
811811

812812
const stepper = await page.find("calcite-stepper");
813813
const [actionStart, actionEnd] = await page.findAll("calcite-stepper >>> calcite-action");
814-
const [stepperItem1] = await page.findAll("calcite-stepper-item");
815814
const eventSpy = await stepper.spyOnEvent("calciteStepperItemChange");
816815
expect(eventSpy).toHaveReceivedEventTimes(0);
817816

817+
// shouldn't emit change event when disabled element is visible
818818
await actionEnd.click();
819819
await page.waitForChanges();
820-
expect(eventSpy).toHaveReceivedEventTimes(1);
820+
expect(eventSpy).toHaveReceivedEventTimes(0);
821821

822-
await actionStart.click();
822+
await actionEnd.click();
823823
await page.waitForChanges();
824-
expect(eventSpy).toHaveReceivedEventTimes(2);
824+
expect(eventSpy).toHaveReceivedEventTimes(1);
825825

826826
// shouldn't emit change event when disabled element is visible
827-
stepperItem1.setProperty("disabled", true);
828827
await actionStart.click();
829828
await page.waitForChanges();
830-
expect(eventSpy).toHaveReceivedEventTimes(2);
829+
expect(eventSpy).toHaveReceivedEventTimes(1);
831830

832-
await actionEnd.click();
831+
await actionStart.click();
833832
await page.waitForChanges();
834-
expect(eventSpy).toHaveReceivedEventTimes(3);
833+
expect(eventSpy).toHaveReceivedEventTimes(2);
835834
});
836835
});
837836
});

packages/calcite-components/src/components/stepper/stepper.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ export class Stepper implements LocalizedComponent, T9nComponent {
118118
* Fires when the active `calcite-stepper-item` changes.
119119
*
120120
*/
121-
@Event({ cancelable: false })
122-
calciteStepperItemChange: EventEmitter<void>;
121+
@Event({ cancelable: false }) calciteStepperItemChange: EventEmitter<void>;
123122

124123
/**
125124
* Fires when the active `calcite-stepper-item` changes.
@@ -242,7 +241,6 @@ export class Stepper implements LocalizedComponent, T9nComponent {
242241
@Listen("calciteInternalStepperItemSelect")
243242
updateItem(event: CustomEvent): void {
244243
const { position } = event.detail;
245-
246244
if (typeof position === "number") {
247245
this.currentActivePosition = position;
248246
this.selectedItem = event.target as HTMLCalciteStepperItemElement;
@@ -506,7 +504,7 @@ export class Stepper implements LocalizedComponent, T9nComponent {
506504
}
507505

508506
if (
509-
this.currentActivePosition &&
507+
typeof this.currentActivePosition === "number" &&
510508
currentActivePosition !== this.currentActivePosition &&
511509
!this.items[this.currentActivePosition].disabled
512510
) {

0 commit comments

Comments
 (0)