jquery.uls.lcd: Handle scenario where selected item is undetermined

Throw an error if during keyboard navigation the selected item could
not be determined.

Bug: https://phabricator.wikimedia.org/T328956
This commit is contained in:
Abijeet
2023-04-11 12:31:23 +05:30
committed by Niklas Laxström
parent d164459cc6
commit ea8af529a2

View File

@@ -155,6 +155,13 @@
$listItems.removeClass( 'uls-language-option--highlighted' ); $listItems.removeClass( 'uls-language-option--highlighted' );
var $selectedItem = $listItems.eq( this.navigationIndex ); var $selectedItem = $listItems.eq( this.navigationIndex );
if ( $selectedItem.length === 0 ) {
throw new Error(
'Could not identify selected item with index: ' + this.navigationIndex + '; ' +
'Total items in ULS: ' + $listItems.length
);
}
$selectedItem.addClass( 'uls-language-option--highlighted' ); $selectedItem.addClass( 'uls-language-option--highlighted' );
// If the selected item is not visible, then scroll the container to display it // If the selected item is not visible, then scroll the container to display it