Merge pull request #11605 from slovenianGooner/patch-1

Add action, tag and method options to MenuItem
This commit is contained in:
Dan Harrin
2024-02-28 11:51:08 +00:00
committed by GitHub
5 changed files with 54 additions and 4 deletions
+12
View File
@@ -486,6 +486,18 @@ MenuItem::make()
->hidden(fn (): bool => ! auth()->user()->can('viewAny', Payment::class))
```
### Sending a `POST` HTTP request from a user menu item
You can send a `POST` HTTP request from a user menu item by passing a URL to the `postAction()` method:
```php
use Filament\Navigation\MenuItem;
MenuItem::make()
->label('Lock session')
->postAction(fn (): string => route('lock-session'))
```
## Disabling breadcrumbs
The default layout will show breadcrumbs to indicate the location of the current page within the hierarchy of the app.
+12
View File
@@ -435,6 +435,18 @@ MenuItem::make()
->hidden(fn (): bool => ! auth()->user()->can('manage-team'))
```
### Sending a `POST` HTTP request from a tenant menu item
You can send a `POST` HTTP request from a tenant menu item by passing a URL to the `postAction()` method:
```php
use Filament\Navigation\MenuItem;
MenuItem::make()
->label('Lock session')
->postAction(fn (): string => route('lock-session'))
```
### Hiding the tenant menu
You can hide the tenant menu by using the `tenantMenu(false)`
@@ -116,12 +116,18 @@
@if (count($items))
<x-filament::dropdown.list>
@foreach ($items as $item)
@php
$itemPostAction = $item->getPostAction();
@endphp
<x-filament::dropdown.list.item
:action="$itemPostAction"
:color="$item->getColor()"
:href="$item->getUrl()"
:target="$item->shouldOpenUrlInNewTab() ? '_blank' : null"
:icon="$item->getIcon()"
tag="a"
:method="filled($itemPostAction) ? 'post' : null"
:tag="filled($itemPostAction) ? 'form' : 'a'"
:target="$item->shouldOpenUrlInNewTab() ? '_blank' : null"
>
{{ $item->getLabel() }}
</x-filament::dropdown.list.item>
@@ -67,12 +67,18 @@
<x-filament::dropdown.list>
@foreach ($items as $key => $item)
@php
$itemPostAction = $item->getPostAction();
@endphp
<x-filament::dropdown.list.item
:action="$itemPostAction"
:color="$item->getColor()"
:href="$item->getUrl()"
:target="$item->shouldOpenUrlInNewTab() ? '_blank' : null"
:icon="$item->getIcon()"
tag="a"
:method="filled($itemPostAction) ? 'post' : null"
:tag="filled($itemPostAction) ? 'form' : 'a'"
:target="$item->shouldOpenUrlInNewTab() ? '_blank' : null"
>
{{ $item->getLabel() }}
</x-filament::dropdown.list.item>
@@ -8,6 +8,8 @@ use Laravel\SerializableClosure\Serializers\Native;
class MenuItem extends Component
{
protected string | Closure | null $postAction = null;
/**
* @var string | array{50: string, 100: string, 200: string, 300: string, 400: string, 500: string, 600: string, 700: string, 800: string, 900: string, 950: string} | Closure | null
*/
@@ -78,6 +80,13 @@ class MenuItem extends Component
return $this;
}
public function postAction(string | Closure | null $action): static
{
$this->postAction = $action;
return $this;
}
public function openUrlInNewTab(bool | Closure $condition = true): static
{
$this->shouldOpenUrlInNewTab = $condition;
@@ -141,6 +150,11 @@ class MenuItem extends Component
return $this->evaluate($this->url);
}
public function getPostAction(): ?string
{
return $this->evaluate($this->postAction);
}
public function shouldOpenUrlInNewTab(): bool
{
return (bool) $this->evaluate($this->shouldOpenUrlInNewTab);