From 8e5912aac37868cced1f8b4350e48455b7654645 Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 8 May 2016 16:55:34 +0200 Subject: [PATCH] OOUIHTMLForm: Don't output an empty hidden LabelWidget if not needed The hidden element is only needed if either a header is set or the form has errors. If both does not apply, the element isn't needed and should be omitted instead of hidden with `display:none`. It's also not needed to add a LabelWidget for the header, if the form has errors, only, but no header (which would result in an empty space between the header and the fieldset legend). Follow up: Ifbf38878d41906184f97169b22002f788711a311 Change-Id: I4ffefdc50d435590d25a7dfc202228920dd801ae --- includes/htmlform/OOUIHTMLForm.php | 31 +++++++++++-------- .../src/mediawiki/mediawiki.htmlform.ooui.css | 10 ------ 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php index 7a2ed5078d..711750ba79 100644 --- a/includes/htmlform/OOUIHTMLForm.php +++ b/includes/htmlform/OOUIHTMLForm.php @@ -221,22 +221,27 @@ class OOUIHTMLForm extends HTMLForm { // FIXME This only works for forms with no subsections if ( $fieldset instanceof OOUI\FieldsetLayout ) { $classes = [ 'mw-htmlform-ooui-header' ]; - if ( !$this->mHeader ) { - $classes[] = 'mw-htmlform-ooui-header-empty'; - } if ( $this->oouiErrors ) { $classes[] = 'mw-htmlform-ooui-header-errors'; } - $fieldset->addItems( [ - new OOUI\FieldLayout( - new OOUI\LabelWidget( [ 'label' => new OOUI\HtmlSnippet( $this->mHeader ) ] ), - [ - 'align' => 'top', - 'errors' => $this->oouiErrors, - 'classes' => $classes, - ] - ) - ], 0 ); + if ( $this->mHeader || $this->oouiErrors ) { + // if there's no header, don't create an (empty) LabelWidget, simply use a placeholder + if ( $this->mHeader ) { + $element = new OOUI\LabelWidget( [ 'label' => new OOUI\HtmlSnippet( $this->mHeader ) ] ); + } else { + $element = new OOUI\Widget( [] ); + } + $fieldset->addItems( [ + new OOUI\FieldLayout( + $element, + [ + 'align' => 'top', + 'errors' => $this->oouiErrors, + 'classes' => $classes, + ] + ) + ], 0 ); + } } return $fieldset; } diff --git a/resources/src/mediawiki/mediawiki.htmlform.ooui.css b/resources/src/mediawiki/mediawiki.htmlform.ooui.css index 260fd37e3a..8f0ad6becd 100644 --- a/resources/src/mediawiki/mediawiki.htmlform.ooui.css +++ b/resources/src/mediawiki/mediawiki.htmlform.ooui.css @@ -4,16 +4,6 @@ margin: 1em 0; } -.oo-ui-fieldLayout.mw-htmlform-ooui-header-empty, -.oo-ui-fieldLayout.mw-htmlform-ooui-header-empty .oo-ui-fieldLayout-body { - display: none; -} - -.oo-ui-fieldLayout.mw-htmlform-ooui-header-errors { - /* Override 'display: none' from above */ - display: block; -} - .mw-htmlform-ooui .mw-htmlform-submit-buttons { margin-top: 1em; } -- 2.20.1