-
Notifications
You must be signed in to change notification settings - Fork 47
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
Navigation Item Current Attribute dropped on dispatched event. #918
Comments
@kyledoesdev That's happening because your navigation item is a Livewire component containing the event listener thus it is getting re-rendered when the event is dispatched and, at that point, the route is I believe if you move the layout-level:
livewire/navigation-badge.blade.php
|
This somewhat patches the problem, but the badge is now not included in the accent underline of the nav item because it's a sperate badge being rendered. This works, it just doesn't have that fluid look to it: |
@kyledoesdev We're getting closer... I'll give this a think. |
Sounds good, I am going to continue to tinker with it as well. |
@kyledoesdev Just heading out, but what about moving the word 'Invitations' into the component's render so the component is responsible for the entire menu prompt? |
I think that'll do it. I can throw some tailwind on the badge to scale it better. But I can go with this one for now: 2024-12-22.12-52-21.mp4 |
@kyledoesdev thanks for reporting! @jeffchown is correct, on update, request has changed, so the current route no longer matches. Caleb recently added So even if you manage to find a work around, I think you should leave this open, so we can see if we can get Flux using something like |
Sounds good Josh! Let's leave it open for now. The work-around that @jeffchown suggested above is working fine for now for me. |
I've had a look into whether we can use The reason is that Flux adds a So I've submitted a PR livewire/livewire#9130 to Livewire to add support for a This should allow us to update Flux at a later date to support usage of this, or a user can do it themselves by using <flux:navbar.item href="/about" :current="false" wire:current.attr="data-current">About</flux:navbar.item> Volt component I used for testing the Livewire PR Volt::route('/playground/{id?}', 'playground')->name('playground'); <?php
use Livewire\Volt\Component;
new class extends Component {
//
};
?>
<div>
<button type="button" wire:click="$refresh">Refresh</button>
<flux:navbar>
<flux:navbar.item
href="{{ route('playground') }}"
:badge="5"
badge-color="sky"
icon="envelope"
>
Invitations
</flux:navbar.item>
<flux:navbar.item href="/playground" :current="false" wire:current.attr="data-current">Playground</flux:navbar.item>
<flux:navbar.item href="/playground" :current="false" wire:current.attr.exact="data-current">Playground Exact</flux:navbar.item>
<flux:navbar.item href="/playground/1" :current="false" wire:current.attr.exact="data-current">Playground 1</flux:navbar.item>
<flux:navbar.item href="/playground/2" :current="false" wire:current.attr.exact="data-current">Playground 2</flux:navbar.item>
</flux:navbar>
<hr class="mt-4" />
<a class="block" href="/playground" wire:current="font-bold">Playground</a>
<a class="block" href="/playground" wire:current.exact="font-bold">Playground Exact</a>
<a class="block" href="/playground/1" wire:current.exact="font-bold">Playground 1</a>
<a class="block" href="/playground/2" wire:current.exact="font-bold">Playground 2</a>
<flux:link class="!block" href="/playground" wire:current="font-bold">Playground</flux:link>
<flux:link class="!block" href="/playground" wire:current.exact="font-bold">Playground Exact</flux:link>
<flux:link class="!block" href="/playground/1" wire:current.exact="font-bold">Playground 1</flux:link>
<flux:link class="!block" href="/playground/2" wire:current.exact="font-bold">Playground 2</flux:link>
</div> |
@kyledoesdev so I've just tested what you are reporting a bit further and realised for your specific scenario you shouldn't need to set Like <flux:navbar.item
href="{{ route('playground') }}"
:badge="5"
badge-color="sky"
icon="envelope"
> If you don't use |
I believe I was doing :current="request()->is('invites')" because without it the theme underline color of the nav item was not appearing when I was on that page's route. <flux:navbar.item
href="{{ route('invites') }}"
:badge="App\Models\Invite::getPending()"
badge-color="sky"
icon="envelope"
>
Invitations
</flux:navbar.item> <flux:navbar.item
href="{{ route('invites') }}"
:badge="App\Models\Invite::getPending()"
badge-color="sky"
icon="envelope"
:current="request()->is('invites')"
>
Invitations
</flux:navbar.item> You are correct though if I remove the :current it resolves the issue as you described above, thank you! Thank you so much for taking the time to look into this and test it out & submitting the PR to Livewire! |
@kyledoesdev just to confirm it wasn't working properly before without No worries! 🙂 |
That is what I think as well. I believe a flux patch that was released since me initially running into this fixed it. How did you want to proceed with this issue? Did you want to close it, or wait until livewire/livewire#9130 is merged? |
Ok great! I'm going to close this now, as I believe this issue is fixed. But I will leave the Livewire PR open as I think it could be a helpful feature to have 😁 |
Flux version
1.1
Livewire version
3.5.17
What is the problem?
When an event is dispatched from a component to another component, the :current Attribute on a navigation item seems to drop off. Attached is a demo video of this happening.
2024-12-22.12-09-03.mp4
Code snippets
Attached are the files involved with this issue:
Navigation Badge Livewire Component
Navigation Component Template
Model getPending query function.
Navigation Layout Header.
Invite approved function that dispatches event:
How do you expect it to work?
I expect it to when the event is dispatched, the count of the badge in the navigation item to be updated without the theming underline disappearing. The current route did not change.
Please confirm (incomplete submissions will not be addressed)
The text was updated successfully, but these errors were encountered: