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

Added hasPreviousStep and hasNextStep to StepComponent #76

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions docs/usage/navigating-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ You can also call it in your view.
</div>
```

You can also check if a next or previous step exists directly from the step component.

```blade
$this->hasNextStep();
$this->hasPreviousStep();
```

## Start at a specific step

If you want the wizard to display a specific step when it is rendered first, you can pass the step name to the `show-step` property.
Expand Down
10 changes: 10 additions & 0 deletions src/Components/StepComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public function showStep(string $stepName)
$this->emitUp('showStep', $stepName, $this->state()->currentStep());
}

public function hasPreviousStep()
{
return $this->allStepNames[0] !== Livewire::getAlias(static::class);
}

public function hasNextStep()
{
return end($this->allStepNames) !== Livewire::getAlias(static::class);
}

public function stepInfo(): array
{
return [];
Expand Down
14 changes: 14 additions & 0 deletions tests/WizardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,17 @@

assertMatchesHtmlSnapshot($navigationHtml);
});

it('does have the correct has step states', function () {
$this->secondStep = Livewire::test(SecondStepComponent::class);
$this->thirdStep = Livewire::test(ThirdStepComponent::class);

$this->assertTrue($this->firstStep->call('hasNextStep'));
$this->assertFalse($this->firstStep->call('hasPreviousStep'));

$this->assertTrue($this->secondStep->call('hasNextStep'));
$this->assertTrue($this->secondStep->call('hasPreviousStep'));

$this->assertFalse($this->thirdStep->call('hasNextStep'));
$this->assertTrue($this->thirdStep->call('hasPreviousStep'));
});