[IMP] web: ensure a fully transparent color is made opaque on edition

This allows the user to not have to understand that it has to decrease
the transparency by himself.

Part of https://github.com/odoo/odoo/pull/67545
task-2476601
This commit is contained in:
qsm-odoo
2021-07-13 08:20:02 +00:00
parent f383905616
commit d8a632fbfc
@@ -187,6 +187,12 @@ var ColorpickerWidget = Widget.extend({
* @param {integer} [a]
*/
_updateRgba: function (r, g, b, a) {
// Remove full transparency in case some lightness is added
const opacity = a || this.colorComponents.opacity;
if (opacity < 0.1 && (r > 0.1 || g > 0.1 || b > 0.1)) {
a = 100;
}
// We update the hexadecimal code by transforming into a css color and
// ignoring the opacity (we don't display opacity component in hexa as
// not supported on all browsers)
@@ -211,6 +217,12 @@ var ColorpickerWidget = Widget.extend({
* @param {integer} l
*/
_updateHsl: function (h, s, l) {
// Remove full transparency in case some lightness is added
let a = this.colorComponents.opacity;
if (a < 0.1 && l > 0.1) {
a = 100;
}
var rgb = ColorpickerWidget.convertHslToRgb(h, s, l);
if (!rgb) {
return;
@@ -220,7 +232,8 @@ var ColorpickerWidget = Widget.extend({
_.extend(this.colorComponents,
{hue: h, saturation: s, lightness: l},
rgb,
{hex: hex}
{hex: hex},
{opacity: a},
);
this._updateCssColor();
},