From ea8af529a2c5d2f7b0857a8eee04a4d35a3cbf3e Mon Sep 17 00:00:00 2001 From: Abijeet Date: Tue, 11 Apr 2023 12:31:23 +0530 Subject: [PATCH] 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 --- src/jquery.uls.lcd.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/jquery.uls.lcd.js b/src/jquery.uls.lcd.js index 8390844..39bf8f7 100644 --- a/src/jquery.uls.lcd.js +++ b/src/jquery.uls.lcd.js @@ -155,6 +155,13 @@ $listItems.removeClass( 'uls-language-option--highlighted' ); 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' ); // If the selected item is not visible, then scroll the container to display it