jenkins-bot has submitted this change and it was merged.

Change subject: TextInputWidget: Add support for 'autofocus' config option
......................................................................


TextInputWidget: Add support for 'autofocus' config option

Not very useful in JS (just calling .focus() is almost always preferable),
but will come in handy in PHP.

Change-Id: Idfc89279b9a4e017d59c9732c89c14a0c2849a90
---
M bin/testsuitegenerator.rb
M php/widgets/TextInputWidget.php
M src/widgets/TextInputWidget.js
3 files changed, 12 insertions(+), 1 deletion(-)

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



diff --git a/bin/testsuitegenerator.rb b/bin/testsuitegenerator.rb
index e1d8b7d..7349aca 100644
--- a/bin/testsuitegenerator.rb
+++ b/bin/testsuitegenerator.rb
@@ -39,6 +39,7 @@
                'enctype' => true,
                'target' => ['_blank'],
                'name' => true,
+               'autofocus' => true, # usually makes no sense in JS
                'tabIndex' => true,
                'icon' => ['picture'],
                'indicator' => ['down'],
diff --git a/php/widgets/TextInputWidget.php b/php/widgets/TextInputWidget.php
index 51f02b4..545b68e 100644
--- a/php/widgets/TextInputWidget.php
+++ b/php/widgets/TextInputWidget.php
@@ -27,12 +27,14 @@
         * @param array $config Configuration options
         * @param string $config['type'] HTML tag `type` attribute (default: 
'text')
         * @param string $config['placeholder'] Placeholder text
+        * @param boolean $config['autofocus'] Ask the browser to focus this 
widget, using the 'autofocus'
+        *   HTML attribute (default: false)
         * @param boolean $config['readOnly'] Prevent changes (default: false)
         * @param boolean $config['multiline'] Allow multiple lines of text 
(default: false)
         */
        public function __construct( array $config = array() ) {
                // Config initialization
-               $config = array_merge( array( 'readOnly' => false ), $config );
+               $config = array_merge( array( 'readOnly' => false, 'autofocus' 
=> false ), $config );
 
                // Parent constructor
                parent::__construct( $config );
@@ -52,6 +54,9 @@
                if ( isset( $config['placeholder'] ) ) {
                        $this->input->setAttributes( array( 'placeholder' => 
$config['placeholder'] ) );
                }
+               if ( $config['autofocus'] ) {
+                       $this->input->setAttributes( array( 'autofocus' => 
'autofocus' ) );
+               }
                $this->setAttributes( array( 'role' => 'textbox' ) );
        }
 
diff --git a/src/widgets/TextInputWidget.js b/src/widgets/TextInputWidget.js
index 8c8bc42..98de1d9 100644
--- a/src/widgets/TextInputWidget.js
+++ b/src/widgets/TextInputWidget.js
@@ -11,6 +11,8 @@
  * @param {Object} [config] Configuration options
  * @cfg {string} [type='text'] HTML tag `type` attribute
  * @cfg {string} [placeholder] Placeholder text
+ * @cfg {boolean} [autofocus=false] Ask the browser to focus this widget, 
using the 'autofocus' HTML
+ *  attribute
  * @cfg {boolean} [readOnly=false] Prevent changes
  * @cfg {boolean} [multiline=false] Allow multiple lines of text
  * @cfg {boolean} [autosize=false] Automatically resize to fit content
@@ -64,6 +66,9 @@
        if ( config.placeholder ) {
                this.$input.attr( 'placeholder', config.placeholder );
        }
+       if ( config.autofocus ) {
+               this.$input.attr( 'autofocus', 'autofocus' );
+       }
        this.$element.attr( 'role', 'textbox' );
 };
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Idfc89279b9a4e017d59c9732c89c14a0c2849a90
Gerrit-PatchSet: 5
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.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