Problem/Motivation

When choosing inline labels in "manage display," the classy theme (and template) attaches a "field--inline-label" class to the div that contains the inline field and label. Then, the inline label contains a class ".field--label-inline .field__label" that floats the label left.

However the enveloping div should include a "clearfix." Because clearfix is missing, any subsequent non-text fields will float up onto one line.

This bug can often be disguised if a field containing an inline label is a text field, since text fields automatically contain a clearfix, or when a field using an inline label is followed by a text field, since that clearfix will clear the float from the prior inline label.

NOTE: Since Bartik uses classy as a base theme, the problem occurs there as well.

Proposed resolution

Add a clearfix class to the div enclosing the field label and field contents in the template, OR

Create a ".field--label-inline" class for the div only, that will clear the label's float in "core\themes\classy\css\components\field.css"

Remaining tasks

User interface changes

API changes

Data model changes

Comments

zoon_unit created an issue. See original summary.

darketaine’s picture

Could you upload a screenshot where that happens (wherever I see it it's combined with a clearfix class so I can't reproduce it)? In what field type?

There is a discussion that 'clearfix' should be removed anyway: #2544868: Discuss removing 'clearfix' class from Classy
So I guess there is no option to insert one more here (at least for now).

darketaine’s picture

Status: Active » Needs review
StatusFileSize
new475 bytes
new207.77 KB
new203.98 KB

So, using Classy as default theme we have the first screenshot (Bartik "solves" this with a clearfix on specific fields).

In context of avoiding the clearfix logic some CSS was applied on 'field--label-inline'

darketaine’s picture

StatusFileSize
new418 bytes

Did it again to be typically correct with the right element order.

zoon_unit’s picture

StatusFileSize
new61.2 KB
new57.63 KB

Here's an example of the issue, with a fix that I added in my custom css, replicating the clearfix class.

The first example comes from Bartik as the default theme. Bartik provides clearfix on text fields, but not on entity reference fields, so you can see the error. Several "non-text" fields have floated to the same line, due to the absence of a clear.

In the second example, I created a sub-theme of Bartik, thereby allowing me to add a "fixing css" file, where I added the clear.
not fixed
fixed

john cook’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new27.39 KB
new24.03 KB

I have applied the patch and it works as designed.

Before:

After:

catch’s picture

Assigned: Unassigned » star-szr
yesct’s picture

Version: 8.0.5 » 8.1.x-dev
Issue summary: View changes

re-organized the issue summary with the issue summary template https://www.drupal.org/issue-summaries (I used https://dreditor.org/ issue summary button)

8.0.x is not open anymore, and 8.2.x is in beta https://groups.drupal.org/node/512705
but bug fixes are allowed in patch releases (8.1.x) https://www.drupal.org/core/d8-allowed-changes#beta
so changing version to 8.1.x

yesct’s picture

Issue tags: +Drupalaton
star-szr’s picture

Version: 8.1.x-dev » 8.3.x-dev
Assigned: star-szr » Unassigned
Status: Reviewed & tested by the community » Needs work

Thanks for this.

Making a change like this is a bit tricky IMO because some people might expect inline to not fill the "row" but from a site builder POV…

I think the behaviour proposed here makes the most sense and themers can still override it if they do want to have multiple fields in a row, it is a bug that setting the label inline sets the entire field to inline. The fact that text fields clearfix already also helps. Having said that there is a risk for disruption so I think this would only be safe to commit to 8.3.x at this point.

My only gripe is minor about the placement of the code in the CSS file, it starts with .field__label and then the rest is all .field--label-inline so can we move this new CSS below the first selector?

Edit: Actually setting the field label to inline shouldn't mean that the entire field is inline, very important difference there, so edited above to reflect that.

mikeker’s picture

Status: Needs work » Needs review
StatusFileSize
new602 bytes
new475 bytes
new79.98 KB
new81.21 KB

OK, I think this is where @Cottser wants the CSS...? I couldn't find anything in the CSS coding standards for ordering element vs modifier rules. Is there?

Before:

After:

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikeker’s picture

Patch in #11 still applies to 8.4.x without modification.

Version: 8.4.x-dev » 8.5.x-dev

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

Vidushi Mehta’s picture

StatusFileSize
new477 bytes

#11 is failed to apply on 8.5.x so rerolled the patch.

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

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

kay_v’s picture

A solution proposed in the issue summary above is to "Add a clearfix class to the div enclosing the field label and field contents in the template." This proposal matches up with @alexpott's recommendation in a thread that duplicates this one (#2850075: When Setting Field Label to 'Inline', subsequent fields are affected by 'float: left;'). He gets more specific, recommending "only add[ing] clearfix when the label is inlined." Later in the same duplicate thread, Alex wonders whether it would be appropriate to take the approach taken in the last patch attached above (the second approach proposed in the issue summary above).

I agree with the first recommendation in each instance: adding .clearfix to the container of label and contents complies with the Drupal standard that CSS "be abstracted out into a common reusable class." The approach in the latest patch creates a new style associated only with .field--label-inline that is a 1:1 repeat of .clearfix.

Interested in others' review of that logic, of course.

kay_v’s picture

Status: Needs review » Needs work
kay_v’s picture

Status: Needs work » Needs review
StatusFileSize
new473 bytes

here's a patch with the proposed change

adriancid’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new45.25 KB
new44.05 KB

I can confirm the problem and that the patch solves the problem.

Before:

After:

adriancid’s picture

StatusFileSize
new44.05 KB

Status: Reviewed & tested by the community » Needs work
kay_v’s picture

Status: Needs work » Reviewed & tested by the community

resetting to rtbc - the testbot comment above says tests failed, but viewing results shows all the tests passed.

alexpott’s picture

Adding credit from duplicate issue.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

As per #10/@Cottser as this can only go into 8.6.x for fear of possible disruption - we should have a change record for themers here that states that inline field labels now have the clearfix class applied in classy.

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.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vladimiraus’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Change record added: https://www.drupal.org/node/3040758
Should we retro fit it for 8.7?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ytsurk’s picture

Yes, I definitely vote for a backport! But even more important to just make it in ;)

vladimiraus’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Needs review » Reviewed & tested by the community

Change record added as requested.

lauriii’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs steps to reproduce

Could someone add the steps that need to be taken to reproduce this?

vladimiraus’s picture

Status: Needs review » Reviewed & tested by the community

@lauriii All steps in Problem/Motivation.

When choosing inline labels in manage display, the classy theme (and template) attaches a .field--inline-label class to the div that contains the inline field and label. Then, the inline label contains a class .field--label-inline .field__label that floats the label left.

  • lauriii committed bffed55 on 9.0.x
    Issue #2679775 by darketaine, mikeker, kay_v, Vidushi Mehta, adriancid,...

  • lauriii committed c44e1df on 8.9.x
    Issue #2679775 by darketaine, mikeker, kay_v, Vidushi Mehta, adriancid,...
lauriii’s picture

Version: 8.8.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs steps to reproduce

I couldn't reproduce this with Bartik. I created an empty theme that extended Classy and I could reproduce this.

Committed bffed55 and pushed to 9.0.x and 8.9.x. Thanks!

I don't think we should backport this to 8.8.x to minimize any regressions on patch releases.

Status: Fixed » Closed (fixed)

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