mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge pull request #17120 from filamentphp/fix/infolist-entry-actions-and-urls
fix: Infolist entry actions and URLs
This commit is contained in:
@@ -38,11 +38,7 @@
|
||||
}
|
||||
|
||||
& .fi-in-entry-content {
|
||||
@apply w-full;
|
||||
|
||||
&.fi-align-start {
|
||||
@apply text-start;
|
||||
}
|
||||
@apply block w-full text-start;
|
||||
|
||||
&.fi-align-center {
|
||||
@apply text-center;
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
if ($entry) {
|
||||
$action ??= $entry->getAction();
|
||||
$alignment ??= $entry->getAlignment();
|
||||
$hasInlineLabel ??= $entry->hasInlineLabel();
|
||||
$label ??= $entry->getLabel();
|
||||
$labelSrOnly ??= $entry->isLabelHidden();
|
||||
$url ??= $entry->getUrl();
|
||||
}
|
||||
|
||||
if (! $alignment instanceof Alignment) {
|
||||
@@ -80,20 +82,49 @@
|
||||
<div class="fi-in-entry-content-col">
|
||||
{{ $entry?->getChildSchema($entry::ABOVE_CONTENT_SCHEMA_KEY) }}
|
||||
|
||||
<div class="fi-in-entry-content-ctn">
|
||||
<dd class="fi-in-entry-content-ctn">
|
||||
{{ $beforeContentContainer }}
|
||||
|
||||
<dd
|
||||
@class([
|
||||
'fi-in-entry-content',
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')),
|
||||
])
|
||||
>
|
||||
{{ $slot }}
|
||||
</dd>
|
||||
@if (filled($url))
|
||||
<a
|
||||
{{ \Filament\Support\generate_href_html($url, $shouldOpenUrlInNewTab) }}
|
||||
@class([
|
||||
'fi-in-entry-content',
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')),
|
||||
])
|
||||
>
|
||||
{{ $slot }}
|
||||
</a>
|
||||
@elseif (filled($action))
|
||||
@php
|
||||
$wireClickAction = $action->getLivewireClickHandler();
|
||||
@endphp
|
||||
|
||||
<button
|
||||
type="button"
|
||||
wire:click="{{ $wireClickAction }}"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="{{ $wireClickAction }}"
|
||||
@class([
|
||||
'fi-in-entry-content',
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')),
|
||||
])
|
||||
>
|
||||
{{ $slot }}
|
||||
</button>
|
||||
@else
|
||||
<div
|
||||
@class([
|
||||
'fi-in-entry-content',
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')),
|
||||
])
|
||||
>
|
||||
{{ $slot }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{ $afterContentContainer }}
|
||||
</div>
|
||||
</dd>
|
||||
|
||||
{{ $entry?->getChildSchema($entry::BELOW_CONTENT_SCHEMA_KEY) }}
|
||||
</div>
|
||||
|
||||
@@ -16,9 +16,11 @@ use Filament\Support\Concerns\HasPlaceholder;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
use Illuminate\View\ComponentSlot;
|
||||
|
||||
use function Filament\Support\generate_href_html;
|
||||
|
||||
class Entry extends Component
|
||||
{
|
||||
use CanOpenUrl;
|
||||
@@ -244,6 +246,14 @@ class Entry extends Component
|
||||
$alignment = $this->getAlignment();
|
||||
$label = $this->getLabel();
|
||||
$labelSrOnly = $this->isLabelHidden();
|
||||
$action = $this->getAction();
|
||||
$url = $this->getUrl();
|
||||
|
||||
$wrapperTag = match (true) {
|
||||
filled($url) => 'a',
|
||||
filled($action) => 'button',
|
||||
default => 'div',
|
||||
};
|
||||
|
||||
if (! $alignment instanceof Alignment) {
|
||||
$alignment = filled($alignment) ? (Alignment::tryFrom($alignment) ?? $alignment) : null;
|
||||
@@ -262,6 +272,18 @@ class Entry extends Component
|
||||
'fi-in-entry-has-inline-label' => $hasInlineLabel,
|
||||
]);
|
||||
|
||||
$contentAttributes = (new ComponentAttributeBag)
|
||||
->merge([
|
||||
'type' => ($wrapperTag === 'button') ? 'button' : null,
|
||||
'wire:click' => $wireClickAction = $action?->getLivewireClickHandler(),
|
||||
'wire:loading.attr' => ($wrapperTag === 'button') ? 'disabled' : null,
|
||||
'wire:target' => $wireClickAction,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-in-entry-content',
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')),
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
@@ -296,18 +318,17 @@ class Entry extends Component
|
||||
<div class="fi-in-entry-content-col">
|
||||
<?= $this->getChildSchema($this::ABOVE_CONTENT_SCHEMA_KEY)?->toHtml() ?>
|
||||
|
||||
<div class="fi-in-entry-content-ctn">
|
||||
<dd class="fi-in-entry-content-ctn">
|
||||
<?= $beforeContentSchema?->toHtml() ?>
|
||||
|
||||
<dd class="<?= Arr::toCssClasses([
|
||||
'fi-in-entry-content',
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')),
|
||||
])?>">
|
||||
<<?= $wrapperTag ?> <?php if ($wrapperTag === 'a') {
|
||||
echo generate_href_html($url, $this->shouldOpenUrlInNewTab())->toHtml();
|
||||
} ?> <?= $contentAttributes->toHtml() ?>>
|
||||
<?= $html ?>
|
||||
</dd>
|
||||
</<?= $wrapperTag ?>>
|
||||
|
||||
<?= $afterContentSchema?->toHtml() ?>
|
||||
</div>
|
||||
</dd>
|
||||
|
||||
<?= $this->getChildSchema($this::BELOW_CONTENT_SCHEMA_KEY)?->toHtml() ?>
|
||||
</div>
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -32,7 +32,7 @@ trait CanOpenUrl
|
||||
? $this->evaluate($this->url, [
|
||||
'state' => $state,
|
||||
])
|
||||
: $this->evaluate($this->url);
|
||||
: null;
|
||||
}
|
||||
|
||||
if ($this->hasStateBasedUrls()) {
|
||||
|
||||
@@ -57,6 +57,8 @@ trait HasActions
|
||||
*/
|
||||
public function getAction(string | array | null $name = null): ?Action
|
||||
{
|
||||
$actions = $this->getActions();
|
||||
|
||||
if (blank($name)) {
|
||||
return $this->action;
|
||||
}
|
||||
@@ -72,7 +74,7 @@ trait HasActions
|
||||
$name = $firstName;
|
||||
}
|
||||
|
||||
$action = $this->cacheActions()[$name] ?? null;
|
||||
$action = $actions[$name] ?? null;
|
||||
|
||||
if (! $action) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user