Background: #2002336-86: Introduce a CSS class to hide borders of fieldset elements
Problem
-
An
input
element with a'size'
attribute value does not respect amax-width
applied via CSS, when theinput
element appears in afieldset
. - http://stackoverflow.com/a/18039139/811306
For some reason the size attribute over-rode the css widths.
- http://stackoverflow.com/a/1480592/811306
HTML controls the semantic meaning of the elements. CSS controls the layout/style of the page. Use CSS when you are controlling your layout.
In short, never use size=""
Proof
→ http://jsfiddle.net/sun/6gWA5/19/
Proposed solution
- Remove the default value for #size from all form input elements throughout core.
pre-patch field sizes
Click the following images to view full-size.
Demonstrations of post-patch field sizes
Comment | File | Size | Author |
---|---|---|---|
#89 | 2193271-89.patch | 7.01 KB | Nikhil_110 |
| |||
#89 | interdiff_88-89.txt | 323 bytes | Nikhil_110 |
#88 | 2193271-88.patch | 7.02 KB | Nikhil_110 |
#87 | 2193271-nr-bot.txt | 144 bytes | needs-review-queue-bot |
#82 | 2193271-82.patch | 7.01 KB | Abhijith S |
Comments
Comment #1
sunDamn. This reduces the width of input form elements to a default of ~10 chars throughout core...
Adding
min-width: 100%
fixes it. Hm.By supplying a default of 60, we seemingly intended to all input elements to have a default width that "fits into an assumed 1995-ish main page content container"...
→ When not exceeding the max-width of 100%, the default 'size' of 60 is an articulation of a relative font-based width.
→ Globally replace with
min-width: 20em
?I just tried that in the fiddle, and
min-width
overridesmax-width
:-(((Comment #2
sunApparently, this is caused by the wrapping fieldsets:
http://jsfiddle.net/sun/6gWA5/2/
Comment #3
sunComment #5
sunHuh, not even width works correctly for inputs in a fieldset: http://jsfiddle.net/sun/6gWA5/3/
Comment #6
markhalliwellYes please, let's remove it from core. We really shouldn't be using this anymore unless there's a good reason, like captchas and phone numbers (but even that's debatable). The themes are responsible for displaying how a form looks (especially in a lot of frameworks). If we "need" input widths on forms in core, we should be adding that CSS to seven or bartik.
Comment #7
markhalliwellAnother alternative would be to simply remove it from core add
#size
back in both the seven and bartik themes by preprocessing the elements. This would fix both the "get it out of core for themes that don't need it" and it would temporarily get around the CSS nightmares you're having. Bartik and seven kind of expect these to be set (I'm pretty sure they don't style input widths... could be wrong though).Comment #8
sunSorry — apparently, I distorted the tests my fiddle, by putting both an input with 'size' and one without into the same fieldsets:
The element with 'size' causes the wrapping fieldset to break the bounding box → the max-width of any other element is the already broken box width.
After splitting into separate fieldsets, it looks slightly better now: http://jsfiddle.net/sun/6gWA5/19/
→ We're able to apply
min-width
+max-width: 100%
However, we're not able to apply a font-relative min-width à la
min-width: 30em
, because that would always be the minimum width, regardless, of whether less horizontal space is available (breaking the layout again).We can only use a percentage, because a smaller percentage is always smaller than 100%.
Therefore, my proposed solution is this:
The min-width of 55% comes closest to the former default size of 60 for
Comment #10
sunComment #12
sunSorry, merge of latest HEAD went wrong.
Comment #13
markhalliwellThis REALLY should be added to the individual seven and bartik themes, not system.theme.css (which is also very assumptive). Many frameworks already provide handling of input elements. Enforcing this through core just causes completely unnecessary overrides.
Comment #14
mike stewart CreditAttribution: mike stewart commented-1
Without heavily considering the implications, I don't have a strong opinion on removing size from elements. Off the top of my head, I agree 'size' is not useful for presentation purposes; and CSS should be utilized. However, I beleive 'size' has useful functional purposes which affect browser behavior to ensure a max number of characters is not exceeded in a form, and therefore should be the same as the db field storing the submitted data.
That said, the problem #1 defined by the issue, that you cannot override the input size with css, the test code is incorrect. The tests incorrectly use max-width in an attempt to establish width. This is incorrect (and I agree CSS can be nightmarishly confusing in this regard). However, the correct way to override an element 'size' is to set the width on an element. You may ALSO add a max-width to ensure that element is contained within its parent container (such as a DOM parent or browser viewport).
correct test: http://jsfiddle.net/mdrmike/6gWA5/22/
supporting example: http://stackoverflow.com/questions/2125509/how-do-i-set-the-size-of-an-h...
Comment #15
mgiffordI'd actually be into having a set width for these form elements. I hate when there a jagged form elements. Much prefer a fully justified form myself.
Anyways, adding need for UX review.
Comment #16
sun@Mark Carver: Hm. While I can see the argument, I'm not 100% comfortable with doing that, because we'd force every theme to re-invent a sane default on its own.
In past discussions on similar topics, the benchmark always has been the Stark theme: Stark doesn't ship with any custom styles (except minimal layout), but our base expectation is that Drupal's user interface should at least look "sane" in Stark. — Without these sane defaults, every form input element would be way too small.
Also, the styles are added to system.theme.css only, which I think you want to (completely) replace/remove for a framework/base theme à la Booststrap & Co anyway. A clear separation between base/module and default theme styles was the whole point of the revised and modernized (SMA)CSS architecture in D8...?
In any case, we should manually test whether the proposed solution actually works throughout the entire Drupal core user interface. The 'size' attribute is pretty much removed from all input elements throughout core; including (smaller) search fields, [instant]filter fields, views exposed filters, forms in blocks like the user login form, etc.pp.
→ simplytest.me is most likely the easiest way for testing this change.
Comment #17
sunComment #18
fietserwin#14: size defines the visible width only, the maxlength attribute defines behavior (#maxlength in Drupal code). See e.g. http://www.w3schools.com/tags/att_input_size.asp.
Comment #19
webchickThis makes the installer look quite bad, so escalating to major.
Comment #20
mgifford@webchick - do you think it's worth just adding the CSS piece of this patch - core/modules/system/css/system.theme.css
So that the installer doesn't look so ugly? That could be done in a separate issue if this one is going to take some time.
Comment #21
Dragan Eror CreditAttribution: Dragan Eror commentedThis issue seams to become huge. This requires change in many areas, like:
Comment #22
Dragan Eror CreditAttribution: Dragan Eror commentedI wanted to test patch from #2193271-12: Remove default #size attribute from core in DrupalDevDays in Szeged, applied it automatically with git but returned errors when I tried to apply it to latest HEAD. I will try to re-roll the patch following git re-roll instructions https://drupal.org/patch/reroll
Comment #23
Dragan Eror CreditAttribution: Dragan Eror commentedRerolled patch
Comment #24
Dragan Eror CreditAttribution: Dragan Eror commentedLooks nice, here is screenshot.
Comment #25
LewisNymanI was initially confused by this patch because the issue title mentions removing the default size attribute only, but we're actually removing all #size declarations in core. This is going to end up being a really big patch because we're going to have to go through all the forms in core and write CSS against them to get them looking how they were before.
For example here's a before/after of the views edit page.
From my point of view it seems better to remove core form size attributes in a follow up.
Comment #26
webchickThis indeed looks like a massive undertaking, and I'm not sure how realistic it is.
I'd love a quick spin-off at this point to at least just fix the configuration page of the install screen. It continues to look really nasty, and it's literally like the first (ok, third) page people will see in Drupal 8.
Comment #27
Dragan Eror CreditAttribution: Dragan Eror commentedWe could put just
'#size' => NULL
in install page form elements, that would quick fix the bug.
Comment #28
Dragan Eror CreditAttribution: Dragan Eror commentedComment #29
LewisNymanI'm all for just removing the default attribute here, without modifying core's form structures. That should fix the install page.
Comment #30
sunA one-off fix for the installer pages may be done in #2195781: Configure Site page on install is badly formatted, not here.
Comment #31
LewisNyman@sun Can you update the title or the summary to make it clear what the intention of this issue is? Are we removing the default #size value or removing all #size values in core?
Comment #32
LewisNymanIn suns absence I'm going to take the lead from the current issue summary. This patch should only remove the default size attribute. It shouldn't remove the size attributes that are specifically defined.
The patch for this issue should be a lot smaller.
Comment #33
LewisNymanComment #34
webchickHm. I believe this would actually constitute an API change (suddenly certain form elements would look wider/thinner than normal without CSS correction in the theme in a minor version update), so should be pushed to 9.x instead.
Comment #35
yoroy CreditAttribution: yoroy commentedThis doesn't seem blocked on a usability review. Re-tagging.
Comment #36
catchI don't think this is an API change, even if we decided it is, we could probably add some core CSS to keep things looking the same in Stable.
Comment #38
joelpittetWe need to shorten the scope to what the issue title says and what @LewisNyman said
Comment #39
yoroy CreditAttribution: yoroy commentedSomething to just take a next stab at with a patch.
Comment #40
Orizontal CreditAttribution: Orizontal commentedworking on the issue @bohemier
Comment #41
bohemier CreditAttribution: bohemier as a volunteer commentedWorking on this from DrupalNorth2016. Here's a patch that removes #size from the following form elements:
Search
Datetime
Email
Tel
Textfield
Url
Weight
File
MachineName
Password
Tested the install screen and there are small changes in the ui. See attached screens. Easily fixed in css by applying
width: 100%
Comment #42
bohemier CreditAttribution: bohemier as a volunteer commentedComment #44
bohemier CreditAttribution: bohemier as a volunteer commentedRerolling... Modified the tests so that #maxlength is changed instead of #size
Comment #45
bohemier CreditAttribution: bohemier as a volunteer commentedComment #49
joelpittetThis needs a re-roll but mostly applies.
Comment #50
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-rolled.
Comment #51
tonifisler CreditAttribution: tonifisler at Antistatique commentedI'm looking at the patch right now (Vienna 2017 sprints).
Comment #52
joelpittetThanks @Jo, we are working on this at the core mentored sprint. The next steps are:
#size
in core)Comment #53
tonifisler CreditAttribution: tonifisler at Antistatique commentedLooking for any missed instances of
#size
:)Comment #54
rominronin CreditAttribution: rominronin commentedHere at DrupalCon Vienna - I'm about to work on this issue.
edit: Part 2: Manually testing
Comment #55
al0aAlso tested it, input fields get smaller, but it's doesn't break any functionality.
Comment #56
mradcliffeThank you for the screenshots, @al0a. Can you embed the images into the issue summary?
Comment #57
rominronin CreditAttribution: rominronin commentedIn order to test patch #50, I added the following fields to a basic page type:
Timestamp
Email
File
Tel
Text (plain)
Link (for URL)
and Number (integer) (fall-back for weight)
My feedback on the above is the following:
Timestamp: no size attribute
Email: size = 60
File: size = 22
Tel: no size attribute
Text (plain): size = 60
Link (for URL): no size attribute (same for the accompanying link text field)
and Number (integer) (fall-back for weight): no size attribute
It seems like accompanying css might be a necessity to this patch?
I'll follow up with demonstrations of the outstanding changes.
Screenshots in chrome:
Comment #58
rominronin CreditAttribution: rominronin commentedComment #59
tonifisler CreditAttribution: tonifisler at Antistatique commentedAs said before (#38), this patch "shouldn't remove the size attributes that are specifically defined". The underlying problem is, as said in #34, that the fields that were relying on the default
'#size'
value will be wider/thinner.Should we set those specific fields with a default
'#size'
value or are we ok with the small visual changes in some cases?Comment #60
jenlamptonIt probably depends on the fields. If there is a good reason to set a size attribute, we should add it. If there's not, the small visual changes are probably an improvement.
Comment #61
tonifisler CreditAttribution: tonifisler at Antistatique commentedOk so this seems to work and not break any fields. We can merge this and open a new issue if there are fields that need to be wider or narrower - that should be fixed in CSS / Theming.
Comment #62
al0aComment #63
larowlanComment #64
yoroy CreditAttribution: yoroy commentedThere are some broken links to images in the issue summary.
FWIW, I'm ok with this patch introducing minor visual changes. Setting more specific widths where needed in a follow up issue is a good idea (URL field looks potentially a bit small for the external URL use case for example). Maybe we should open it already?
Comment #65
alexpottI'm wondering if we are worried about this introducing visual regressions in live sites? The minor visual changes to core themes look fine but maybe custom and contrib won't be so forgiving?
Comment #66
xjmVisual disruption could potentially be allowed in minor releases, but this issue does seem extremely disruptive. On the other hand I also can't think of how we'd provide BC for this change that wasn't more problematic than the change itself, nor could I come up with how I would make this change in the continuous upgrade path.
Cottser's frontend BC notes say:
So, well, agreed on leaving it for the frontend framework managers to review as tagged in #63. For the bit that's within my purview: I don't think this is really a major unless theme or render system maintainers feel particularly that it should be. It was promoted in #19 for some visual regressions in the installer that should have been addressed (presumably long since) with more direct, less sledgehammer fixes.
Comment #67
catchI see the screenshots, but unless I'm missing something do we only have 'after' screenshots and not 'before'?
Comment #68
mradcliffeI spun up a core 8.5.x in simplytest.me and added the same fields as @rominronin did in #57 to take before screenshots. Added to issue summary.
I reduced the embedded images width to 50% and wrapped those images in links so we can click on them to view fully.
Comment #71
xjmThanks everyone for working on this.
Discussed with @Cottser and @effulgentsia. We're not actually convinced this change is necessary anymore, or at least not sufficiently so to justify the disruption, for a few reasons:
Per @effulgentsia, all three input elements were rendered as the same size.
max-width
of100%
, which seems like a pretty specific case that doesn't justify the disruption. The other evidence in the summary like one person expressing an opinion on stackoverflow that we (including Cottser, a frontend and theme system maintainer) didn't know of as a best practice.If we were to make this change, we'd need several things:
#size
element in place about all these items (maybe it should since someone could still probably specify it on their individual form, but we should confirm that.)#size
explaining to the developer why this change was made, so that they could follow the best practice in their own code.But before we jump down the rabbit hole of most of that work, let's have that subsystem maintainer signoff and that stronger case for making the change. Otherwise, we might want to mark this issue wontfix instead. Thanks!
Comment #73
mradcliffeRemoving Novice tag from the issue as it's currently in limbo waiting on subsystem maintainer review.
Comment #74
markhalliwellGiven that CSS can [now] fix the OP, I say that we "won't fix" this issue. Chasing browser bugs has never led us down a decent rabbit hole and we certainly have other bigger fish to fry instead of putting the required effort that will be needed to keep BC for this change.
Comment #77
andeersg CreditAttribution: andeersg at Bouvet commentedI would still argue that the default
size="60"
parameter is bad.It totally breaks flexbox: https://jsbin.com/sabefubagu/4/edit?html,css,output.
If the width of the container is too small for
size="60"
the input will be pushed outside.Comment #81
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedPatch #50 can't be applied on 9.2.x.Needs reroll
Comment #82
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedAdded reroll for patch #50 ,Please check
Comment #87
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #88
Nikhil_110 CreditAttribution: Nikhil_110 at Srijan | A Material+ Company commentedAttached patch against Drupal 10.1.x
Comment #89
Nikhil_110 CreditAttribution: Nikhil_110 at Srijan | A Material+ Company commentedFixed CC issue
Comment #90
RassoniComment #91
smustgrave CreditAttribution: smustgrave at Mobomo commentedWas previous tagged for issue summary appears that still needs to happen also.