Skip to content

Commit

Permalink
Enable InputAttributes for SelectFilter (#2133)
Browse files Browse the repository at this point in the history
* Enable InputAttributes for SelectFilter

* Fix styling

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Dec 24, 2024
1 parent 4bb6b3d commit ab35e6c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
17 changes: 9 additions & 8 deletions resources/views/components/tools/filters/select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
'rounded-md shadow-sm' => $isTailwind,
'inline' => $isBootstrap,
])>
<select {!! $filter->getWireMethod('filterComponents.'.$filter->getKey()) !!}
wire:key="{{ $filter->generateWireKey($tableName, 'select') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
@class([
'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,
'form-control' => $isBootstrap4,
'form-select' => $isBootstrap5,
<select {!! $filter->getWireMethod('filterComponents.'.$filter->getKey()) !!} {{
$filterInputAttributes->merge()
->class([
'block w-full transition duration-150 ease-in-out rounded-md shadow-sm focus:ring focus:ring-opacity-50' => $isTailwind && ($filterInputAttributes['default-styling'] ?? true),
'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),
'form-control' => $isBootstrap4 && ($filterInputAttributes['default-styling'] ?? true),
'form-select' => $isBootstrap5 && ($filterInputAttributes['default-styling'] ?? true),
])
>
->except(['default-styling','default-colors'])
}}>
@foreach($filter->getOptions() as $key => $value)
@if (is_iterable($value))
<optgroup label="{{ $key }}">
Expand Down
11 changes: 11 additions & 0 deletions src/Views/Filters/SelectFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,15 @@ public function getFilterPillValue($value): array|string|bool|null
->mapWithKeys(fn ($options, $optgroupLabel) => is_iterable($options) ? $options : [$optgroupLabel => $options])[$value]
?? null;
}

protected function getCoreInputAttributes(): array
{
$attributes = array_merge(parent::getCoreInputAttributes(),
[
'wire:key' => $this->generateWireKey($this->getGenericDisplayData()['tableName'], 'select'),
]);
ksort($attributes);

return $attributes;
}
}
4 changes: 4 additions & 0 deletions tests/Unit/Views/Filters/SelectFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ protected function setUp(): void
{
parent::setUp();
self::$filterInstance = SelectFilter::make('Active')->options(['Cartman', 'Tux', 'May', 'Ben', 'Chico']);
self::$extraFilterInputAttributes = [
'wire:key' => 'test123-filter-select-active',
];

}

public function test_array_setup(): array
Expand Down

0 comments on commit ab35e6c

Please sign in to comment.