jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/342773 )

Change subject: mw.widgets.SearchInputWidget: Do not pass `type: 'search'` to 
TextInputWidget
......................................................................


mw.widgets.SearchInputWidget: Do not pass `type: 'search'` to TextInputWidget

Causes deprecation warnings.

Most of this code is copy-pasted from OO.ui.SearchInputWidget.

Bug: T148471
Change-Id: I81d52ba938a8b90c5d2c173f1f2682d9e3300e43
(cherry picked from commit e218f21d444dbdf32b6541ff1a54fca2cf8776f8)
---
M includes/widget/SearchInputWidget.php
M resources/src/mediawiki.widgets/mw.widgets.SearchInputWidget.js
2 files changed, 70 insertions(+), 2 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/widget/SearchInputWidget.php 
b/includes/widget/SearchInputWidget.php
index 0d71629..49510da 100644
--- a/includes/widget/SearchInputWidget.php
+++ b/includes/widget/SearchInputWidget.php
@@ -31,7 +31,6 @@
        public function __construct( array $config = [] ) {
                $config = array_merge( [
                        'maxLength' => null,
-                       'type' => 'search',
                        'icon' => 'search',
                ], $config );
 
@@ -56,6 +55,10 @@
                $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
        }
 
+       protected function getInputElement( $config ) {
+               return ( new \OOUI\Tag( 'input' ) )->setAttributes( [ 'type' => 
'search' ] );
+       }
+
        protected function getJavaScriptClassName() {
                return 'mw.widgets.SearchInputWidget';
        }
diff --git a/resources/src/mediawiki.widgets/mw.widgets.SearchInputWidget.js 
b/resources/src/mediawiki.widgets/mw.widgets.SearchInputWidget.js
index 0a73bef..7880b55 100755
--- a/resources/src/mediawiki.widgets/mw.widgets.SearchInputWidget.js
+++ b/resources/src/mediawiki.widgets/mw.widgets.SearchInputWidget.js
@@ -30,7 +30,6 @@
                var $form = config.$input ? config.$input.closest( 'form' ) : 
$();
 
                config = $.extend( {
-                       type: 'search',
                        icon: 'search',
                        maxLength: undefined,
                        performSearchOnClick: true,
@@ -67,6 +66,12 @@
                                )
                        } );
                }.bind( this ) );
+
+               this.$element.addClass( 'oo-ui-textInputWidget-type-search' );
+               this.updateSearchIndicator();
+               this.connect( this, {
+                       disable: 'onDisable'
+               } );
        };
 
        /* Setup */
@@ -76,6 +81,66 @@
        /* Methods */
 
        /**
+        * @inheritdoc
+        * @protected
+        */
+       mw.widgets.SearchInputWidget.prototype.getInputElement = function () {
+               return $( '<input>' ).attr( 'type', 'search' );
+       };
+
+       /**
+        * @inheritdoc
+        */
+       mw.widgets.SearchInputWidget.prototype.onIndicatorMouseDown = function 
( e ) {
+               if ( e.which === OO.ui.MouseButtons.LEFT ) {
+                       // Clear the text field
+                       this.setValue( '' );
+                       this.$input[ 0 ].focus();
+                       return false;
+               }
+       };
+
+       /**
+        * Update the 'clear' indicator displayed on type: 'search' text
+        * fields, hiding it when the field is already empty or when it's not
+        * editable.
+        */
+       mw.widgets.SearchInputWidget.prototype.updateSearchIndicator = function 
() {
+               if ( this.getValue() === '' || this.isDisabled() || 
this.isReadOnly() ) {
+                       this.setIndicator( null );
+               } else {
+                       this.setIndicator( 'clear' );
+               }
+       };
+
+       /**
+        * @inheritdoc
+        */
+       mw.widgets.SearchInputWidget.prototype.onChange = function () {
+               mw.widgets.SearchInputWidget.parent.prototype.onChange.call( 
this );
+               this.updateSearchIndicator();
+       };
+
+       /**
+        * Handle disable events.
+        *
+        * @param {boolean} disabled Element is disabled
+        * @private
+        */
+       mw.widgets.SearchInputWidget.prototype.onDisable = function () {
+               this.updateSearchIndicator();
+       };
+
+       /**
+        * @inheritdoc
+        */
+       mw.widgets.SearchInputWidget.prototype.setReadOnly = function ( state ) 
{
+               mw.widgets.SearchInputWidget.parent.prototype.setReadOnly.call( 
this, state );
+               this.updateSearchIndicator();
+               return this;
+       };
+
+       /**
         * @inheritdoc mw.widgets.TitleWidget
         */
        mw.widgets.SearchInputWidget.prototype.getSuggestionsPromise = function 
() {

-- 
To view, visit https://gerrit.wikimedia.org/r/342773
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I81d52ba938a8b90c5d2c173f1f2682d9e3300e43
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.29.0-wmf.16
Gerrit-Owner: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Bartosz DziewoƄski <matma....@gmail.com>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to