Problem/Motivation
Drupal has shipped with the Farbtastic library since Garland was added in 2006 to allow users to select colors from a color picker in themes.
Nowadays, the "color" HTML input type is widely supported in all major browsers except IE11 (https://caniuse.com/?search=color) and provides a preferred native UI/UX for this functionality.
Proposed resolution
Use the "color" input type in color.module.
Remaining tasks
- Deprecate Farbtastic?
User interface changes
The color picker in color.module will be replaced with a native UI, except in IE11 where colors can only be entered by hex code.
API changes
Data model changes
Release notes snippet
The color picker used in theme settings has been replaced with the native browser widget.
Related Issues
- Originally postponed on #1445224: Add new HTML5 FAPI element: color
- Postponed on #1957400: Improve Color's admin interface on touch devices
Original report by @nod_
Works well on FF, Opera. Chrome implementation of the color widget is messed up, hopefully they will fix it.
Providing a patch to allow testing from other people and hopefully come up with a proper strategy for weird browsers. Color input type is kinda the bleeding edge, we'll get cut.
The js in itself needs quite some work, but outside the scope of this issue.
Comment | File | Size | Author |
---|---|---|---|
#56 | HwhoTOBo.png | 62.5 KB | mherchel |
Issue fork drupal-1651344
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedThanks _nod! We're also going to be able to remove the "custom" validation and conversion from the color module. We also have to check the preview correctly keeps updating in browsers that *do* support the color widget. Maybe we should also disable the color picker in that case.
The common way to do feature detection here would be
$("<input type='color' />")[0].type === "color"
.Comment #2
nod_(: That was a quick and dirty patch to make color patch testing easier.
It does work with browser having native color picker (beside some weirdness in chrome). The preview gets updated as expected. I'd get rid of jQuery to do the feature testing. And you should actually append the input to the body to be able to check the type, in a detached element it just pretend it supports it (jQuery might do fancy things during element creation so maybe that just works).
Yeah could be a good thing to not use it for proper browsers. But we need to be careful with feature detection, at some point chrome was saying it supported the color input but didn't have any color picker for it, was pretty much useless.
And yes there needs to be cleanup added to this patch.
Comment #3
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedIt's in, it's in!
Comment #4
nod_There is some HSL conversion going on, which function should be added to the color class? rgbToHsl, hexToHsl? both? all possible permutations?
There are a couple of helper functions that are needed for the conversions, should they end up in color module as well?
Comment #5
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedMaybe we should reconsider having color objects with state. Just something like Color::createFromRgb(), Color::parseHex(), Color::createFromHsl(), Color::getRgb(), Color::getHsl(), Color::__toString() would buy us all permutations.
However I already had a lengthy argument about this, with sun. I should probably ask him what he thinks.
Comment #6
sunMy stance is still the same ;)
1) We introduced the custom Utility\Color class, because there is no simple generic utility class anywhere out there. For the Form API element, we did not want to move these rarely used functions to form.inc, common.inc, or a new color.inc. Thus, we added some simple helper/conversion methods to a PSR-0 class that can be autoloaded on demand. (Some sites might never load this.)
2) For Color module, I can see a point in that it might need a full-blown classed Color object. In fact, the module passes some $color variables around within its code that actually are pristine typed variables/objects. But when reaching the point in that we need more powerful and stateful Color class objects, we should immediately stop to think about writing own code. That would only re-invent the wheel; there are a couple of Color classes out there.
It might even make most sense to collaborate with the #1561832: Replace Image toolkit API with Imagine idea/effort — and apparently, Imagine has a dedicated Color class, too:
http://imagine.readthedocs.org/en/latest/usage/introduction.html#color-c...
(Note: I'm not necessarily saying that we should use this particular Color class. That's just one out of many implementations that can be found on the net. Just google for "php color class." There might be better ones. Just saying that there is a chance that we'll replace image toolkits with Imagine and it has one; but then again, there also hasn't been any progress on that issue yet.)
Comment #7
markhalliwellTriggering bot, will probably need a re-roll though.
Comment #9
runeasgar CreditAttribution: runeasgar commentedPer @Mark Carver : the "color" input type isn't supported by most browsers yet, so postponing this on #1957400: Improve Color's admin interface on touch devices
Comment #9.0
runeasgar CreditAttribution: runeasgar commentedUpdated issue summary.
Comment #9.1
runeasgar CreditAttribution: runeasgar commentedUpdating format.
Comment #9.2
runeasgar CreditAttribution: runeasgar commentedUpdated issue summary.
Comment #10
mgiffordI am pretty sure it's now supported on FF 29. Just nudging this along, but this might need to be moved to D9 anyways.
Comment #11
LewisNymanIn my opinion, having a simple text box where you can type in a hex value is an perfectly accessible fallback, the colour picker is an enhancement. We could decide to implement the colour input type and then decide on a polyfill in a follow up.
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedJ'agree – I'm going to have a go at extending #10 to remove farbtastic entirely.
Comment #13
nod_Can you make a new issue dedicated to removing farbtastic without the input type change please? This issue is only about changing input type. It's fine to postpone this one on your new issue but it needs to be two patches.
Comment #14
nod_Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commentedSure thing nod_, makes sense. New issue is https://drupal.org/node/2268955
Comment #16
martin107 CreditAttribution: martin107 commentedTriggering testbot
Comment #18
markhalliwellhttp://caniuse.com/#feat=input-color
Still less than 50% support (only FF and Chrome).
Also, this is still a feature request (want), not suitable for 8.x at this point.
Comment #19
markhalliwellAs @Bojhan mentioned in IRC, we can possible roll this out in 8.1+ once we get more support for this input type in most browsers. Leaving postponed until then.
Comment #20
mgiffordOpera & Android support it now too.
Comment #30
longwaveThis is now available to 93% of users so I think we can un-postpone?
https://caniuse.com/input-color
Comment #31
longwaveComment #32
sokru CreditAttribution: sokru as a volunteer commentedReroll from #10.
Comment #34
meena.bisht CreditAttribution: meena.bisht at QED42 for Drupal India Association commentedComment #36
raman.b CreditAttribution: raman.b at OpenSense Labs commentedRemoving custom validation for
color_scheme_form
Comment #37
raman.b CreditAttribution: raman.b at OpenSense Labs commentedAlso, just realized that
color.js
was edited directly in #32Comment #38
longwaveThe code looks great but I think this could do with some screenshots in different browsers so we can confirm that it looks usable everywhere.
Comment #39
bnjmnmManual testing surfaced some issues:
Addressing the above would likely require some pretty complex conditional logic to apply different styles and lock behavior based on native support vs Farbtastic. However, https://caniuse.com/input-datetime shows that the only browsers that don't support native color pickers are IE11 (which we're looking into getting rid of for 11) and Opera Mini (which I suspect is rarely used to interact with the color module)
My proposed solution is for the color module to stop using Farbtastic and have IE11 and Opera Mini use text inputs instead of color. A similar solution was implemented on date inputs here: #3072906: Deprecate and remove jQuery UI datepicker. In that issue, browsers that don't support native date inputs now use a text input. Seeing how this was acceptable for ALL date fields in Drupal, I think it's acceptable to do something similar to a handful of inputs provided by the color module, particularly since there's wider browser support for color than there is date.
I suspect a release manager would need to approve this proposed solution, so tagging accordingly.
Comment #40
mradcliffeI am removing the Novice tag from this issue because there isn't anything actionable to do until @bnjmnm's proposed solution for browser compatibility is reviewed.
Comment #41
bnjmnmAdding the "remove jQuery from Drupal" issue as a parent issue since Farbtastic is a jQuery library that needs to be removed/replaced as part of those efforts.
Comment #42
ckrinaWe discussed this today at the Weekly Usability meeting and we didn't see any concern with removing the color picker option for IE11 users because they still could add the color manually as a fallback, and even more if a note is added as @bnjmnm mentioned. So +1 to this.
Comment #43
nod_Comment #44
bnjmnmChanges in this patch
Drupal.colorUtils
object with utilities for converting values such as HSL to Hex. Most of these functions are taken from Farbtastic and updated to meet Drupal CS.Among the tasks that still need to be done:
Drupal.colorUtils
is based on Farbtastic utility function.Comment #46
nod_Looking good :)
fixed a few alignemnt issues with the locks, rolled for 9.3.x
Added some stub jsdoc comments to be completed.
Comment #48
nod_Comment #49
longwaveUpdated the issue summary. Not sure if we should deprecate Farbtastic here or defer that to a followup, as it is used by a handful of tests and maybe that is better off unpicked elsewhere.
Comment #52
nod_I think the deprecation should be done as part of this issue. That's in line with how the previous deprecation were made. As per the priority rules, decoupling from an unmaintained dependency is a major task.
Closing the related issue as duplicate and added commit credit to this one.
From #2268955-29: Deprecate farbtastic library
But the spec says it's a feature not a bug:
Comment #53
andypostIt just needs to make color picker form element to apply different library behaviour
Comment #54
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedThe HTML colour input type (like many of the new HTML5 input types) has poor accessibility support.
Accessibility has barely been mentioned in this issue. Lewis mentioned it back in comment #11 7 years ago:
That sounds OK... kind-of, but it contains some false assumptions: (1) that there is a text box you can type in, and (2) that you can just use the text box and avoid having to use the colour picker. This turns out NOT to be the case in some user-agents.
e.g. Chromium on Android with Talkback (I tried Chrome and Edge on Android 9):
And that's just one browser/AT/OS combination.
Detailed manual test results of the colour input from 2019 paint a poor picture for lots of other common browser/AT/OS combinations. It's looking dire for speech control users.
None of this is Drupal's fault, but it is our problem.
Replacing an old library is an understandable motivation, but replacing it with something which has poor accessibility is doing a diservice to our users, and doesn't meet our values.
I'd urge extreme caution here (i.e. exercise a veto). The HTML colour input is NOT fit for purpose (per WCAG's "accessibility supported" conformance requirement). "Works on Safari/Voiceover" won't suffice. If we want to ditch our old library, we need to replace it with a better one, not just foist the HTML colour input on users.
Comment #56
mherchelDiving into this a bit (we’re hoping to implement color-choosing within Olivero).
A good deep dive on color picker accessibility is at https://css-tricks.com/color-inputs-a-deep-dive-into-cross-browser-diffe...
Reading through and testing these, @andrewmacpherson, I agree that it’s not accessible enough.
However in some browsers, the color picker does seem to be accessible and provides decent utility to keyboard users.
How the Color module works
The color module provides simple text inputs, which JS grabs ahold of and generates the color picker. The color picker itself is not focusable. The text inputs are.
Proposed solution
I propose that we keep the primary form control to be a text input. However, I also propose that we use vanilla JS to create a HTML5 native color input. Both the text inputs and color inputs would have `input` events bound to each other so they would always stay synchronized. We could also add form validation to ensure that the hex value is valid.
This solution would enable the current accessible utility of how the color module works. However it would remove farbtastic, and rely on the native color picker (which seems to be accessible in certain browsers) for color picker functionality.
Here is a quick and dirty example of what that could look like (note this has no form validation, which would need to be added):
https://codepen.io/mherchel/pen/poWZZPK
Comment #57
bnjmnmEspecially considering that Farbtastic is now read only (unsure when that happened), I think some form of the solution in #56 should be added to core. The value can still be updated via text input, so there's no regression in that respect, and it's very unlikely that native inputs are somehow less accessible than Farbtastic, despite their well-documented shortcomings.
There is a use case I'd like figured out:
It seems beneficial for the native color picker to be focusable, but that means there are two focusable elements for updating a single field. Visually, this relationship is clear (as evidenced by the Codepen in #56). I'm not sure how to best convey this relationship to AT. It's possible there's is a common pattern that I've forgotten.
It may also be worth looking into a visually hidden bit of help text making AT users aware of the accessibility limitations of datepickers, and recommending the text field be used instead.
I think if these are taken into consideration, it will offer equivalent-at-worst accessibility, with the added benefit of native color pickers improving in the future without Drupal having to do anything vs. Farbtastic being frozen in time.
Comment #58
andy-blum@bnjmnm - would the correct version simply be to have a label element without the 'for' attribute and use aria-labelledby on the inputs?
https://stackoverflow.com/a/31274644
Comment #59
mgiffordI like the idea of the move. Native support is usually more accessible.
Is there a link to the Chrome bug. Always useful to have links to and from Drupal to upstream barriers.
I'd have to see how the focus is set to see if it is a problem. Definitely want it to be intuitive for keyboard only users.
Comment #60
xjmI reopened the discussion to deprecate Color today. (Even if it does move to contrib, I think this issue is still the right path forward for the contrib module, but it's less of a hard D10 blocker if we end up deprecating the whole module.)
Comment #62
quietone CreditAttribution: quietone at PreviousNext commentedColor has been removed from core, #3270899: Remove Color module from core.
Comment #63
quietone CreditAttribution: quietone at PreviousNext commentedThe parent issue is in core and that doesn't really makes sense since this is in contrib. Moving that parent to related to help retain the history.