Skip to content

Commit ab35e6c

Browse files
authored
Enable InputAttributes for SelectFilter (rappasoft#2133)
* Enable InputAttributes for SelectFilter * Fix styling --------- Co-authored-by: lrljoe <[email protected]>
1 parent 4bb6b3d commit ab35e6c

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

resources/views/components/tools/filters/select.blade.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
'rounded-md shadow-sm' => $isTailwind,
66
'inline' => $isBootstrap,
77
])>
8-
<select {!! $filter->getWireMethod('filterComponents.'.$filter->getKey()) !!}
9-
wire:key="{{ $filter->generateWireKey($tableName, 'select') }}"
10-
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
11-
@class([
12-
'block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600' => $isTailwind,
13-
'form-control' => $isBootstrap4,
14-
'form-select' => $isBootstrap5,
8+
<select {!! $filter->getWireMethod('filterComponents.'.$filter->getKey()) !!} {{
9+
$filterInputAttributes->merge()
10+
->class([
11+
'block w-full transition duration-150 ease-in-out rounded-md shadow-sm focus:ring focus:ring-opacity-50' => $isTailwind && ($filterInputAttributes['default-styling'] ?? true),
12+
'border-gray-300 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-gray-800 dark:text-white dark:border-gray-600' => $isTailwind && ($filterInputAttributes['default-colors'] ?? true),
13+
'form-control' => $isBootstrap4 && ($filterInputAttributes['default-styling'] ?? true),
14+
'form-select' => $isBootstrap5 && ($filterInputAttributes['default-styling'] ?? true),
1515
])
16-
>
16+
->except(['default-styling','default-colors'])
17+
}}>
1718
@foreach($filter->getOptions() as $key => $value)
1819
@if (is_iterable($value))
1920
<optgroup label="{{ $key }}">

src/Views/Filters/SelectFilter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,15 @@ public function getFilterPillValue($value): array|string|bool|null
4949
->mapWithKeys(fn ($options, $optgroupLabel) => is_iterable($options) ? $options : [$optgroupLabel => $options])[$value]
5050
?? null;
5151
}
52+
53+
protected function getCoreInputAttributes(): array
54+
{
55+
$attributes = array_merge(parent::getCoreInputAttributes(),
56+
[
57+
'wire:key' => $this->generateWireKey($this->getGenericDisplayData()['tableName'], 'select'),
58+
]);
59+
ksort($attributes);
60+
61+
return $attributes;
62+
}
5263
}

tests/Unit/Views/Filters/SelectFilterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ protected function setUp(): void
1313
{
1414
parent::setUp();
1515
self::$filterInstance = SelectFilter::make('Active')->options(['Cartman', 'Tux', 'May', 'Ben', 'Chico']);
16+
self::$extraFilterInputAttributes = [
17+
'wire:key' => 'test123-filter-select-active',
18+
];
19+
1620
}
1721

1822
public function test_array_setup(): array

0 commit comments

Comments
 (0)