jenkins-bot has submitted this change and it was merged. Change subject: TextInputWidget: Support 'rows' option when in multiline mode ......................................................................
TextInputWidget: Support 'rows' option when in multiline mode Bug: T104682 Change-Id: I6a8ec1f7d00e73e89b9d25718eac2a547b1e2ba6 --- M demos/pages/widgets.js M demos/widgets.php M php/widgets/TextInputWidget.php M src/widgets/TextInputWidget.js 4 files changed, 53 insertions(+), 5 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/demos/pages/widgets.js b/demos/pages/widgets.js index 5c0843c..74a0497 100644 --- a/demos/pages/widgets.js +++ b/demos/pages/widgets.js @@ -827,6 +827,17 @@ new OO.ui.FieldLayout( new OO.ui.TextInputWidget( { multiline: true, + rows: 15, + value: 'Multiline\nMultiline' + } ), + { + label: 'TextInputWidget (multiline, rows=15)\u200E', + align: 'top' + } + ), + new OO.ui.FieldLayout( + new OO.ui.TextInputWidget( { + multiline: true, autosize: true, value: 'Autosize\nAutosize\nAutosize\nAutosize' } ), @@ -837,6 +848,18 @@ ), new OO.ui.FieldLayout( new OO.ui.TextInputWidget( { + multiline: true, + rows: 10, + autosize: true, + value: 'Autosize\nAutosize\nAutosize\nAutosize' + } ), + { + label: 'TextInputWidget (autosize, rows=10)\u200E', + align: 'top' + } + ), + new OO.ui.FieldLayout( + new OO.ui.TextInputWidget( { icon: 'tag', indicator: 'alert', value: 'Text input with label', diff --git a/demos/widgets.php b/demos/widgets.php index d4adbaa..64ade93 100644 --- a/demos/widgets.php +++ b/demos/widgets.php @@ -619,6 +619,17 @@ ) ), new OOUI\FieldLayout( + new OOUI\TextInputWidget( array( + 'multiline' => true, + 'rows' => 15, + 'value' => "Multiline\nMultiline" + ) ), + array( + 'label' => "TextInputWidget (multiline, rows=15)\xE2\x80\x8E", + 'align' => 'top' + ) + ), + new OOUI\FieldLayout( new OOUI\DropdownInputWidget( array( 'options' => array( array( diff --git a/php/widgets/TextInputWidget.php b/php/widgets/TextInputWidget.php index 3412639..7305521 100644 --- a/php/widgets/TextInputWidget.php +++ b/php/widgets/TextInputWidget.php @@ -33,6 +33,7 @@ * @param boolean $config['readOnly'] Prevent changes (default: false) * @param number $config['maxLength'] Maximum allowed number of characters to input * @param boolean $config['multiline'] Allow multiple lines of text (default: false) + * @param int $config['rows'] If multiline, number of visible lines in textarea * @param boolean $config['required'] Mark the field as required (default: false) * @param boolean $config['autocomplete'] If the field should support autocomplete * or not (default: true) @@ -76,6 +77,9 @@ } if ( !$config['autocomplete'] ) { $this->input->setAttributes( array( 'autocomplete' => 'off' ) ); + } + if ( $this->multiline && isset( $config['rows'] ) ) { + $this->input->setAttributes( array( 'rows' => $config['rows'] ) ); } } @@ -130,6 +134,10 @@ public function getConfig( &$config ) { if ( $this->isMultiline() ) { $config['multiline'] = true; + $rows = $this->input->getAttribute( 'rows' ); + if ( $rows !== null ) { + $config['rows'] = $rows; + } } else { $type = $this->input->getAttribute( 'type' ); if ( $type !== 'text' ) { diff --git a/src/widgets/TextInputWidget.js b/src/widgets/TextInputWidget.js index 1069501..8347371 100644 --- a/src/widgets/TextInputWidget.js +++ b/src/widgets/TextInputWidget.js @@ -34,9 +34,12 @@ * @cfg {boolean} [readOnly=false] Prevent changes to the value of the text input. * @cfg {number} [maxLength] Maximum number of characters allowed in the input. * @cfg {boolean} [multiline=false] Allow multiple lines of text + * @cfg {number} [rows] If multiline, number of visible lines in textarea. If used with `autosize`, + * specifies minimum number of rows to display. * @cfg {boolean} [autosize=false] Automatically resize the text input to fit its content. * Use the #maxRows config to specify a maximum number of displayed rows. - * @cfg {boolean} [maxRows=10] Maximum number of rows to display when #autosize is set to true. + * @cfg {boolean} [maxRows] Maximum number of rows to display when #autosize is set to true. + * Defaults to the maximum of `10` and `2 * rows`, or `10` if `rows` isn't provided. * @cfg {string} [labelPosition='after'] The position of the inline label relative to that of * the value or placeholder text: `'before'` or `'after'` * @cfg {boolean} [required=false] Mark the field as required @@ -51,8 +54,7 @@ // Configuration initialization config = $.extend( { type: 'text', - labelPosition: 'after', - maxRows: 10 + labelPosition: 'after' }, config ); // Parent constructor @@ -68,7 +70,8 @@ this.readOnly = false; this.multiline = !!config.multiline; this.autosize = !!config.autosize; - this.maxRows = config.maxRows; + this.minRows = config.rows !== undefined ? config.rows : ''; + this.maxRows = config.maxRows || Math.max( 2 * ( this.minRows || 0 ), 10 ); this.validate = null; // Clone for resizing @@ -116,6 +119,9 @@ } if ( config.autocomplete === false ) { this.$input.attr( 'autocomplete', 'off' ); + } + if ( this.multiline && config.rows ) { + this.$input.attr( 'rows', config.rows ); } if ( this.label || config.autosize ) { this.installParentChangeDetector(); @@ -327,7 +333,7 @@ if ( this.multiline && this.autosize && this.$input.val() !== this.valCache ) { this.$clone .val( this.$input.val() ) - .attr( 'rows', '' ) + .attr( 'rows', this.minRows ) // Set inline height property to 0 to measure scroll height .css( 'height', 0 ); -- To view, visit https://gerrit.wikimedia.org/r/222541 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6a8ec1f7d00e73e89b9d25718eac2a547b1e2ba6 Gerrit-PatchSet: 10 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Bartosz DziewoĆski <matma....@gmail.com> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits