Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stepper): selects next enabled stepper-item when first one is disabled #8004

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/calcite-components/src/components/stepper/stepper.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,21 @@ describe("calcite-stepper", () => {
await page.waitForChanges();
expect(stepperItem2.getAttribute("aria-current")).toEqual("step");
});

it("should select the next enabled stepper-item if first stepper-item is disabled", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-stepper>
<calcite-stepper-item heading="Step 1" id="step-1" disabled>
<div>Step 1 content</div>
</calcite-stepper-item>
<calcite-stepper-item heading="Step 2" id="step-2">
<div>Step 2 content</div>
</calcite-stepper-item>
</calcite-stepper>`);

const [stepperItem1, stepperItem2] = await page.findAll("calcite-stepper-item");

expect(stepperItem1).not.toHaveAttribute("selected");
anveshmekala marked this conversation as resolved.
Show resolved Hide resolved
expect(stepperItem2).toHaveAttribute("selected");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,9 @@ export const verticalLayout_TestOnly = (): string => html`<calcite-stepper layou
>Step 1 Content Goes Here</calcite-stepper-item
>
</calcite-stepper>`;

export const firstItemDisabled_TestOnly = (): string => html`<calcite-stepper>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this test if the E2E test already covers it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are visual differences for selected stepper-item it is better to have a screenshot. I think we can utilize existing disabled story. Thoughts?

<calcite-stepper-item heading="item1" disabled>1</calcite-stepper-item>
<calcite-stepper-item heading="item2">2</calcite-stepper-item>
<calcite-stepper-item heading="item3">3</calcite-stepper-item>
</calcite-stepper>`;
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class Stepper {
// if no stepper items are set as active, default to the first one
if (typeof this.currentPosition !== "number") {
this.calciteInternalStepperItemChange.emit({
position: 0,
position: this.getFirstEnabledStepperPosition(),
});
}
}
Expand Down Expand Up @@ -333,4 +333,9 @@ export class Stepper {
this.el.style.gridTemplateColumns = spacing;
this.setStepperItemNumberingSystem();
};

private getFirstEnabledStepperPosition(): number {
const enabledStepIndex = this.items.findIndex((item) => !item.disabled);
return enabledStepIndex > -1 ? enabledStepIndex : 0;
}
}
Loading