Classy puts a margin on form items, but not when they're in table rows.
This causes problems in contrib: if forms are placed inside responsive tables, there is no spacing between fields:
#2668708: Spacing between fields on paras
This behavior dates back to Drupal 4, and the reasoning is lost in the mists of time. Probably it is that core sometimes has a single form element in a table row (like a checkbox or dropdown) and no more spacing is desired than would be needed for text alone.
The least disruptive solution is:
When a table row has a single form item prevent it from adding unnecessary extra spacing, but if it has multiple form items allow spacing between them.
Comment | File | Size | Author |
---|---|---|---|
#57 | 2675464-57.patch | 2.95 KB | komalk |
#57 | interdiff_56-57.txt | 2.56 KB | komalk |
#56 | 2675464-56.patch | 658 bytes | komalk |
#47 | Screen Shot 2018-06-27 at 16.36.35.png | 165.35 KB | lauriii |
#40 | 2675464-Margin-on-form-items-in-table-rows.patch | 658 bytes | twfahey |
Comments
Comment #2
darketaine CreditAttribution: darketaine commentedA first guess would be that in case there is a single field-item inside a td it should get its spaces from the table elements (td) and not their content.
What I see is that this comes in drupal since 4.7 so I don't know if it's a good idea to change it just because there is a case of a module where this goes a bit wrong.
I would like though to have an opinion from the Classy maintainers as they sure know more than we do :)
Comment #3
bojanz CreditAttribution: bojanz at Centarro commentedAlso a problem in Inline Entity Form. Our fields look terrible because of the low spacing. Would be great not to need custom CSS.
Comment #4
mglamanThe drag handle is positioned and all other elements just kind of float around it. Almost like it's expected to be in its own
td
, however inline forms are not rendering it that way.Comment #5
emma.mariaComment #6
mglamanLinking to solution that bojanz committed to Drupal Commerce 2.x: https://github.com/drupalcommerce/commerce/commit/e52fbfe03e305421905243...
In short:
Needed to manually make
tabledrag
atd
manually with an empty value.Comment #7
bojanz CreditAttribution: bojanz at Centarro commented@mglaman
This issue is about the element margins (vertical spacing between two elements), which is unaffected by #6.
The extra column trick is just for avoiding reflow problems around the tabledrag element.
Comment #9
davidhernandezCan someone add a couple screenshots highlighting what the problem is before digging in?
Comment #10
jonathanshawHere's the screenshot from Paragraphs:
It may not be very helpful though, because of the additional styling that the paragraphs widget is doing is not making the context very obvious. This is actually a row in a responsive table (with the drag handle aligned to the top of the cell), and that row is rendering an edit form for an entity called "List item" that has 3 fields
This might be a problem with any screenshot in fact ... maybe the issue comes up mostly when people do unusual things with forms.
Comment #11
davidhernandezBased on what the issue summary says, we should be able to add some form elements to a table and look at it directly in Classy, right? That should reveal the problem directly.
Comment #12
jonathanshawI think so, yes
Comment #13
Chernous_dn CreditAttribution: Chernous_dn at FFW for FFW commentedHi #jonathanjfshaw can you provide screenshots with this bug? And where I can check this bug? Thanks.
Comment #14
jonathanshaw#10 is all I've got. I don't know if there's anywhere in core that is directly affected. The problem shows up when contrib modules like IEF and paragraphs want to put forms inside tables.
Comment #18
pivica CreditAttribution: pivica at MD Systems GmbH commentedInvestigated this a bit and manage to track original CSS addition in file /misc/drupal.css in commit http://cgit.drupalcode.org/drupal/commit/?id=ad5e3ebb75df5c861251ba3ed3d... which happened in 2004, yep long time ago:
This code didn't change a lot over the year, got moved a couple of time and now it is in /core/themes/classy/css/components/form.css:
This margin reset rules are useful for tables with single table row form elements, for example, pages like
admin/modules
admin/config/regional/language
...
So a use case for this is that we need to have .form-item in table and table rows needs to have .odd or .even classes. And then we apply this margin reset rules so we save up some vertical space.
The problem is that these reset rules are too general and they will be applied for other cases like for Inline Entity Forms or Paragraphs. In this cases, we don't want this.
We could easily fix this if we assume that this rules should be active only in the case when we have one form-item inside of td, and this was probably the case when these rules were originally added:
Use cases where margin reset should be active should still work with this but the rule will not be active for table cell which has multiple elements inside of table cells.
Here are the screenshots before and after the patch applied:
Browser support for :only-child pseudo selector is good https://caniuse.com/#feat=css-sel3, including IE9.
Comment #21
slydevil CreditAttribution: slydevil commentedPatch from #18 works well. Thank you!
Comment #22
slydevil CreditAttribution: slydevil commentedI've re-run the tests and they all passed for the 8.5 branch. Setting back to Needs Review.
Comment #23
sgurlt CreditAttribution: sgurlt commentedAgree #18 also works for me and makes the UX for my editors way better :)
Comment #24
ricksta CreditAttribution: ricksta commentedOur team noticed this issue when using fields with unlimited instances, and a single link field, within a Paragraphs container (similar to the screenshot in #10), and the patch in #18 resolves this.
In testing, we created pages, blocks, forms and content using paragraphs, using various types of fields, and do not see any problems anywhere. On forms using Paragraphs this patch equalizes the spacing between fields, as well as anywhere table rows contain elements with the "form-item" class, such as a contact form containing a link field. We noted no regressions.
Before (below)
After (below)
Themes tested:
• tested with Seven (subtheme of Classy)
• tested with Bratik (subtheme of Classy)
• tested with Adminimal (subtheme of Classy)
Browsers tested:
• Chrome 65.0.3325
• IE 11
• MS Edge 14, 15, 16
• FireFox 52.0
• Safari 11.0.3
Drupal versions tested:
8.5
8.6.x-dev
This very selective minimal patch (margin-on-form-items-in-table-rows-2675464.patch) does seem to work as intended. We think it would be a worthwhile improvement to backend UX where the admin theme is Seven, Bartik or Adminimal theme, or any other theme with Classy as the parent theme.
Based on #21, #22, and #23, and our own testing, I'm marking this as RTBC.
Comment #25
ricksta CreditAttribution: ricksta commentedComment #26
davidhernandezI didn't test this personally, but regarding the change itself, it is pretty small and I would classify as a minor bug fix. It shouldn't adversely affect any subthemes, so I'm ok to make the change.
Comment #27
lauriiiThanks @pivica for pointing out on #18 what is the use case for having those rules set. Could we document that in the CSS as well so that when this is being looked at next time, it would be faster to get the idea why it is there?
Comment #28
ricksta CreditAttribution: ricksta at University of Texas at Austin commentedCSS inline comment added as per suggestion by @lauriii, along with interdiff from #18.
Comment #29
ricksta CreditAttribution: ricksta at University of Texas at Austin commentedComment #30
jonathanshawThanks for adding the comment @ricksta. However, we probably need it to explain the "why" (per #18) more than the "what".
Comment #31
davidhernandezComment #32
ricksta CreditAttribution: ricksta at University of Texas at Austin commentedUpdated comment in CSS for the patch to include the "why" as requested by @jonathanshaw.
Comment #33
ricksta CreditAttribution: ricksta at University of Texas at Austin commentedUpdating patch against latest 8.6.x commits. This includes updated comment in CSS for the patch to include the "why" as requested by @jonathanshaw.
Comment #35
mark_fullmerPatch in #33 has my RTBC -- tested in multiple browsers & with nested fields.
I'll defer to the maintainers of Classy for the official issue status change.
Comment #36
davidhernandezYou don't need my permission to change it to RTBC. If you reviewed it and it meets the criteria, feel free.
Comment #37
mark_fullmerComment #38
lauriiiThe question this should answer to is: why are we modifying the
.form-item
elements when it is the only child directly under an odd even colored table column. For me the rule seems very strict so there must be a specific reason why it exists, and that's exactly what we want to document here.Comment #39
jonathanshawI suspect no one knows why we only do this for odd/even colored tables. The answer to that may be lost in the sands of Drupal 4.7.
We could say "When a table row has a single form item prevent it from adding unnecessary extra spacing, but if it has multiple form items allow spacing between them."
Comment #40
twfahey CreditAttribution: twfahey as a volunteer and at University of Texas at Austin commentedUpdated with more descriptive comment per jonathanshaw's suggestion, which seems correct to me.
Comment #41
jonathanshawComment #42
ju.vanderw CreditAttribution: ju.vanderw as a volunteer commentedScreenshots were provided two years ago in #18, and are still applicable. Removing the "Needs Screenshots" Issue tag.
Comment #43
jonathanshawComment #44
jonathanshawComment #45
jonathanshawComment #46
xjmThanks @twfahey! In the future you can also post an interdiff so we can easily see the changes you made.
The visual fix itself looks right but as @lauriii said this is an unusually specific selector. If no one knows why we do this (as #39 suggests) then maybe we should not be doing it. :) What would
admin/modules
andadmin/config/regional/language
look like without the rule? Should those tables have their own CSS for this styling, rather than the general rule that is causing us problems here? Etc.Leaving at RTBC, but tagging for @lauriii's review again. Thank you!
Comment #47
lauriiiIt seems like the original CSS rule was introduced in Drupal 4.4.0 🐘I can't find any reason why this should be only applied to tables with odd even classes (rather than all tables). For example, it seems content list styles are broken since it doesn't have odd even classes.
For that reason something like this would probably make sense:
I'm sorry to come up with this feedback this late, but after my research, I started feeling making this change in Classy is too risky since this doesn't only affect core themes but all themes built on top of Classy. I'd like to suggest that we try to first come up with a proper fix in Seven, and once we are confident it works, try to find a way to move it to Classy. Currently, it is difficult to make this type of risky bug fixes to Classy, see #2659890: [Policy] [Plan] Drupal 9 and 10 markup and CSS backwards compatibility.
Comment #48
jonathanshawCreated #2982097: Margin on form-items in table rows (Seven) for Seven, postponing this on that.
Comment #49
Anatoliy Vorobyov CreditAttribution: Anatoliy Vorobyov commentedWe have patch and solution here:
https://www.drupal.org/project/drupal/issues/2982097
Comment #51
jonathanshaw#2982097: Margin on form-items in table rows (Seven) is now in.
Is this issue postponed on #2659890: [Policy] [Plan] Drupal 9 and 10 markup and CSS backwards compatibility, or is it postponed for a period of time to detect any problems from #2982097: Margin on form-items in table rows (Seven) ?
Comment #54
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedSince #2982097: Margin on form-items in table rows (Seven) was fixed long time ago I am updating the issue status here.
Comment #56
komalk CreditAttribution: komalk at Material for Drupal India Association commentedRerolled patch.
Comment #57
komalk CreditAttribution: komalk at Material for Drupal India Association commentedComment #63
BerdirThis will need a reroll for D10.
Comment #64
quietone CreditAttribution: quietone at PreviousNext commentedThis was discussed at a bugsmash group triage, with lendude and myself. lendude pointed out that that this breaks for form elements inside a table which isn't common in a front end theme. He looked at his own projects and did not find any custom CSS for this, suggesting that it might be fixed in Claro. Further, Umami only needs to support what it is needs for demonstration so it does not need a fix. That all seems reasonable so we have agreed to move this is contrib Classy.