From d8a632fbfcf00d3d375e8dec69818882a19a64eb Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 12 Jul 2021 10:23:56 +0000 Subject: [PATCH] [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 --- .../static/src/legacy/js/widgets/colorpicker.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/legacy/js/widgets/colorpicker.js b/addons/web/static/src/legacy/js/widgets/colorpicker.js index 6772db6166c..a2854d85131 100644 --- a/addons/web/static/src/legacy/js/widgets/colorpicker.js +++ b/addons/web/static/src/legacy/js/widgets/colorpicker.js @@ -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(); },