Skip to content

Commit df67212

Browse files
authored
fix(stepper): linear property in story not working (#1501)
1 parent 77bc2c4 commit df67212

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

stories/stepper.stories.ts

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { html } from 'lit';
44
import {
55
IgcButtonComponent,
66
IgcInputComponent,
7+
type IgcStepComponent,
78
IgcStepperComponent,
89
defineComponents,
910
} from 'igniteui-webcomponents';
@@ -122,19 +123,35 @@ const BasicTemplate = ({
122123
verticalAnimation,
123124
horizontalAnimation,
124125
}: IgcStepperArgs) => {
125-
const next = () => {
126+
document.addEventListener('DOMContentLoaded', () => {
126127
const stepper = document.getElementById('stepper') as IgcStepperComponent;
127-
stepper.next();
128-
};
129128

130-
const prev = () => {
129+
stepper.addEventListener('igcInput', () => {
130+
checkValidity();
131+
});
132+
stepper.addEventListener('igcChange', () => {
133+
checkValidity();
134+
});
135+
});
136+
137+
function checkValidity() {
131138
const stepper = document.getElementById('stepper') as IgcStepperComponent;
132-
stepper.prev();
133-
};
139+
const activeStep = stepper.steps.find(
140+
(step) => step.active
141+
) as IgcStepComponent;
142+
const form = activeStep!.querySelector('form') as HTMLFormElement;
143+
const isFormInvalid = !form.checkValidity();
134144

135-
return html`
136-
<span>test content top</span>
145+
if (activeStep!.optional) {
146+
return;
147+
}
148+
149+
if (stepper.linear) {
150+
activeStep!.invalid = isFormInvalid;
151+
}
152+
}
137153

154+
return html`
138155
<igc-stepper
139156
id="stepper"
140157
.orientation=${orientation}
@@ -146,31 +163,28 @@ const BasicTemplate = ({
146163
.verticalAnimation=${verticalAnimation}
147164
.horizontalAnimation=${horizontalAnimation}
148165
>
149-
<igc-step complete>
166+
<igc-step invalid>
150167
<span slot="title">Step1</span>
151-
<span slot="subtitle">(completed)</span>
152-
<igc-input
153-
label="First Name"
154-
id="first-name"
155-
name="first-name"
156-
required
157-
></igc-input>
158-
<br /><br />
159-
<igc-button @click=${next}>Next</igc-button>
168+
<form id="form">
169+
<igc-input
170+
label="First Name"
171+
id="first-name"
172+
name="first-name"
173+
required
174+
></igc-input>
175+
</form>
160176
</igc-step>
161177
162-
<igc-step active>
178+
<igc-step invalid>
163179
<span slot="title">Step 2</span>
164-
<span slot="subtitle">(default)</span>
165-
<igc-input
166-
label="Last Name"
167-
id="last-name"
168-
name="last-name"
169-
required
170-
></igc-input>
171-
<br /><br />
172-
<igc-button @click=${prev}>Prev</igc-button>
173-
<igc-button @click=${next}>Next</igc-button>
180+
<form id="form">
181+
<igc-input
182+
label="Last Name"
183+
id="last-name"
184+
name="last-name"
185+
required
186+
></igc-input>
187+
</form>
174188
</igc-step>
175189
176190
<igc-step optional>
@@ -180,9 +194,6 @@ const BasicTemplate = ({
180194
soluta nulla asperiores, officia ullam recusandae voluptatem omnis
181195
perferendis vitae non magni magnam praesentium placeat nemo quas
182196
repudiandae. Nisi, quo ex!
183-
<br /><br />
184-
<igc-button @click=${prev}>Prev</igc-button>
185-
<igc-button @click=${next}>Next</igc-button>
186197
</igc-step>
187198
188199
<igc-step disabled>
@@ -197,11 +208,8 @@ const BasicTemplate = ({
197208
repudiandae. Nisi, quo ex!
198209
</div>
199210
<br />
200-
<igc-button @click=${prev}>Prev</igc-button>
201211
</igc-step>
202212
</igc-stepper>
203-
204-
<span>test content bottom</span>
205213
`;
206214
};
207215

0 commit comments

Comments
 (0)