Skip to content

Commit ad8eb5f

Browse files
committed
Hide bulk actions on empty
1 parent e5952de commit ad8eb5f

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [1.11.0] - 2021-06-23
8+
9+
### Added
10+
11+
- Added $hideBulkActionsOnEmpty to hide the bulk actions dropdown until something is selected.
12+
713
## [1.10.3] - 2021-06-22
814

915
### Added

resources/views/bootstrap-4/includes/bulk-actions.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if ($bulkActionsEnabled && count($bulkActions))
1+
@if ($this->showBulkActionsDropdown)
22
<div class="mb-3 mb-md-0">
33
<div class="dropdown d-block d-md-inline">
44
<button class="btn dropdown-toggle d-block w-100 d-md-inline" type="button" id="bulkActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

resources/views/bootstrap-5/includes/bulk-actions.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if ($bulkActionsEnabled && count($bulkActions))
1+
@if ($this->showBulkActionsDropdown)
22
<div class="mb-3 mb-md-0">
33
<div class="dropdown d-block d-md-inline">
44
<button class="btn dropdown-toggle d-block w-100 d-md-inline" type="button" id="bulkActions" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

resources/views/tailwind/includes/bulk-actions.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if ($bulkActionsEnabled && count($bulkActions))
1+
@if ($this->showBulkActionsDropdown)
22
<div class="w-full md:w-auto mb-4 md:mb-0">
33
<div
44
x-data="{ open: false }"

src/Traits/WithBulkActions.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ trait WithBulkActions
1616
public bool $selectAll = false;
1717
public $selected = [];
1818
public array $bulkActions = [];
19+
public bool $hideBulkActionsOnEmpty = false;
1920

2021
public function renderingWithBulkActions(): void
2122
{
@@ -89,4 +90,25 @@ public function getSelectedKeysProperty(): array
8990
{
9091
return $this->selectedKeys();
9192
}
93+
94+
public function getShowBulkActionsDropdownProperty(): bool
95+
{
96+
$showBulkActions = false;
97+
98+
if ($this->bulkActionsEnabled) {
99+
if (count($this->bulkActions)) {
100+
$showBulkActions = true;
101+
}
102+
103+
if ($this->hideBulkActionsOnEmpty) {
104+
if (count($this->selected)) {
105+
$showBulkActions = true;
106+
} else {
107+
$showBulkActions = false;
108+
}
109+
}
110+
}
111+
112+
return $showBulkActions;
113+
}
92114
}

0 commit comments

Comments
 (0)