Skip to content

Commit 7d1af55

Browse files
authored
Merge pull request #58 from dcblogdev/update-select-style-to-match-input
enhance select component to support dynamic data and improve errors
2 parents 31d5721 + 1b236e8 commit 7d1af55

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

resources/views/components/form/select.blade.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@props([
2+
'data' => [],
23
'required' => '',
34
'name' => '',
45
'id' => '',
@@ -23,21 +24,34 @@
2324

2425
<div class="mb-5">
2526
@if ($label !='none')
26-
<x-form.label :$label :$required :$name />
27+
<label for='{{ $name }}' class='block mb-2 font-bold text-sm mb-2 text-gray-600 dark:text-gray-200'>{{ $label }} @if ($required != '') <span aria-hidden="true" class="error">*</span>@endif</label>
2728
@endif
2829
<select
2930
name='{{ $name }}'
3031
id='{{ $name }}'
3132
{{ $required }}
32-
{{ $attributes->merge(['class' => 'border border-gray-300 bg-white dark:bg-gray-500 dark:text-gray-200 py-2 px-3 w-full rounded-md shadow']) }}
33-
@error($name)
34-
aria-invalid="true"
35-
aria-description="{{ $message }}"
36-
@enderror
33+
{{ $attributes->merge([
34+
'class' => implode(' ', [
35+
'block w-full bg-white dark:bg-gray-500 dark:text-gray-200 dark:placeholder-gray-200 border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-light-blue-500 focus:border-light-blue-500 sm:text-sm',
36+
$errors->has($name) ? 'border-red-500' : 'border-gray-300',
37+
])
38+
]) }}
39+
@if(isset($errors))
40+
@error($name)
41+
aria-invalid="true"
42+
aria-description="{{ $message }}"
43+
@enderror
44+
@endif
45+
{{ $attributes }}
3746
>
3847
@if ($placeholder != '')
3948
<option value=''>{{ $placeholder }}</option>
4049
@endif
50+
@if (count($data) > 0)
51+
@foreach($data as $item)
52+
<option value="{{ $item['id'] }}">{{ $item['value'] }}</option>
53+
@endforeach
54+
@endif
4155
{{ $slot }}
4256
</select>
4357
@error($name)

0 commit comments

Comments
 (0)