Skip to content

Commit 74f2287

Browse files
committed
adding properties to compute model options on search property. currently set to .debounce.250ms in themes, this allows use to control those options without override the themes.
1 parent eea59ca commit 74f2287

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

resources/views/bootstrap-4/includes/search.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if ($showSearch)
22
<div class="mb-3 mb-md-0 input-group">
33
<input
4-
wire:model.debounce.250ms="filters.search"
4+
wire:model{{ $this->searchFilterOptions }}="filters.search"
55
placeholder="{{ __('Search') }}"
66
type="text"
77
class="form-control"

resources/views/bootstrap-5/includes/search.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if ($showSearch)
22
<div class="mb-3 mb-md-0 input-group">
33
<input
4-
wire:model.debounce.250ms="filters.search"
4+
wire:model{{ $this->searchFilterOptions }}="filters.search"
55
placeholder="{{ __('Search') }}"
66
type="text"
77
class="form-control"

resources/views/tailwind/includes/search.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if ($showSearch)
22
<div class="flex rounded-md shadow-sm">
33
<input
4-
wire:model.debounce.250ms="filters.search"
4+
wire:model{{ $this->searchFilterOptions }}="filters.search"
55
placeholder="{{ __('Search') }}"
66
type="text"
77
class="flex-1 shadow-sm border-cool-gray-300 block w-full transition duration-150 ease-in-out sm:text-sm sm:leading-5 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo @if (isset($filters['search']) && strlen($filters['search'])) rounded-none rounded-l-md @else rounded-md @endif"

src/Traits/WithFilters.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,62 @@
77
*/
88
trait WithFilters
99
{
10+
/**
11+
* Filter values
12+
*
13+
* @var array
14+
*/
1015
public array $filters = [];
16+
17+
/**
18+
* Map filter names
19+
*
20+
* @var array
21+
*/
1122
public array $filterNames = [];
23+
24+
/**
25+
* Default filters
26+
*
27+
* @var array|null[]
28+
*/
1229
public array $baseFilters = [
1330
'search' => null,
1431
];
1532

33+
/**
34+
* @var int
35+
*/
36+
public ?int $searchFilterDebounce = null;
37+
38+
/**
39+
* @var bool
40+
*/
41+
public ?bool $searchFilterLazy = null;
42+
43+
/**
44+
* @var bool
45+
*/
46+
public ?bool $searchFilterDefer = null;
47+
48+
/**
49+
* Build livewire model options for the search input
50+
*
51+
* @return string
52+
*/
53+
public function getSearchFilterOptionsProperty()
54+
{
55+
if ($this->searchFilterLazy) {
56+
return '.lazy';
57+
} elseif($this->searchFilterDefer) {
58+
return '.defer';
59+
}elseif($this->searchFilterDebounce){
60+
return '.debounce.' . $this->searchFilterDebounce . 'ms';
61+
}else{
62+
return '';
63+
}
64+
}
65+
1666
public function resetFilters(): void
1767
{
1868
$search = $this->filters['search'] ?? null;

0 commit comments

Comments
 (0)