Skip to content

[BUGFIX] Fix the checkbox sync select-all state and preserve selection - #2145

Open
aleRibeiro0209 wants to merge 1 commit into
Power-Components:7.xfrom
aleRibeiro0209:bugfix/PG-fix-select-all-checkbox-state
Open

aleRibeiro0209 wants to merge 1 commit into
Power-Components:7.xfrom
aleRibeiro0209:bugfix/PG-fix-select-all-checkbox-state

Conversation

@aleRibeiro0209

Copy link
Copy Markdown
Contributor

⚡ PowerGrid - Pull Request

  • Bug fix
  • Enhancement
  • New feature
  • Breaking change

Description

Fixes the "select all" checkbox so its state always reflects the actual row selection, and prevents the selection from being cleared when the per-page size changes.

Previously the header checkbox relied on the two-way bound checkboxAll property (wire:model + wire:click), which could desync from the real state of the row checkboxes and never rendered an indeterminate state. On top of that, changing the per-page size triggered a page reset that wiped the current selection.

Header checkbox driven by the real row state — a new pgSelectAll Alpine component inspects the row checkboxes and updates the header accordingly:

<input
    x-data="pgSelectAll"
    class="{{ theme('table.checkbox.input') }}"
    type="checkbox"
    x-on:change="$wire.selectCheckboxAll($event.target.checked)"
>

- checked when all enabled rows are selected.
- indeterminate when some (but not all) rows are selected.
- Re-evaluated on every row change and after each Livewire commit.

Explicit intent sent to the server — the front-end now passes the checked value instead of depending on the two-way bound property:

public function selectCheckboxAll(?bool $checked = null): void
{
    if ($checked !== null) {
        $this->checkboxAll = $checked;
    }
    // ...
}

Implementation notes:
- New resources/js/components/pg-select-all.js (registered in components/index.js) manages the checked/indeterminate state and listens to a pg-select-all:refresh event dispatched after each Livewire commit.
- checkbox-all.blade.php (shared structure view + tailwind view) swaps wire:model/wire:click for x-data="pgSelectAll" + x-on:change="$wire.selectCheckboxAll($event.target.checked)".
- Checkbox::selectCheckboxAll() accepts an optional ?bool $checked to receive the explicit intent from the front-end.
- PowerGridComponent::resetToFirstPage() short-circuits when already on page 1, so changing the per-page size no longer clears the current selection.
- Added tests covering the page-1 short-circuit, selection preserved across per-page changes, and the explicit checked argument.

Related Issue(s):

Documentation

 This PR requires Documentation update?

- [ ] Yes
- [x] No
- [ ] I have already submitted a Documentation pull request.

@aleRibeiro0209 aleRibeiro0209 changed the title Fix the checkbox sync select-all state and preserve selection [BUGFIX] Fix the checkbox sync select-all state and preserve selection Sep 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant