Bug 1146946 - Handle empty lists in sidebar.js when using the up/down key. r=florian a=readinglist
authorBlake Winton <bwinton@latte.ca>
Tue, 24 Mar 2015 15:12:17 -0400
changeset 248472 5a005b821daee4994d7a1e895dea23066eb79fee
parent 248471 6e5a2a95f319e79211b143c5ef50b7a6d8458cc7
child 248473 ee9b3d01d1c2b5f5477047545b80316d028953e4
push id7837
push userjwein@mozilla.com
push dateFri, 27 Mar 2015 00:27:16 +0000
treeherdermozilla-aurora@cb0db44ce60e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, readinglist
bugs1146946
milestone38.0a2
Bug 1146946 - Handle empty lists in sidebar.js when using the up/down key. r=florian a=readinglist
browser/components/readinglist/sidebar.js
--- a/browser/components/readinglist/sidebar.js
+++ b/browser/components/readinglist/sidebar.js
@@ -402,26 +402,33 @@ let RLSidebar = {
    * Handle a keydown event on the list box.
    * @param {Event} event - Triggering event.
    */
   onListKeyDown(event) {
     if (event.keyCode == KeyEvent.DOM_VK_DOWN) {
       // TODO: Refactor this so we pass a direction to a generic method.
       // See autocomplete.xml's getNextIndex
       event.preventDefault();
+
+      if (!this.numItems) {
+        return;
+      }
       let index = this.selectedIndex + 1;
       if (index >= this.numItems) {
         index = 0;
       }
 
       this.selectedIndex = index;
       this.selectedItem.focus();
     } else if (event.keyCode == KeyEvent.DOM_VK_UP) {
       event.preventDefault();
 
+      if (!this.numItems) {
+        return;
+      }
       let index = this.selectedIndex - 1;
       if (index < 0) {
         index = this.numItems - 1;
       }
 
       this.selectedIndex = index;
       this.selectedItem.focus();
     } else if (event.keyCode == KeyEvent.DOM_VK_RETURN) {