OOUIHTMLForm: Don't output an empty hidden LabelWidget if not needed
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Sun, 8 May 2016 14:55:34 +0000 (16:55 +0200)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Fri, 13 May 2016 19:30:22 +0000 (21:30 +0200)
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
resources/src/mediawiki/mediawiki.htmlform.ooui.css

index 7a2ed50..711750b 100644 (file)
@@ -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;
        }
index 260fd37..8f0ad6b 100644 (file)
@@ -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;
 }