Suggested commit message:

git commit -m 'Issue #2653914 by kevin.dutra, emma.maria, gnuget: Date form field display label has visual differences to other form fields'

The date widget is composed of (potentially) two form elements, one for date and one for time. The real labels for these two elements are visually hidden and instead a faux label, rendered as an <h4>, is used to mark label the widget. However, the CSS applied to this faux label doesn't match the font size of other normal labels.

This appears to only affect the Bartik theme; in Seven, the faux label is the same size as the rest.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kevin.dutra created an issue. See original summary.

kevin.dutra’s picture

Status: Active » Needs review
FileSize
352 bytes
kevin.dutra’s picture

Patch in #2 uses the same rule as is defined in Bartik's form.css for the real .form-item label.

gnuget’s picture

Can you add a couple of screenshots with and without your patch?

Thanks!

kevin.dutra’s picture

FileSize
77.99 KB
67.88 KB

Certainly. Here are the before and after shots. The difference is really minor; I didn't even notice it until someone else pointed it out to me and I looked closer. :)

kevin.dutra’s picture

FileSize
67.88 KB
77.99 KB

What a dork...I reversed the labels on those images. Here they are with correct labels.

Before
Label size before

After
Label size after

emma.maria’s picture

Assigned: kevin.dutra » Unassigned
Issue tags: +Usability, +CSS, +frontend

Unassigning to allow others to review @kevin.dutra's work.

gnuget’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed manually some pages and there are other places with the tag h4 and the class label (like /user/[0-9]) but certainly this is the only place where I found the combination h4 + class label + input.

So this is RTBC to me.

Great work!

emma.maria’s picture

Assigned: Unassigned » emma.maria
Status: Reviewed & tested by the community » Needs review

Thanks for the work @kevin.dutra and @gnuget!

Sorry for knocking this back, I'm going to take a quick look at the CSS codebase first before this is passed onto a committer.

kevin.dutra’s picture

@emma.maria: were you able to take a look at the CSS codebase?

emma.maria’s picture

Title: Bartik date field widget label is slightly too big » Date form field display label uses a <h4> element which cause visual differences compared to all other form field labels that use <label>
Assigned: emma.maria » Unassigned
Issue summary: View changes
Status: Needs review » Needs work
Issue tags:
FileSize
438.99 KB

Hi Kevin, thanks for the issue and the patch. Sorry this took so long, this issue needed more thought than first anticipated. (I was thinking of chasing the datetime.module because of the use of a <h4> but I have since studied the core form markup and the HTML standards for forms).

I've noticed that the code does not follow a few of the core CSS coding standards.

Here are the coding standard conflicts for future reference...

We shouldn't fight broken visual styles by bulking up selectors with classes that only match that specific context eg. .field--type-date-time.

This may seem natural, but actually makes CSS less predictable and maintainable. Sooner or later you’re going to need that component style somewhere other than a sidebar! Or, the reverse may happen: a new developer places a component in the sidebar and gets an unexpectedly different appearance.

Referenced from https://www.drupal.org/coding-standards/css/architecture#pitfall-context

And we shouldn't use HTML structure within selectors ie. the <h4> tag itself, to provide styles.

Mirroring a markup structure in our CSS selectors makes the resulting styles easy to break (with markup changes) and hard to reuse (because it’s tied to very specific HTML).

Referenced from https://www.drupal.org/coding-standards/css/architecture#pitfall-structure

So in Bartik form.css there are already styles to style all other labels with the correct font and sizing without being too specific to the type of form element it is. We need to apply the same styling rules using the HTML structure that datetime is using for it's wrapper and label.

