Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#18 | after-date.png | 122.14 KB | emma.maria |
#18 | before-date.png | 91.28 KB | emma.maria |
#17 | bartik-date-label-size-2653914-17.patch | 954 bytes | kevin.dutra |
#17 | interdiff.txt | 556 bytes | kevin.dutra |
#16 | after-solo-2.png | 38.16 KB | emma.maria |
Comments
Comment #2
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commentedComment #3
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commentedPatch in #2 uses the same rule as is defined in Bartik's
form.css
for the real.form-item label
.Comment #4
gnugetCan you add a couple of screenshots with and without your patch?
Thanks!
Comment #5
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commentedCertainly. 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. :)
Comment #6
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commentedWhat a dork...I reversed the labels on those images. Here they are with correct labels.
Before
After
Comment #7
emma.mariaUnassigning to allow others to review @kevin.dutra's work.
Comment #8
gnugetI 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!
Comment #9
emma.mariaThanks 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.
Comment #10
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commented@emma.maria: were you able to take a look at the CSS codebase?
Comment #11
emma.mariaHi 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
.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.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)
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.
Comment #12
emma.mariaComment #13
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commentedThank 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.)
Comment #14
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commentedComment #15
emma.mariaThanks 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.
Comment #16
emma.mariaOK 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
Comment #17
kevin.dutra CreditAttribution: kevin.dutra at Workday, Inc. commentedWhoops, 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.
Comment #18
emma.mariaCheers 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
Comment #19
emma.mariaComment #20
emma.mariaSuggested 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'
Comment #22
gnugetRetesting against 8.1.x
Comment #23
star-szrMoving to 8.2.x because this is a UI change and also minor :)
Comment #24
yoroy CreditAttribution: yoroy commentedComment #26
webchickGreat work on this fix! What a silly bug. :) Before/after screenshots are especially helpful.
Committed and pushed to 8.2.x. Thanks!
Comment #27
webchickOopsie. Credit.
Comment #29
Gábor HojtsyThanks, removing from UX sprint now.