RCFilters UI: Fix scrolling to item on tag click
authorMoriel Schottlender <moriel@gmail.com>
Mon, 17 Apr 2017 23:30:03 +0000 (16:30 -0700)
committerMoriel Schottlender <moriel@gmail.com>
Mon, 17 Apr 2017 23:30:03 +0000 (16:30 -0700)
Bug: T163138
Change-Id: I1f3a5b29eb3d9125faf1d4d27c84b8711fd4fdda

resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterTagMultiselectWidget.js

index 2461929..7de2a79 100644 (file)
         */
        mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onTagSelect = function ( tagItem ) {
                var widget = this,
-                       menuOption = this.menu.getItemFromData( tagItem.getData() );
+                       menuOption = this.menu.getItemFromData( tagItem.getData() ),
+                       oldInputValue = this.input.getValue();
 
                // Reset input
                this.input.setValue( '' );
                this.menu.selectItem( menuOption );
 
                // Scroll to the item
-               // We're binding a 'once' to the itemVisibilityChange event
-               // so this happens when the menu is ready after the items
-               // are visible again, in case this is done right after the
-               // user filtered the results
-               this.getMenu().once(
-                       'itemVisibilityChange',
-                       function () { widget.scrollToTop( menuOption.$element ); }
-               );
+               if ( oldInputValue ) {
+                       // We're binding a 'once' to the itemVisibilityChange event
+                       // so this happens when the menu is ready after the items
+                       // are visible again, in case this is done right after the
+                       // user filtered the results
+                       this.getMenu().once(
+                               'itemVisibilityChange',
+                               function () { widget.scrollToTop( menuOption.$element ); }
+                       );
+               } else {
+                       this.scrollToTop( menuOption.$element );
+               }
        };
 
        /**