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 305c5e5c39f..bbc55ccb0aa 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -2038,6 +2038,14 @@ const SnippetOptionWidget = Widget.extend({ * @returns {Promise|undefined} */ selectStyle: async function (previewMode, widgetValue, params) { + // Disable all transitions for the duration of the method as many + // comparisons will be done on the element to know if applying a + // property has an effect or not. Also, changing a css property via the + // editor should not show any transition as previews would not be done + // immediately, which is not good for the user experience. + this.$target[0].classList.add('o_we_force_no_transition'); + const _restoreTransitions = () => this.$target[0].classList.remove('o_we_force_no_transition'); + if (params.cssProperty === 'background-color') { this.$target.trigger('background-color-event', previewMode); } @@ -2063,6 +2071,7 @@ const SnippetOptionWidget = Widget.extend({ // Those are the special color combinations classes. Just have // to add it (and adding the potential extra class) then leave. this.$target[0].classList.add('o_cc', `o_cc${widgetValue}`, params.extraClass); + _restoreTransitions(); if (previewMode === false) await this.updateChangesInWysiwyg(); return; } @@ -2075,6 +2084,7 @@ const SnippetOptionWidget = Widget.extend({ // property we are editing, nothing more has to be done. // (except adding the extra class) this.$target.addClass(params.extraClass); + _restoreTransitions(); if (previewMode === false) await this.updateChangesInWysiwyg(); return; } @@ -2132,6 +2142,7 @@ const SnippetOptionWidget = Widget.extend({ this.$target.toggleClass(params.extraClass, hasUserValue); } + _restoreTransitions(); if (previewMode === false) await this.updateChangesInWysiwyg(); }, @@ -2425,6 +2436,12 @@ const SnippetOptionWidget = Widget.extend({ } } + // Disable all transitions for the duration of the style check + // as we want to know the final value of a property to properly + // update the UI. + this.$target[0].classList.add('o_we_force_no_transition'); + const _restoreTransitions = () => this.$target[0].classList.remove('o_we_force_no_transition'); + const styles = window.getComputedStyle(this.$target[0]); const cssProps = weUtils.CSS_SHORTHANDS[params.cssProperty] || [params.cssProperty]; const cssValues = cssProps.map(cssProp => { @@ -2447,6 +2464,9 @@ const SnippetOptionWidget = Widget.extend({ if (cssValues.length === 2 && weUtils.areCssValuesEqual(cssValues[1], cssValues[0], params.cssProperty, this.$target)) { cssValues.pop(); } + + _restoreTransitions(); + return cssValues.join(' '); } } diff --git a/addons/web_editor/static/src/scss/wysiwyg_snippets.scss b/addons/web_editor/static/src/scss/wysiwyg_snippets.scss index f0a12064d1d..4c53f637806 100644 --- a/addons/web_editor/static/src/scss/wysiwyg_snippets.scss +++ b/addons/web_editor/static/src/scss/wysiwyg_snippets.scss @@ -1998,3 +1998,11 @@ we-select.o_we_shape_menu { .o_main_sidebar:not(.o_loaded) #oe_snippets { display: none !important; } + +.o_we_force_no_transition { + // Note: this is forced through a CSS class instead of inline style to avoid + // overridding existing inline styles or forgetting to restore them as the + // code evolves. We may need to increase the CSS priority of this. It will + // also not work to override important inline style... this is a limitation. + transition: none !important; +}