Skip to content

Commit

Permalink
Merge pull request #21 from stvtk/main
Browse files Browse the repository at this point in the history
Fix state when multiple is enabled
  • Loading branch information
199ocero committed Jun 25, 2024
2 parents 94389e6 + 8d13c6d commit 2381559
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion resources/views/forms/components/radio-deck.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

<label class="flex cursor-pointer gap-x-3">
<input @disabled($shouldOptionBeDisabled) id="{{ $id }}-{{ $value }}"
name="{{ $id }}"
@if (! $isMultiple)
name="{{ $id }}"
@endif
type="{{ $isMultiple ? 'checkbox' : 'radio' }}"
value="{{ $value }}" wire:loading.attr="disabled"
{{ $applyStateBindingModifiers('wire:model') }}="{{ $statePath }}"
Expand Down
12 changes: 12 additions & 0 deletions src/Forms/Components/RadioDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ protected function setUp(): void
parent::setUp();

$this->default(fn (RadioDeck $component): mixed => $component->isMultiple() ? [] : null);

$this->afterStateHydrated(static function (RadioDeck $component, $state): void {
if (! $component->isMultiple()) {
return;
}

if (is_array($state)) {
return;
}

$component->state([]);
});
}

public function icons(array|Arrayable|string|Closure|null $icons): static
Expand Down

0 comments on commit 2381559

Please sign in to comment.