Open mvaliolahi opened 2 months ago
There's some cases not covered in the code and tests
https://github.com/mvaliolahi/alpine/pull/1
Made a PR to add these tests.
Specifically:
else-if
that overlap?else-if
that have different dependencies?This is a great feature to have, so kudos for stepping up to do it!
I don't think this isn't a great way to go about it though.
Maybe have the initial x-if
walk forward through the DOM to identify the branches and control who should show.
@ekwoka I think your concerns are valid I will change the code to support this case.
This pull request adds two new directives, x-else and x-else-if, to Alpine.js.
How It Works:
x-else-if: Looks for a preceding x-if or x-else-if and only shows its content if none of those conditions are true. x-else: Displays its content only if all previous conditions have failed.
Basic Usage:
Inside a Loop:
Tests:
I've added tests to ensure these new directives work as expected, including cases with multiple conditions and inside x-for loops.
Why This Matters:
This enhancement provides more flexibility for conditional logic, allowing you to handle complex scenarios directly within your templates.