diff --git a/src/Components/FormSelect.php b/src/Components/FormSelect.php index 0142ec8..12b0600 100644 --- a/src/Components/FormSelect.php +++ b/src/Components/FormSelect.php @@ -45,7 +45,9 @@ public function __construct( if ($this->isNotWired()) { $inputName = static::convertBracketsToDots(Str::before($name, '[]')); - $default = $this->getBoundValue($bind, $inputName) ?: $default; + if (is_null($default)) { + $default = $this->getBoundValue($bind, $inputName); + } $this->selectedKey = old($inputName, $default); diff --git a/tests/Feature/BindTest.php b/tests/Feature/BindTest.php index 884cfea..59f8281 100644 --- a/tests/Feature/BindTest.php +++ b/tests/Feature/BindTest.php @@ -96,7 +96,7 @@ public function it_overrides_the_default_value() $this->visit('/default-values-with-bound-target') ->seeElement('input[name="input"][value="a"]') ->seeInElement('textarea[name="textarea"]', 'b') - ->seeElement('option[value="c"]:selected') + ->seeElement('option[value="f"]:selected') ->seeElement('input[name="checkbox"]') ->dontSeeElement('input[name="checkbox"]:checked') ->seeElement('input[name="radio"]') @@ -111,7 +111,7 @@ public function it_overrides_the_default_value_when_nested() $this->visit('/default-values-with-nested-bound-target') ->seeElement('input[name="nested[input]"][value="a"]') ->seeInElement('textarea[name="nested[textarea]"]', 'b') - ->seeElement('select[name="nested[select]"] > option[value="c"]:selected') + ->seeElement('select[name="nested[select]"] > option[value="f"]:selected') ->seeElement('input[name="nested[checkbox]"]') ->dontSeeElement('input[name="nested[checkbox]"]:checked') ->seeElement('input[name="nested[radio]"]') diff --git a/tests/Feature/SelectBooleanValueTest.php b/tests/Feature/SelectBooleanValueTest.php new file mode 100644 index 0000000..c08f927 --- /dev/null +++ b/tests/Feature/SelectBooleanValueTest.php @@ -0,0 +1,28 @@ +registerTestRoute('select-boolean-value'); + + $this->visit('/select-boolean-value') + ->seeElement('option[value="1"]') + ->seeElement('option[value="0"]'); + } + + /** @test */ + public function it_shows_the_false_value_selected() + { + $this->registerTestRoute('select-boolean-value'); + + $this->visit('/select-boolean-value') + ->seeElement('option[value="1"]') + ->seeElement('option[value="0"][selected="selected"]'); + } +} diff --git a/tests/Feature/views/default-values-with-bound-target.blade.php b/tests/Feature/views/default-values-with-bound-target.blade.php index ba9fd9f..efa3b39 100644 --- a/tests/Feature/views/default-values-with-bound-target.blade.php +++ b/tests/Feature/views/default-values-with-bound-target.blade.php @@ -12,7 +12,7 @@ @bind($target) - + diff --git a/tests/Feature/views/default-values-with-nested-bound-target.blade.php b/tests/Feature/views/default-values-with-nested-bound-target.blade.php index 7dace12..17973b5 100644 --- a/tests/Feature/views/default-values-with-nested-bound-target.blade.php +++ b/tests/Feature/views/default-values-with-nested-bound-target.blade.php @@ -14,7 +14,7 @@ @bind($target) - + diff --git a/tests/Feature/views/select-boolean-value.blade.php b/tests/Feature/views/select-boolean-value.blade.php new file mode 100644 index 0000000..11877d9 --- /dev/null +++ b/tests/Feature/views/select-boolean-value.blade.php @@ -0,0 +1,7 @@ + + @bind(['select' => '0']) + + @endbind + + +