Skip to content
Open
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
17 changes: 17 additions & 0 deletions packages/schemas/resources/js/components/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ export default function wizardSchemaComponent({
this.scroll()
},

goToStep(stepKey) {
const stepIndex = this.getStepIndex(stepKey)

if (stepIndex <= -1) {
return
}

if (!isSkippable && stepIndex > this.getStepIndex(this.step)) {
return
}

this.step = stepKey

this.autofocusFields()
this.scroll()
},

scroll() {
this.$nextTick(() => {
this.$refs.header?.children[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
stepQueryStringKey: @js($getStepQueryStringKey()),
})"
x-on:next-wizard-step.window="if ($event.detail.key === @js($key)) goToNextStep()"
x-on:wizard-go-to-step.window="($event.detail.key === @js($key)) && goToStep($event.detail.step)"
wire:ignore.self
{{
$attributes
Expand Down
31 changes: 31 additions & 0 deletions packages/schemas/src/Components/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,37 @@ public function previousStep(int $currentStepIndex): void
$this->currentStepIndex($currentStepIndex - 1);
}

#[ExposedLivewireMethod]
public function goToStep(string $step): void
{
$steps = array_values(
$this->getChildSchema()->getComponents()
);

foreach ($steps as $index => $wizardStep) {
if ($wizardStep->getKey() !== $step) {
continue;
}

if (! $this->isSkippable() && $index > $this->getCurrentStepIndex()) {
return;
}

$this->currentStepIndex($index);

/** @var HasSchemas&LivewireComponent $livewire */
$livewire = $this->getLivewire();

$livewire->dispatch(
'wizard-go-to-step',
key: $this->getKey(),
step: $step,
);

return;
}
}

public function getNextAction(): Action
{
$action = Action::make($this->getNextActionName())
Expand Down
Loading