Here is the label styling that already exists Bartik form CSS - (which isn't perfect but will be refactored in the future... #2502027: Clean up the "form" component in Bartik)

.form-item label {
  font-size: 0.929em;
}

.node-form label,
.node-form .description {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

We can use the same format of selector which is .form-wrapper .label and add it to the styles above to match the other form field element styles on the page. Then any other form item instance that matches what datetime does can benefit from the styles.

It's not the best solution, but it makes it slightly more reusable than the existing patch in this issue. I will also document this change to be refactored further in #2502027: Clean up the "form" component in Bartik.

emma.maria’s picture

Title: Date form field display label uses a <h4> element which cause visual differences compared to all other form field labels that use <label> » Date form field display label has visual differences to other form fields.
kevin.dutra’s picture

Thank you for the thorough review @emma.maria! Your suggestions all make sense to me. And also ugh! I thought this would all be simple initially, but it's turning out to be much more involved. :)

It seems that the use of an <h4 class="label"> is intentional when a field is composed of multiple form elements. In this particular case, there can be two (one for date and one for time, depending on how the field is configured). Each of the individual form elements actually do have a <label> -- they're just visually hidden -- so the field label can't really be a proper <label>.

This same principle is applied when a field has cardinality > 1. At that point, the widget renders as a <table> with an <h4 class="label"> header for the field label. As a result, only using .form-wrapper .label has the unintended consequence of reducing the field label size on any multi-valued field too (datetime or otherwise). I've added that second rule to counteract this. Maybe there's a better way to work around that, but nothing was jumping to mind immediately.

(And FWIW, the label size for those multi-valued fields is smaller than for their single valued couterparts, but probably outside the scope of what we're trying to do here. I just returned them to their current size.)

kevin.dutra’s picture

Status: Needs work » Needs review
emma.maria’s picture

Thanks Kevin for the further research into the fields markup. And yes the simplest things seem to gain so much complexity!
I will take visually take a look at the fields with a cardinality of >1 with the patch applied and post some screenshots.

emma.maria’s picture

Issue summary: View changes
Status: Needs review » Needs work
FileSize
25.52 KB
43.85 KB
61.89 KB
38.16 KB

OK good shout on the .form-wrapper .field-multiple-table .label selector.

The date label now has the correct sizing...

Before


 

After

 

 
The patch however needs one more thing. The label also needs to have the correct font set to it. Please can the selector be added to the code block I posted in #11 which has the font declaration in it?

Thanks

kevin.dutra’s picture

Status: Needs work » Needs review
FileSize
556 bytes
954 bytes

Whoops, brain fart. This patch includes the font family change as well as a similar workaround for the multi-valued fields, which of course use a slightly different font.

emma.maria’s picture

Issue summary: View changes
FileSize
91.28 KB
122.14 KB

Cheers Kevin this is great.

We have added a fix to allow fields such as 'Date' who have a different markup structure and have to use a .label class instead of a <label> to have consistent label styling with the rest of the fields in core.

The CSS can be refactored further in the future once we tackle what we have existing in the form.css file already - #2502027: Clean up the "form" component in Bartik. For now we have looked into all scenarios where this code could provide visual regressions and accounted for them.

See before and after screenshots.

Before
 

 
After
 

emma.maria’s picture

Status: Needs review » Reviewed & tested by the community
emma.maria’s picture

Issue summary: View changes

Suggested commit message:

git commit -m 'Issue #2653914 by kevin.dutra, emma.maria, gnuget: Date form field display label has visual differences to other form fields'

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: bartik-date-label-size-2653914-17.patch, failed testing.

gnuget’s picture

Status: Needs work » Reviewed & tested by the community

Retesting against 8.1.x

star-szr’s picture

Version: 8.0.x-dev » 8.2.x-dev

Moving to 8.2.x because this is a UI change and also minor :)

yoroy’s picture

Issue tags: +sprint

  • webchick committed c261af6 on 8.2.x
    Issue #2653914 by kevin.dutra, emma.maria, gnuget: Date form field...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great work on this fix! What a silly bug. :) Before/after screenshots are especially helpful.

Committed and pushed to 8.2.x. Thanks!

webchick’s picture

Oopsie. Credit.

Status: Fixed » Closed (fixed)

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

Gábor Hojtsy’s picture

Issue tags: -sprint

Thanks, removing from UX sprint now.