Skip to content

Commit

Permalink
Merge pull request #16217 from craftcms/bugfix/16213-sortable-checkbo…
Browse files Browse the repository at this point in the history
…x-menubtn-show-hide

Bugfix/16213 sortable checkbox menubtn show hide
  • Loading branch information
brandonkelly authored Nov 27, 2024
2 parents 053c8e1 + 4e56ccf commit 4ac4d02
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixed a bug where element slideouts had Save buttons even if the user didn’t have permission to save the element. ([#16205](https://github.com/craftcms/cms/pull/16205))
- Fixed a bug where pagination wasn’t working properly on the Entry Types index page when searching. ([#16204](https://github.com/craftcms/cms/issues/16204))
- Fixed an error that could occur when saving an element with an invalid Link field value. ([#16212](https://github.com/craftcms/cms/issues/16212))
- Fixed a bug where sortable checkbox selects were displaying menu buttons even when only one option was selected. ([#16213](https://github.com/craftcms/cms/issues/16213))

## 5.5.3 - 2024-11-22

Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions src/web/assets/cp/src/js/SortableCheckboxSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,26 @@ Craft.SortableCheckboxSelect.Item = Garnish.Base.extend({
}
});

const allCheckedSiblings = this.getAllCheckedSiblings();
// if there are no other checked siblings, hide current item's action menu btn
if (allCheckedSiblings.length == 0) {
this.$actionMenuBtn.hide();
} else if (allCheckedSiblings.length == 1) {
// if there's only one other checked sibling,
// we need to show that sibling's action menu btn as it would have been hidden so far
$(allCheckedSiblings[0]).find('.btn.action-btn').show();
}

this.$item.trigger('checked');
},

onUncheck: function () {
const allCheckedSiblings = this.getAllCheckedSiblings();
// if there's only one other checked sibling, hide that sibling's action menu btn
if (allCheckedSiblings.length == 1) {
$(allCheckedSiblings[0]).find('.btn.action-btn').hide();
}

this.$moveHandle?.addClass('disabled');
this.$actionMenuBtn?.remove();
this.$actionMenu?.remove();
Expand All @@ -149,6 +165,12 @@ Craft.SortableCheckboxSelect.Item = Garnish.Base.extend({
return $item.length ? $item : null;
},

getAllCheckedSiblings: function () {
return this.$item.siblings(
'.checkbox-select-item:not(.all):has(input[type=checkbox]:checked)'
);
},

moveUp: function () {
const $prev = this.getPrevCheckedItem();
if ($prev) {
Expand Down

0 comments on commit 4ac4d02

Please sign in to comment.