Keyboard navigation (results:next) does not advance to or trigger infinite scroll .select2-results__option--load-more
Description
In Select2 4.1.0, keyboard arrow navigation (results:previous and results:next in src/js/select2/results.js) was updated to only query:
var $options = self.$results.find('.select2-results__option--selectable');When using AJAX data with pagination (infinite scroll), the bottom element is rendered with:
<li class="select2-results__option select2-results__option--load-more" role="option" aria-disabled="true">
Loading more results…
</li>Because .select2-results__option--load-more does not have the --selectable modifier class, pressing ArrowDown at the end of the current page halts navigation at index = $options.length - 1.
Steps to Reproduce
- Configure Select2 with an AJAX data source that returns paginated results (
pagination: { more: true }). - Open the dropdown and navigate through results using the
ArrowDownkey. - Reach the last option of the first page and press
ArrowDownagain.
Expected Behavior
Pressing ArrowDown past the last option should either focus the load-more element or scroll it into view to trigger loadMoreIfNeeded(), allowing keyboard-only users to seamlessly paginate through AJAX results.
Actual Behavior
results:next hits if (nextIndex >= $options.length) { return; } and halts. Keyboard-driven infinite scrolling cannot advance to subsequent pages.
Environment
- Select2 Version: 4.1.0
- Browsers: All (Chrome, Firefox, Safari)
Proposed Solution
In src/js/select2/results.js (under both results:previous and results:next), include .select2-results__option--load-more in $options:
var $options = self.$results.find(
'.select2-results__option--selectable, .select2-results__option--load-more'
);Alternatively, trigger loadMoreIfNeeded() when nextIndex >= $options.length.
Source: select2/select2