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 all 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
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(await stepperItem1.getProperty("selected")).toBe(false);
expect(await stepperItem2.getProperty("selected")).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ export const overriddenWidth_TestOnly = (): string => html` <calcite-stepper num
</calcite-stepper>`;

export const disabled_TestOnly = (): string => html`<calcite-stepper>
<calcite-stepper-item heading="item1" complete>1</calcite-stepper-item>
<calcite-stepper-item heading="item1" complete disabled>1</calcite-stepper-item>
<calcite-stepper-item heading="item2">2</calcite-stepper-item>
<calcite-stepper-item heading="item3" selected>3</calcite-stepper-item>
<calcite-stepper-item heading="item4" disabled>4</calcite-stepper-item>
</calcite-stepper>`;

export const arabicNumberingSystem_TestOnly = (): string => html` <calcite-stepper
Expand Down
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