livewire / flux

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

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

Closed lucasromanojf closed 4 days ago

lucasromanojf commented 1 week ago

Hello,

When using a flux:select which has an option of value zero, if I select this option, the binded model is set with the option label and not with zero. 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 "Option 0" and not to "0" (zero).

<?php

use function Livewire\Volt\{state};

state([
    'value' => '',
    'options' => [
        ['label' => 'Option 0', 'value' => '0'],
        ['label' => 'Option 1', 'value' => '1'],
        ['label' => 'Option 2', 'value' => '2'],
    ]
]);

?>

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

    Selected option: {{ $value }}
</div>
ThomasEnssner commented 1 week ago

Same issue here.

As long as you are using <flux:select ...> without a variant. You can use regular <option value="0">myLabel</option> as workaround.

calebporzio commented 4 days ago

Thanks for this, there was a loose equality check on the $value prop in the option component instead of checking for a strict null.

Will be fixed in the next release. Thanks.