In #2675464: Margin on form-items in table rows (Classy) we identified and devised a solution for a problem in the Classy theme that causes problems for modules like IEF and Paragraphs. However, @lauriii suggested it was too dangerous to fix properly in Classy without trying first in Seven.

Problem

In /core/themes/classy/css/components/form.css we have:

tr.odd .form-item,
tr.even .form-item {
  margin-top: 0;
  margin-bottom: 0;
}

This works fine for single element forms (like checkboxes or selects) in table rows, but causes problems when we want to have more complex multi-element forms in tables (like anywhere in a standard node edit form when a field widget requires multiple form elements).

Furthermore, this may break break content list styles; see comment 47 in #2675464-47: Margin on form-items in table rows (Classy).

Solution

Add the margin back in, overriding Classy. Then remove it just for td > .form-item:only-child.

Todo

  1. Create a patch
  2. Post screenshots showing before/after in a complex form like paragraphs
  3. Post screenshots showing before/after in the content list
  4. Tag for Needs frontend framework manager review
  5. Copy issue credit across from #2675464: Margin on form-items in table rows (Classy)

Screenshots

Before:

After:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathanshaw created an issue. See original summary.

jonathanshaw’s picture

Title: Margin on form-items in table rows » Margin on form-items in table rows (Seven)
Anatoliy Vorobyov’s picture

jonathanshaw’s picture

Status: Active » Needs work
Issue tags: +Needs screenshots

thanks @Anatoliy

lauriii’s picture

Status: Needs work » Needs review

Moving to needs review to encourage contributors to take screenshots 🙌

lauriii’s picture

Issue tags: +Needs manual testing
--- a/core/themes/classy/css/components/form.css
+++ b/core/themes/classy/css/components/form.css

@@ -32,8 +32,7 @@ form .field-add-more-submit {
-tr.even .form-item {
+td > .form-item:only-child {

This still changes Classy. We should implement this so that it only affects Seven. Leaving to needs review for the manual testing since knowing if something is broken would be useful already at this point.

jonathanshaw’s picture

Sorry @lauriii I forgot to make the most important thing clear in the IS!

KondratievaS’s picture

Issue summary: View changes
Issue tags: -Needs screenshots, -Needs manual testing
FileSize
152.22 KB
161.12 KB

I have tested and patch works as expected - margins are added

jonathanshaw’s picture

Status: Needs review » Needs work

Thanks @Kondratieva. Putting to Needs Work temporarily in the hope that will attract someone to fix #6

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
440 bytes
39.39 KB
40.1 KB

I have tried testing it in 'seven' theme with some changes in the patch #3.

jonathanshaw’s picture

@anmolgoyal74 it would help if you could explain the reason for changing the margin to 0.75em instead of the 0em suggested in the IS based on the parent issue.

jhcastanod’s picture

Assigned: Unassigned » jhcastanod
Status: Needs review » Reviewed & tested by the community
FileSize
230.88 KB

I tested the solution provided and worked as expected

lauriii’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
+++ b/core/themes/seven/css/components/form.css
@@ -49,6 +49,10 @@ fieldset:not(.fieldgroup) > legend {
+td .form-item:only-child {

The logic here doesn't seem right. We should make sure that there's no margin when .form-item elements are placed as only child directly inside a td element. When that isn't the case, the default margin given for .form-item should apply.

anmolgoyal74’s picture

Status: Needs work » Needs review

we cannot have margin set to 0 only to element that are placed as only child directly inside a td element without removing the following CSS in Classy theme.

tr.odd .form-item,
tr.even .form-item {
  margin-top: 0;
  margin-bottom: 0;
}

Or we can instead add margin to other cases as in #10.

Else we can proceed with patch in #3

jonathanshaw’s picture

In #2675464: Margin on form-items in table rows (Classy) we ended up with:

tr.odd td > .form-item:only-child,
tr.even td > .form-item:only-child {
   margin-top: 0;
   margin-bottom: 0;
 }

Maybe that would work here too.

anmolgoyal74’s picture

#15 doesn't work till we have the CSS in classy which needs to be removed to reflect the changes.

If we remove this from classy then #15 works well.

tr.odd .form-item,
tr.even .form-item {
  margin-top: 0;
  margin-bottom: 0;
}

This code sets margin to 0 for every element. So we need to add margin to other cases.

jonathanshaw’s picture

Good point. But I'm still not understanding #10. Shouldn't we be doing something like this in seven to first reverse classy then reapply in a more targeted fashion:

tr.odd td > .form-item,
tr.even td > .form-item {
  margin-top: 0. 75em;
  margin-bottom: 0.75em;
}
tr.odd td > .form-item:only-child,
tr.even td > .form-item:only-child {
  margin-top: 0;
  margin-bottom: 0;
}
anmolgoyal74’s picture

Nice workaround.

But #17 isn't working.
This is working

tr.odd .form-item,
tr.even .form-item {
  margin-top: 0.75em;
  margin-bottom: 0.75em;
}
tr.odd td > .form-item:only-child,
tr.even td > .form-item:only-child {
  margin-top: 0;
  margin-bottom: 0;
}
jonathanshaw’s picture

Great. For this to be RTBC we're going to need a code comment. Perhaps something like:

* When a table row has a single form item, prevent it from adding unnecessary
* extra spacing. If it has multiple form items, allow spacing between them,
* overriding Classy.

anmolgoyal74’s picture

jonathanshaw’s picture

Let's see what @lauriii says

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lauriii’s picture

+++ b/core/themes/seven/css/components/form.css
@@ -49,6 +49,21 @@ fieldset:not(.fieldgroup) > legend {
+tr.odd td > .form-item:only-child,
+tr.even td > .form-item:only-child {

Could this be changed to be only td > .form-item:only-child or isn't that heavy enough to override the other selector? Besides that this starts to looks good for me.

anmolgoyal74’s picture

FileSize
722 bytes
39.71 KB
54.47 KB
jonathanshaw’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I can't recreate the content list problem that @lauriii reported in #2675464-47: Margin on form-items in table rows (Classy), so can't provide a screenshot to show it's fixed.

jonathanshaw’s picture

lauriii credited pivica.

lauriii credited ricksta.

lauriii credited twfahey.

lauriii’s picture

Version: 8.7.x-dev » 8.6.x-dev
FileSize
423 bytes

Credited people from #2675464: Margin on form-items in table rows (Classy) to make sure their work gets credited. I also made a minor code style adjustment on the commit (interdiff attached).

Committed 25809ca and pushed to 8.7.x. Thanks!

  • lauriii committed 25809ca on 8.7.x
    Issue #2982097 by anmolgoyal74, Anatoliy Vorobyov, KondratievaS,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Cherry-picked f139cc7 and pushed to 8.6.x.

  • lauriii committed f139cc7 on 8.6.x
    Issue #2982097 by anmolgoyal74, Anatoliy Vorobyov, KondratievaS,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.