Skip to content

Commit

Permalink
Merge pull request #11565 from craftcms/feature/pagination-focus
Browse files Browse the repository at this point in the history
Feature/pagination focus
  • Loading branch information
brandonkelly authored Aug 11, 2022
2 parents c6f04cf + a40fc19 commit 066e688
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added `craft\web\Controller::getCurrentUser()`. ([#11754](https://github.com/craftcms/cms/pull/11754))

### Changed
- Improved the control panel accessibility. ([#11565](https://github.com/craftcms/cms/pull/11565))
- `users/session-info` responses now include a `csrfTokenName` key. ([#11706](https://github.com/craftcms/cms/pull/11706))
- `craft\services\Search::EVENT_BEFORE_INDEX_KEYWORDS` is now cancellable by setting `$event->isValid` to `false`. ([#11705](https://github.com/craftcms/cms/discussions/11705))
- `checkboxSelect` inputs without `showAllOption: true` now post an empty value if no options were selected. ([#11748](https://github.com/craftcms/cms/issues/11748))
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.

11 changes: 8 additions & 3 deletions src/web/assets/cp/src/js/BaseElementIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ Craft.BaseElementIndex = Garnish.Base.extend(
return params;
},

updateElements: function (preservePagination) {
updateElements: function (preservePagination, pageChanged) {
// Ignore if we're not fully initialized yet
if (!this.initialized) {
return;
Expand Down Expand Up @@ -836,6 +836,11 @@ Craft.BaseElementIndex = Garnish.Base.extend(
: this.$main
).scrollTop(0);
this._updateView(params, response.data);

if (pageChanged) {
const $elementContainer = this.view.getElementContainer();
Garnish.firstFocusableElement($elementContainer).trigger('focus');
}
})
.catch((e) => {
this.setIndexAvailable();
Expand Down Expand Up @@ -1979,7 +1984,7 @@ Craft.BaseElementIndex = Garnish.Base.extend(
this.removeListener($prevBtn, 'click');
this.removeListener($nextBtn, 'click');
this.setPage(this.page - 1);
this.updateElements(true);
this.updateElements(true, true);
});
}

Expand All @@ -1988,7 +1993,7 @@ Craft.BaseElementIndex = Garnish.Base.extend(
this.removeListener($prevBtn, 'click');
this.removeListener($nextBtn, 'click');
this.setPage(this.page + 1);
this.updateElements(true);
this.updateElements(true, true);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/garnish/dist/garnish.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/web/assets/garnish/src/Garnish.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ Garnish = $.extend(Garnish, {
return $(container).find(':focus').length > 0;
},

/**
* Gets the first focusable element inside a container
* @param {Object} container
*/
firstFocusableElement: function (container) {
return $(container).find(':focusable').first();
},

/**
* Traps focus within a container, so when focus is tabbed out of it, it’s cycled back into it.
* @param {Object} container
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/js/app.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

0 comments on commit 066e688

Please sign in to comment.