diff --git a/packages/forms/src/Components/Concerns/HasExtraInputAttributes.php b/packages/forms/src/Components/Concerns/HasExtraInputAttributes.php index cccd4f6b6b..761500520d 100644 --- a/packages/forms/src/Components/Concerns/HasExtraInputAttributes.php +++ b/packages/forms/src/Components/Concerns/HasExtraInputAttributes.php @@ -8,16 +8,20 @@ use Illuminate\View\ComponentAttributeBag; trait HasExtraInputAttributes { /** - * @var array | Closure + * @var array | Closure> */ - protected array | Closure $extraInputAttributes = []; + protected array $extraInputAttributes = []; /** * @param array | Closure $attributes */ - public function extraInputAttributes(array | Closure $attributes): static + public function extraInputAttributes(array | Closure $attributes, bool $merge = false): static { - $this->extraInputAttributes = $attributes; + if ($merge) { + $this->extraInputAttributes[] = $attributes; + } else { + $this->extraInputAttributes = [$attributes]; + } return $this; } @@ -27,7 +31,13 @@ trait HasExtraInputAttributes */ public function getExtraInputAttributes(): array { - return $this->evaluate($this->extraInputAttributes); + $temporaryAttributeBag = new ComponentAttributeBag(); + + foreach ($this->extraInputAttributes as $extraInputAttributes) { + $temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraInputAttributes)); + } + + return $temporaryAttributeBag->getAttributes(); } public function getExtraInputAttributeBag(): ComponentAttributeBag diff --git a/packages/forms/src/Components/DateTimePicker.php b/packages/forms/src/Components/DateTimePicker.php index 13654fc064..6ea70a7137 100644 --- a/packages/forms/src/Components/DateTimePicker.php +++ b/packages/forms/src/Components/DateTimePicker.php @@ -28,9 +28,9 @@ class DateTimePicker extends Field protected string | Closure | null $displayFormat = null; /** - * @var array | Closure + * @var array | Closure> */ - protected array | Closure $extraTriggerAttributes = []; + protected array $extraTriggerAttributes = []; protected int | null $firstDayOfWeek = null; @@ -148,9 +148,13 @@ class DateTimePicker extends Field /** * @param array | Closure $attributes */ - public function extraTriggerAttributes(array | Closure $attributes): static + public function extraTriggerAttributes(array | Closure $attributes, bool $merge = false): static { - $this->extraTriggerAttributes = $attributes; + if ($merge) { + $this->extraAttributes[] = $attributes; + } else { + $this->extraAttributes = [$attributes]; + } return $this; } @@ -347,7 +351,13 @@ class DateTimePicker extends Field */ public function getExtraTriggerAttributes(): array { - return $this->evaluate($this->extraTriggerAttributes); + $temporaryAttributeBag = new ComponentAttributeBag(); + + foreach ($this->extraTriggerAttributes as $extraTriggerAttributes) { + $temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraTriggerAttributes)); + } + + return $temporaryAttributeBag->getAttributes(); } public function getExtraTriggerAttributeBag(): ComponentAttributeBag diff --git a/packages/support/src/Concerns/HasExtraAlpineAttributes.php b/packages/support/src/Concerns/HasExtraAlpineAttributes.php index 19bf02852d..810ce787e3 100644 --- a/packages/support/src/Concerns/HasExtraAlpineAttributes.php +++ b/packages/support/src/Concerns/HasExtraAlpineAttributes.php @@ -8,16 +8,20 @@ use Illuminate\View\ComponentAttributeBag; trait HasExtraAlpineAttributes { /** - * @var array | Closure + * @var array | Closure> */ - protected array | Closure $extraAlpineAttributes = []; + protected array $extraAlpineAttributes = []; /** * @param array | Closure $attributes */ - public function extraAlpineAttributes(array | Closure $attributes): static + public function extraAlpineAttributes(array | Closure $attributes, bool $merge = false): static { - $this->extraAlpineAttributes = $attributes; + if ($merge) { + $this->extraAlpineAttributes[] = $attributes; + } else { + $this->extraAlpineAttributes = [$attributes]; + } return $this; } @@ -27,7 +31,13 @@ trait HasExtraAlpineAttributes */ public function getExtraAlpineAttributes(): array { - return $this->evaluate($this->extraAlpineAttributes); + $temporaryAttributeBag = new ComponentAttributeBag(); + + foreach ($this->extraAlpineAttributes as $extraAlpineAttributes) { + $temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraAlpineAttributes)); + } + + return $temporaryAttributeBag->getAttributes(); } public function getExtraAlpineAttributeBag(): ComponentAttributeBag diff --git a/packages/support/src/Concerns/HasExtraAttributes.php b/packages/support/src/Concerns/HasExtraAttributes.php index 09b033957a..b01569a444 100644 --- a/packages/support/src/Concerns/HasExtraAttributes.php +++ b/packages/support/src/Concerns/HasExtraAttributes.php @@ -8,16 +8,20 @@ use Illuminate\View\ComponentAttributeBag; trait HasExtraAttributes { /** - * @var array | Closure + * @var array | Closure> */ - protected array | Closure $extraAttributes = []; + protected array $extraAttributes = []; /** * @param array | Closure $attributes */ - public function extraAttributes(array | Closure $attributes): static + public function extraAttributes(array | Closure $attributes, bool $merge = false): static { - $this->extraAttributes = $attributes; + if ($merge) { + $this->extraAttributes[] = $attributes; + } else { + $this->extraAttributes = [$attributes]; + } return $this; } @@ -27,7 +31,13 @@ trait HasExtraAttributes */ public function getExtraAttributes(): array { - return $this->evaluate($this->extraAttributes); + $temporaryAttributeBag = new ComponentAttributeBag(); + + foreach ($this->extraAttributes as $extraAttributes) { + $temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraAttributes)); + } + + return $temporaryAttributeBag->getAttributes(); } public function getExtraAttributeBag(): ComponentAttributeBag diff --git a/packages/tables/src/Columns/Concerns/HasExtraHeaderAttributes.php b/packages/tables/src/Columns/Concerns/HasExtraHeaderAttributes.php index d08a1bb44d..d91a6deac3 100644 --- a/packages/tables/src/Columns/Concerns/HasExtraHeaderAttributes.php +++ b/packages/tables/src/Columns/Concerns/HasExtraHeaderAttributes.php @@ -8,16 +8,20 @@ use Illuminate\View\ComponentAttributeBag; trait HasExtraHeaderAttributes { /** - * @var array | Closure + * @var array */ - protected array | Closure $extraHeaderAttributes = []; + protected array $extraHeaderAttributes = []; /** - * @param array | Closure $attributes + * @param array | Closure> $attributes */ - public function extraHeaderAttributes(array | Closure $attributes): static + public function extraHeaderAttributes(array | Closure $attributes, bool $merge = false): static { - $this->extraHeaderAttributes = $attributes; + if ($merge) { + $this->extraHeaderAttributes[] = $attributes; + } else { + $this->extraHeaderAttributes = [$attributes]; + } return $this; } @@ -27,7 +31,18 @@ trait HasExtraHeaderAttributes */ public function getExtraHeaderAttributes(): array { - return $this->evaluate($this->extraHeaderAttributes); + $temporaryAttributeBag = new ComponentAttributeBag(); + + foreach ($this->extraHeaderAttributes as $extraHeaderAttributes) { + $temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraHeaderAttributes)); + } + + return $temporaryAttributeBag->getAttributes(); + } + + public function getExtraHeaderAttributeBag(): ComponentAttributeBag + { + return new ComponentAttributeBag($this->getExtraHeaderAttributes()); } public function getExtraHeaderAttributeBag(): ComponentAttributeBag diff --git a/packages/tables/src/Columns/ImageColumn.php b/packages/tables/src/Columns/ImageColumn.php index 8662463c3d..bd339df5b5 100644 --- a/packages/tables/src/Columns/ImageColumn.php +++ b/packages/tables/src/Columns/ImageColumn.php @@ -29,9 +29,9 @@ class ImageColumn extends Column protected int | string | Closure | null $width = null; /** - * @var array | Closure + * @var array | Closure> */ - protected array | Closure $extraImgAttributes = []; + protected array $extraImgAttributes = []; protected function setUp(): void { @@ -197,9 +197,13 @@ class ImageColumn extends Column /** * @param array | Closure $attributes */ - public function extraImgAttributes(array | Closure $attributes): static + public function extraImgAttributes(array | Closure $attributes, bool $merge = false): static { - $this->extraImgAttributes = $attributes; + if ($merge) { + $this->extraImgAttributes[] = $attributes; + } else { + $this->extraImgAttributes = [$attributes]; + } return $this; } @@ -209,7 +213,13 @@ class ImageColumn extends Column */ public function getExtraImgAttributes(): array { - return $this->evaluate($this->extraImgAttributes); + $temporaryAttributeBag = new ComponentAttributeBag(); + + foreach ($this->extraImgAttributes as $extraImgAttributes) { + $temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraImgAttributes)); + } + + return $temporaryAttributeBag->getAttributes(); } public function getExtraImgAttributeBag(): ComponentAttributeBag