diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index deb72ac4f99..2b600c8625d 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -3620,10 +3620,14 @@ const SnippetOptionWidget = Widget.extend({ } let hasUserValue = false; - for (let i = cssProps.length - 1; i > 0; i--) { - hasUserValue = applyCSS.call(this, cssProps[i], values.pop(), styles) || hasUserValue; + const applyAllCSS = (values) => { + for (let i = cssProps.length - 1; i > 0; i--) { + hasUserValue = applyCSS.call(this, cssProps[i], values.pop(), styles) || hasUserValue; + } + hasUserValue = applyCSS.call(this, cssProps[0], values.join(' '), styles) || hasUserValue; } - hasUserValue = applyCSS.call(this, cssProps[0], values.join(' '), styles) || hasUserValue; + + applyAllCSS([...values]); function applyCSS(cssProp, cssValue, styles) { if (typeof params.forceStyle !== 'undefined') { @@ -3631,36 +3635,14 @@ const SnippetOptionWidget = Widget.extend({ return true; } - // This condition requires extraClass to NOT be set. if (!weUtils.areCssValuesEqual(styles.getPropertyValue(cssProp), cssValue, cssProp, this.$target[0])) { - // Property must be set => extraClass will be enabled. - if (params.extraClass) { - // The extraClass is temporarily removed during selectStyle - // because it is enabled only if the element style is set - // by the option. (E.g. add the bootstrap border class only - // if there is a border width.) Unfortunately the - // extraClass might specify default !important properties, - // therefore determining whether !important is needed - // requires the class to be applied. - this.$target[0].classList.add(params.extraClass); - // Set inline style only if different from value defined - // with extraClass. - if (!weUtils.areCssValuesEqual(styles.getPropertyValue(cssProp), cssValue, cssProp, this.$target[0])) { - this.$target[0].style.setProperty(cssProp, cssValue); - } - } else { - // Inline style required. - this.$target[0].style.setProperty(cssProp, cssValue); - } + this.$target[0].style.setProperty(cssProp, cssValue); // If change had no effect then make it important. // This condition requires extraClass to be set. if (!params.preventImportant && !weUtils.areCssValuesEqual( styles.getPropertyValue(cssProp), cssValue, cssProp, this.$target[0])) { this.$target[0].style.setProperty(cssProp, cssValue, 'important'); } - if (params.extraClass) { - this.$target[0].classList.remove(params.extraClass); - } return true; } return false; @@ -3668,6 +3650,13 @@ const SnippetOptionWidget = Widget.extend({ if (params.extraClass) { this.$target.toggleClass(params.extraClass, hasUserValue); + if (hasUserValue) { + // Might have changed because of the class. + for (const cssProp of cssProps) { + this.$target[0].style.removeProperty(cssProp); + } + applyAllCSS(values); + } } _restoreTransitions();