Skip to content

Commit

Permalink
Merge pull request #13 from chrisabey84/hide-select-placeholder
Browse files Browse the repository at this point in the history
Hide select placeholder
  • Loading branch information
chrisrhymes authored Sep 5, 2022
2 parents e9b773c + 127c317 commit 7595a30
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions resources/views/components/horizontal-select.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@props(['label', 'name' => '', 'options' => [], 'value' => '', 'required' => false])
@props(['label', 'name' => '', 'options' => [], 'value' => '', 'required' => false, 'hidePlaceholderFromSelection' => false])
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label" for="{{ \Illuminate\Support\Str::camel($name) }}">{{ $label}}</label>
Expand All @@ -12,7 +12,7 @@
@if($required) required @endif
>
@if($attributes->has('placeholder'))
<option value="">{{ $attributes->get('placeholder') }}</option>
<option value="" @if($hidePlaceholderFromSelection) hidden @endif>{{ $attributes->get('placeholder') }}</option>
@endif
@foreach($options as $key => $option)
<option value="{{ $key }}" @if($key == $value) selected @endif>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@props(['label', 'name' => '', 'options' => [], 'value' => '', 'required' => false])
@props(['label', 'name' => '', 'options' => [], 'value' => '', 'required' => false, 'hidePlaceholderFromSelection' => false])
<div class="field">
<label class="label" for="{{ \Illuminate\Support\Str::camel($name) }}">{{ $label }}</label>
<div class="control">
Expand All @@ -9,7 +9,7 @@
@if($required) required @endif
>
@if($attributes->has('placeholder'))
<option value="">{{ $attributes->get('placeholder') }}</option>
<option value="" @if($hidePlaceholderFromSelection) hidden @endif>{{ $attributes->get('placeholder') }}</option>
@endif
@foreach($options as $key => $option)
<option value="{{ $key }}" @if($key === $value) selected @endif>
Expand Down
14 changes: 13 additions & 1 deletion tests/Components/HorizontalSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public function horizontal_select_render_placeholder_when_set()
['label' => 'The Input Label', 'name' => 'test', 'options' => ['first' => 'First option'], 'placeholder' => 'Select an option']
);

$view->assertSee('<option value="">Select an option</option>', false);
$view->assertSee('<option value="" >Select an option</option>', false);
}

/** @test */
public function horizontal_select_render_placeholder_but_hides_it_from_selection_when_set()
{
$view = $this->withViewErrors([])
->blade(
'<x-bbui::'.$this->component.' :label="$label" :name="$name" :options="$options" :placeholder="$placeholder" :hide-placeholder-from-selection="$hidePlaceholderFromSelection"></x-bbui::'.$this->component.'>',
['label' => 'The Input Label', 'name' => 'test', 'options' => ['first' => 'First option'], 'placeholder' => 'Select an option', 'hidePlaceholderFromSelection' => true]
);

$view->assertSee('<option value="" hidden >Select an option</option>', false);
}
}
14 changes: 13 additions & 1 deletion tests/Components/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public function select_render_placeholder_when_set()
['label' => 'The Input Label', 'name' => 'test', 'options' => ['first' => 'First option'], 'placeholder' => 'Select an option']
);

$view->assertSee('<option value="">Select an option</option>', false);
$view->assertSee('<option value="" >Select an option</option>', false);
}

/** @test */
public function select_render_placeholder_but_hides_it_from_selection_when_set()
{
$view = $this->withViewErrors([])
->blade(
'<x-bbui::'.$this->component.' :label="$label" :name="$name" :options="$options" :placeholder="$placeholder" :hide-placeholder-from-selection="$hidePlaceholderFromSelection"></x-bbui::'.$this->component.'>',
['label' => 'The Input Label', 'name' => 'test', 'options' => ['first' => 'First option'], 'placeholder' => 'Select an option', 'hidePlaceholderFromSelection' => true]
);

$view->assertSee('<option value="" hidden >Select an option</option>', false);
}
}

0 comments on commit 7595a30

Please sign in to comment.