Closed Jagadish056 closed 4 weeks ago
Hey Jagadish,
Thanks for the easy reproduction! I didn't know about that Laravel Playground either, that's a nice tool.
Unfortunately, this looks like an upstream issue with Alpine Morph. It seems that the Morph algorithm doesn't catch the change between #form-1
and #form-2
and treats both forms as the same element (form-1
).
There's two quick fixes for this problem though:
x-merge="morph"
and use x-autofocus
on the tab buttons to maintain keyboard focus.key="anything-here"
attribute to one of the forms. With a different key on both forms, Morph will work as expected.Thanks for the quick fixes! I’ve been waiting all day, and it seems to be working perfectly now.
Hey @imacrayon, sorry to trouble you again!
Without Morph
, all content gets refreshed (not a browser reload 🔄) when switching tabs. What happens if I use all three: Morph
, x-autofocus
, and key
? Could this cause issues in the future?
<section x-merge="morph">
...
<button @if($activeTab) x-autofocus @endif>{{ $tab }}</button>
...
<div key="{{ Str::random(64) }}">
@switch(true)
@case(1)
...
@break
@case(2)
...
@break
@default
...
@endswitch
</div>
</section>
Update: There was also an issue with the loading indicator aria-busy="true"
while enabling Laravel Debugbar. By default, Laravel Playground has the Laravel Debugbar installed, and you can encounter this issue when switching tabs super fast.
Using all of those together shouldn't cause problems. I'd file an issue if you find something though. One thing to note: If you're using Morph you probably don't need x-autofocus
since Morph should automatically preserve keyboard focus for you.
Alright, I'll keep that in mind, but one question remains: in this video ?v=31pBMi0UdYE&t=1637s, he's explaining the concept of Roving Tab Index. Is this currently possible with Alpine AJAX?
You can issue the request on focus
like this: x-on:focus="$ajax('?tab1', {target: 'tab1_content'})
Alternatively, you could use the x-intersect
plugin and issue the same AJAX request when a tab is revealed.
Steps to Reproduce:
playground.blade.php
and run it.Tab 1
toTab 2
, then fromTab 2
toTab 3
.button
in Tab 3.