In this episode, we're working on adding a top navigation to our multi-step form (or "wizard"). This navigation will sit at the top and show all the steps, letting the user click around to quickly jump between them.
We start by creating a new Blade component just for the navigation, and then register it as an anonymous Blade component. That way, we can easily include it in each step of our form. You’ll see a cool trick for registering custom paths for components, so we can keep our code organized.
Next up, we look at how to display each of the steps with a label. To do this, we add a stepInfo
method in each step component to supply a custom label (like "Product Information", "Product Image", etc) that shows up in the navigation.
We then loop through all the steps in our navigation component, show the label (with its index as a step number), and style them with Tailwind so it actually looks nice. There’s some playing around to get the active/current step styled differently so the user knows where they are. And finally, we wire up click events so you can jump to any step by clicking on its name.
Heads up: the navigation lets you jump to any step now, but there's a limitation with this package—it doesn't easily let you prevent users from jumping ahead before filling out earlier steps. That’s something we’ll address in a later episode, but it's still valuable to see how you can build up the navigation UI.
By the end of this video, we have a functional, styled, click-to-jump navigation for our multi-step form!