Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Fixed a bug where custom sources that were hidden for certain user groups weren’t available within element selector modals either. ([#17703](https://github.com/craftcms/cms/issues/17703))
- Fixed a bug where element queries weren’t returning any results if they had a param that resolved to multiple generated fields. ([#17709](https://github.com/craftcms/cms/issues/17709))
- Fixed a bug where Link fields weren’t preserving spaces within Phone and SMS link labels. ([#17707](https://github.com/craftcms/cms/issues/17707))
- Fixed a bug where disabled rows within element selector modals could contain nested focusable elements. ([#17053](https://github.com/craftcms/cms/pull/17053))

## 5.8.12 - 2025-07-29

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.

80 changes: 71 additions & 9 deletions src/web/assets/cp/src/js/BaseElementIndexView.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,26 @@ Craft.BaseElementIndexView = Garnish.Base.extend(
}
);

this.updateInitialViewForSelectedElements($elements);

this._handleEnableElements = (ev) => {
this.elementSelect.addItems(
this.filterSelectableElements($(ev.elements))
);

for (let i = 0; i < $(ev.elements).length; i++) {
const $element = $(ev.elements).eq(i);
this.enableFocusableElements($element);
}
};

this._handleDisableElements = (ev) => {
this.elementSelect.removeItems(ev.elements);

for (let i = 0; i < $(ev.elements).length; i++) {
const $element = $(ev.elements).eq(i);
this.disableFocusableElements($element);
}
};

this.elementIndex.on('enableElements', this._handleEnableElements);
Expand Down Expand Up @@ -146,30 +158,80 @@ Craft.BaseElementIndexView = Garnish.Base.extend(
}
},

filterSelectableElements: function ($elements) {
const selectable = [];

/**
* Updates the initial view for selected elements
* @param $elements
*/
updateInitialViewForSelectedElements: function ($elements) {
for (let i = 0; i < $elements.length; i++) {
const $element = $elements.eq(i);
if ($element.hasClass('disabled')) {
// remove checkbox from tab order and mark as checked
$element.find('.checkbox').attr({
tabindex: '-1',
// mark as checked
this.getElementCheckbox($element).attr({
'aria-checked': 'true',
});

// remove other focusable elements from the tab order
this.disableFocusableElements($element);
continue;
}

if (!this.canSelectElement($element)) {
$element.find('.checkbox').remove();
}
}
},

/**
* Returns selectable elements
* @param $elements Elements to filter
* @returns {jQuery} A jQuery object containing the selectable elements
*/
filterSelectableElements: function ($elements) {
const selectable = [];

for (let i = 0; i < $elements.length; i++) {
const $element = $elements.eq(i);

if (this.canSelectElement($element)) {
selectable.push($element[0]);
} else {
// make sure it doesn't have a checkbox
$element.find('.checkbox').remove();
}
}

return $(selectable);
},

/**
* Removes all focusable elements inside the given container from the focus order
* @param $container
*/
disableFocusableElements: function ($container) {
const disabledAttributes = {
tabindex: '-1',
'data-focusable': true,
};
// Disable all focusable elements inside the disabled elements
const $focusable = Garnish.getKeyboardFocusableElements($container);

if ($focusable.length) {
$focusable.attr(disabledAttributes);
}
this.getElementCheckbox($container).attr(disabledAttributes);
},

/**
* Moves all focusable elements inside the given container into the default focus order
* @param $container
*/
enableFocusableElements: function ($container) {
const $focusableElements = $container.find('[data-focusable]');

if (!$focusableElements.length) return;

$focusableElements.removeAttr('tabindex data-focusable');
this.getElementCheckbox($container).attr('tabindex', '0');
},

canSelectElement: function ($element) {
if (this.settings.canSelectElement) {
return this.settings.canSelectElement($element);
Expand Down
Loading