livewire / flux

The official Livewire UI component library
https://fluxui.dev
488 stars 42 forks source link

[1.0.23] flux:select: option with empty value sets the option label as value and not the empty value #665

Closed lucasromanojf closed 4 days ago

lucasromanojf commented 1 week ago

Hello,

When using a flux:select which has an option of empty value, if I select this option, the binded model is set with the option label and not with an empty string. It was working fine on previous versions.

You can see in the following example that, when selecting the first option, $value variable is set to "Select one" and not to "" (empty).

<?php

use function Livewire\Volt\{state};

state([
    'value' => '',
    'options' => [
        ['value' => '', 'label' => 'Select one'],
        ['value' => '1', 'label' => 'Option 1'],
        ['value' => '2', 'label' => 'Option 2'],
        ['value' => '3', 'label' => 'Option 3'],
    ],
])->url();

?>

<div>
    <flux:select variant="listbox" wire:model.live="value">
        @foreach ($options as $option)
            <flux:option :key="$option['value']" wire:key="{{ $option['value'] }}" :value="$option['value']">
                {{ $option['label'] }}
            </flux:option>
        @endforeach
    </flux:select>

    Selected option value: {{ $value }}
</div>
calebporzio commented 4 days ago

Ah good catch, yeah there were two bugs that worked in combination on this one. Fixed and will be in the next release. Thanks!