Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 700dfdb

Browse files
authored
Merge pull request #16 from protonemedia/select-slot
Select slot support
2 parents 0b2b999 + 3edec77 commit 700dfdb

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-form-components` will be documented in this file
44

5+
## 2.1.0 - 2020-09-14
6+
7+
- Select elements now support a slot
8+
59
## 2.0.0 - 2020-09-09
610

711
- Added sensible 'for' attributes to the Bootstrap 4 Label components.

resources/views/bootstrap-4/form-select.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
@endif
1818

1919
{!! $attributes->merge(['class' => 'form-control ' . ($hasError($name) ? 'is-invalid' : '')]) !!}>
20-
@foreach($options as $key => $option)
20+
@forelse($options as $key => $option)
2121
<option value="{{ $key }}" @if($isSelected($key)) selected="selected" @endif>
2222
{{ $option }}
2323
</option>
24-
@endforeach
24+
@empty
25+
{!! $slot !!}
26+
@endforelse
2527
</select>
2628

2729
{!! $help ?? null !!}

resources/views/tailwind/form-select.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
{!! $attributes->merge([
1717
'class' => ($label ? 'mt-1' : '') . ' block w-full ' . ($multiple ? 'form-multiselect' : 'form-select')
1818
]) !!}>
19-
@foreach($options as $key => $option)
19+
@forelse($options as $key => $option)
2020
<option value="{{ $key }}" @if($isSelected($key)) selected="selected" @endif>
2121
{{ $option }}
2222
</option>
23-
@endforeach
23+
@empty
24+
{!! $slot !!}
25+
@endforelse
2426
</select>
2527
</label>
2628

tests/Feature/SelectSlotTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace ProtoneMedia\LaravelFormComponents\Tests\Feature;
4+
5+
use ProtoneMedia\LaravelFormComponents\Tests\TestCase;
6+
7+
class SelectSlotTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_shows_the_slot_if_the_options_are_empty()
11+
{
12+
$this->registerTestRoute('select-slot');
13+
14+
$this->visit('/select-slot')
15+
->seeElement('option[value="a"]')
16+
->seeElement('option[value="b"]')
17+
->seeElement('option[value="c"]');
18+
}
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<x-form>
2+
<x-form-select name="select">
3+
<option value="a">A</option>
4+
<option value="b">B</option>
5+
<option value="c">C</option>
6+
</x-form-select>
7+
8+
<x-form-submit />
9+
</x-form>

0 commit comments

Comments
 (0)