RCFilters: Clean up focus handling in capsule widget
authorRoan Kattouw <roan.kattouw@gmail.com>
Fri, 6 Jan 2017 23:59:48 +0000 (15:59 -0800)
committerCatrope <roan@wikimedia.org>
Wed, 18 Jan 2017 01:18:32 +0000 (01:18 +0000)
Don't let the parent class's weird implementation run when the
widget is focused through other code paths (e.g. clicking on
the non-input part of it).

We still need to fix the behavior when you click in the
input twice (the first click shows the popup and the second
click hides it), but this is much better already.

Related to I21b8cff4048 in oojs-ui.

Bug: T149452
Change-Id: I08743c64ea32feace757e2a8626df2f5310cfbc9

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

index df6cf8b..db21542 100644 (file)
@@ -25,7 +25,7 @@
                // Events
                // Add the filterInput as trigger
                this.filterInput.$input
-                       .on( 'focus', this.onFocusForPopup.bind( this ) );
+                       .on( 'focus', this.focus.bind( this ) );
 
                this.$element
                        .addClass( 'mw-rcfilters-ui-filterCapsuleMultiselectWidget' );
        /**
         * @inheritdoc
         */
-       mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.onFocusForPopup = function () {
+       mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.focus = function () {
                // Override this method; we don't want to focus on the popup, and we
                // don't want to bind the size to the handle.
                if ( !this.isDisabled() ) {
                        this.popup.toggle( true );
+                       this.filterInput.$input.get( 0 ).focus();
                }
+               return this;
+       };
+
+       /**
+        * @inheritdoc
+        */
+       mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.onFocusForPopup = function () {
+               // HACK can be removed once I21b8cff4048 is merged in oojs-ui
+               this.focus();
        };
 
        /**